![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Embedded C project:18/12/2014
Dependencies: DS1307 TextLCD mbed
NetServices/lwip/include/ipv4/lwip/ip.h@0:8d87bc453349, 2014-12-18 (annotated)
- Committer:
- ninoderkinderen
- Date:
- Thu Dec 18 09:35:49 2014 +0000
- Revision:
- 0:8d87bc453349
Programma embedded C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ninoderkinderen | 0:8d87bc453349 | 1 | /* |
ninoderkinderen | 0:8d87bc453349 | 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
ninoderkinderen | 0:8d87bc453349 | 3 | * All rights reserved. |
ninoderkinderen | 0:8d87bc453349 | 4 | * |
ninoderkinderen | 0:8d87bc453349 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
ninoderkinderen | 0:8d87bc453349 | 6 | * are permitted provided that the following conditions are met: |
ninoderkinderen | 0:8d87bc453349 | 7 | * |
ninoderkinderen | 0:8d87bc453349 | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
ninoderkinderen | 0:8d87bc453349 | 9 | * this list of conditions and the following disclaimer. |
ninoderkinderen | 0:8d87bc453349 | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ninoderkinderen | 0:8d87bc453349 | 11 | * this list of conditions and the following disclaimer in the documentation |
ninoderkinderen | 0:8d87bc453349 | 12 | * and/or other materials provided with the distribution. |
ninoderkinderen | 0:8d87bc453349 | 13 | * 3. The name of the author may not be used to endorse or promote products |
ninoderkinderen | 0:8d87bc453349 | 14 | * derived from this software without specific prior written permission. |
ninoderkinderen | 0:8d87bc453349 | 15 | * |
ninoderkinderen | 0:8d87bc453349 | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
ninoderkinderen | 0:8d87bc453349 | 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
ninoderkinderen | 0:8d87bc453349 | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
ninoderkinderen | 0:8d87bc453349 | 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
ninoderkinderen | 0:8d87bc453349 | 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
ninoderkinderen | 0:8d87bc453349 | 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
ninoderkinderen | 0:8d87bc453349 | 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
ninoderkinderen | 0:8d87bc453349 | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
ninoderkinderen | 0:8d87bc453349 | 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
ninoderkinderen | 0:8d87bc453349 | 25 | * OF SUCH DAMAGE. |
ninoderkinderen | 0:8d87bc453349 | 26 | * |
ninoderkinderen | 0:8d87bc453349 | 27 | * This file is part of the lwIP TCP/IP stack. |
ninoderkinderen | 0:8d87bc453349 | 28 | * |
ninoderkinderen | 0:8d87bc453349 | 29 | * Author: Adam Dunkels <adam@sics.se> |
ninoderkinderen | 0:8d87bc453349 | 30 | * |
ninoderkinderen | 0:8d87bc453349 | 31 | */ |
ninoderkinderen | 0:8d87bc453349 | 32 | #ifndef __LWIP_IP_H__ |
ninoderkinderen | 0:8d87bc453349 | 33 | #define __LWIP_IP_H__ |
ninoderkinderen | 0:8d87bc453349 | 34 | |
ninoderkinderen | 0:8d87bc453349 | 35 | #include "lwip/opt.h" |
ninoderkinderen | 0:8d87bc453349 | 36 | |
ninoderkinderen | 0:8d87bc453349 | 37 | #include "lwip/def.h" |
ninoderkinderen | 0:8d87bc453349 | 38 | #include "lwip/pbuf.h" |
ninoderkinderen | 0:8d87bc453349 | 39 | #include "lwip/ip_addr.h" |
ninoderkinderen | 0:8d87bc453349 | 40 | #include "lwip/err.h" |
ninoderkinderen | 0:8d87bc453349 | 41 | #include "lwip/netif.h" |
ninoderkinderen | 0:8d87bc453349 | 42 | |
ninoderkinderen | 0:8d87bc453349 | 43 | #ifdef __cplusplus |
ninoderkinderen | 0:8d87bc453349 | 44 | extern "C" { |
ninoderkinderen | 0:8d87bc453349 | 45 | #endif |
ninoderkinderen | 0:8d87bc453349 | 46 | |
ninoderkinderen | 0:8d87bc453349 | 47 | /** Currently, the function ip_output_if_opt() is only used with IGMP */ |
ninoderkinderen | 0:8d87bc453349 | 48 | #define IP_OPTIONS_SEND LWIP_IGMP |
ninoderkinderen | 0:8d87bc453349 | 49 | |
ninoderkinderen | 0:8d87bc453349 | 50 | #define IP_HLEN 20 |
ninoderkinderen | 0:8d87bc453349 | 51 | |
ninoderkinderen | 0:8d87bc453349 | 52 | #define IP_PROTO_ICMP 1 |
ninoderkinderen | 0:8d87bc453349 | 53 | #define IP_PROTO_IGMP 2 |
ninoderkinderen | 0:8d87bc453349 | 54 | #define IP_PROTO_UDP 17 |
ninoderkinderen | 0:8d87bc453349 | 55 | #define IP_PROTO_UDPLITE 136 |
ninoderkinderen | 0:8d87bc453349 | 56 | #define IP_PROTO_TCP 6 |
ninoderkinderen | 0:8d87bc453349 | 57 | |
ninoderkinderen | 0:8d87bc453349 | 58 | /* This is passed as the destination address to ip_output_if (not |
ninoderkinderen | 0:8d87bc453349 | 59 | to ip_output), meaning that an IP header already is constructed |
ninoderkinderen | 0:8d87bc453349 | 60 | in the pbuf. This is used when TCP retransmits. */ |
ninoderkinderen | 0:8d87bc453349 | 61 | #ifdef IP_HDRINCL |
ninoderkinderen | 0:8d87bc453349 | 62 | #undef IP_HDRINCL |
ninoderkinderen | 0:8d87bc453349 | 63 | #endif /* IP_HDRINCL */ |
ninoderkinderen | 0:8d87bc453349 | 64 | #define IP_HDRINCL NULL |
ninoderkinderen | 0:8d87bc453349 | 65 | |
ninoderkinderen | 0:8d87bc453349 | 66 | #if LWIP_NETIF_HWADDRHINT |
ninoderkinderen | 0:8d87bc453349 | 67 | #define IP_PCB_ADDRHINT ;u8_t addr_hint |
ninoderkinderen | 0:8d87bc453349 | 68 | #else |
ninoderkinderen | 0:8d87bc453349 | 69 | #define IP_PCB_ADDRHINT |
ninoderkinderen | 0:8d87bc453349 | 70 | #endif /* LWIP_NETIF_HWADDRHINT */ |
ninoderkinderen | 0:8d87bc453349 | 71 | |
ninoderkinderen | 0:8d87bc453349 | 72 | /* This is the common part of all PCB types. It needs to be at the |
ninoderkinderen | 0:8d87bc453349 | 73 | beginning of a PCB type definition. It is located here so that |
ninoderkinderen | 0:8d87bc453349 | 74 | changes to this common part are made in one location instead of |
ninoderkinderen | 0:8d87bc453349 | 75 | having to change all PCB structs. */ |
ninoderkinderen | 0:8d87bc453349 | 76 | #define IP_PCB \ |
ninoderkinderen | 0:8d87bc453349 | 77 | /* ip addresses in network byte order */ \ |
ninoderkinderen | 0:8d87bc453349 | 78 | ip_addr_t local_ip; \ |
ninoderkinderen | 0:8d87bc453349 | 79 | ip_addr_t remote_ip; \ |
ninoderkinderen | 0:8d87bc453349 | 80 | /* Socket options */ \ |
ninoderkinderen | 0:8d87bc453349 | 81 | u8_t so_options; \ |
ninoderkinderen | 0:8d87bc453349 | 82 | /* Type Of Service */ \ |
ninoderkinderen | 0:8d87bc453349 | 83 | u8_t tos; \ |
ninoderkinderen | 0:8d87bc453349 | 84 | /* Time To Live */ \ |
ninoderkinderen | 0:8d87bc453349 | 85 | u8_t ttl \ |
ninoderkinderen | 0:8d87bc453349 | 86 | /* link layer address resolution hint */ \ |
ninoderkinderen | 0:8d87bc453349 | 87 | IP_PCB_ADDRHINT |
ninoderkinderen | 0:8d87bc453349 | 88 | |
ninoderkinderen | 0:8d87bc453349 | 89 | struct ip_pcb { |
ninoderkinderen | 0:8d87bc453349 | 90 | /* Common members of all PCB types */ |
ninoderkinderen | 0:8d87bc453349 | 91 | IP_PCB; |
ninoderkinderen | 0:8d87bc453349 | 92 | }; |
ninoderkinderen | 0:8d87bc453349 | 93 | |
ninoderkinderen | 0:8d87bc453349 | 94 | /* |
ninoderkinderen | 0:8d87bc453349 | 95 | * Option flags per-socket. These are the same like SO_XXX. |
ninoderkinderen | 0:8d87bc453349 | 96 | */ |
ninoderkinderen | 0:8d87bc453349 | 97 | /*#define SOF_DEBUG (u8_t)0x01U Unimplemented: turn on debugging info recording */ |
ninoderkinderen | 0:8d87bc453349 | 98 | #define SOF_ACCEPTCONN (u8_t)0x02U /* socket has had listen() */ |
ninoderkinderen | 0:8d87bc453349 | 99 | #define SOF_REUSEADDR (u8_t)0x04U /* allow local address reuse */ |
ninoderkinderen | 0:8d87bc453349 | 100 | #define SOF_KEEPALIVE (u8_t)0x08U /* keep connections alive */ |
ninoderkinderen | 0:8d87bc453349 | 101 | /*#define SOF_DONTROUTE (u8_t)0x10U Unimplemented: just use interface addresses */ |
ninoderkinderen | 0:8d87bc453349 | 102 | #define SOF_BROADCAST (u8_t)0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ |
ninoderkinderen | 0:8d87bc453349 | 103 | /*#define SOF_USELOOPBACK (u8_t)0x40U Unimplemented: bypass hardware when possible */ |
ninoderkinderen | 0:8d87bc453349 | 104 | #define SOF_LINGER (u8_t)0x80U /* linger on close if data present */ |
ninoderkinderen | 0:8d87bc453349 | 105 | /*#define SOF_OOBINLINE (u16_t)0x0100U Unimplemented: leave received OOB data in line */ |
ninoderkinderen | 0:8d87bc453349 | 106 | /*#define SOF_REUSEPORT (u16_t)0x0200U Unimplemented: allow local address & port reuse */ |
ninoderkinderen | 0:8d87bc453349 | 107 | |
ninoderkinderen | 0:8d87bc453349 | 108 | /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */ |
ninoderkinderen | 0:8d87bc453349 | 109 | #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/) |
ninoderkinderen | 0:8d87bc453349 | 110 | |
ninoderkinderen | 0:8d87bc453349 | 111 | |
ninoderkinderen | 0:8d87bc453349 | 112 | #ifdef PACK_STRUCT_USE_INCLUDES |
ninoderkinderen | 0:8d87bc453349 | 113 | # include "arch/bpstruct.h" |
ninoderkinderen | 0:8d87bc453349 | 114 | #endif |
ninoderkinderen | 0:8d87bc453349 | 115 | PACK_STRUCT_BEGIN |
ninoderkinderen | 0:8d87bc453349 | 116 | struct ip_hdr { |
ninoderkinderen | 0:8d87bc453349 | 117 | /* version / header length / type of service */ |
ninoderkinderen | 0:8d87bc453349 | 118 | PACK_STRUCT_FIELD(u16_t _v_hl_tos); |
ninoderkinderen | 0:8d87bc453349 | 119 | /* total length */ |
ninoderkinderen | 0:8d87bc453349 | 120 | PACK_STRUCT_FIELD(u16_t _len); |
ninoderkinderen | 0:8d87bc453349 | 121 | /* identification */ |
ninoderkinderen | 0:8d87bc453349 | 122 | PACK_STRUCT_FIELD(u16_t _id); |
ninoderkinderen | 0:8d87bc453349 | 123 | /* fragment offset field */ |
ninoderkinderen | 0:8d87bc453349 | 124 | PACK_STRUCT_FIELD(u16_t _offset); |
ninoderkinderen | 0:8d87bc453349 | 125 | #define IP_RF 0x8000 /* reserved fragment flag */ |
ninoderkinderen | 0:8d87bc453349 | 126 | #define IP_DF 0x4000 /* dont fragment flag */ |
ninoderkinderen | 0:8d87bc453349 | 127 | #define IP_MF 0x2000 /* more fragments flag */ |
ninoderkinderen | 0:8d87bc453349 | 128 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ |
ninoderkinderen | 0:8d87bc453349 | 129 | /* time to live */ |
ninoderkinderen | 0:8d87bc453349 | 130 | PACK_STRUCT_FIELD(u8_t _ttl); |
ninoderkinderen | 0:8d87bc453349 | 131 | /* protocol*/ |
ninoderkinderen | 0:8d87bc453349 | 132 | PACK_STRUCT_FIELD(u8_t _proto); |
ninoderkinderen | 0:8d87bc453349 | 133 | /* checksum */ |
ninoderkinderen | 0:8d87bc453349 | 134 | PACK_STRUCT_FIELD(u16_t _chksum); |
ninoderkinderen | 0:8d87bc453349 | 135 | /* source and destination IP addresses */ |
ninoderkinderen | 0:8d87bc453349 | 136 | PACK_STRUCT_FIELD(ip_addr_p_t src); |
ninoderkinderen | 0:8d87bc453349 | 137 | PACK_STRUCT_FIELD(ip_addr_p_t dest); |
ninoderkinderen | 0:8d87bc453349 | 138 | } PACK_STRUCT_STRUCT; |
ninoderkinderen | 0:8d87bc453349 | 139 | PACK_STRUCT_END |
ninoderkinderen | 0:8d87bc453349 | 140 | #ifdef PACK_STRUCT_USE_INCLUDES |
ninoderkinderen | 0:8d87bc453349 | 141 | # include "arch/epstruct.h" |
ninoderkinderen | 0:8d87bc453349 | 142 | #endif |
ninoderkinderen | 0:8d87bc453349 | 143 | |
ninoderkinderen | 0:8d87bc453349 | 144 | #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12) |
ninoderkinderen | 0:8d87bc453349 | 145 | #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f) |
ninoderkinderen | 0:8d87bc453349 | 146 | #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff) |
ninoderkinderen | 0:8d87bc453349 | 147 | #define IPH_LEN(hdr) ((hdr)->_len) |
ninoderkinderen | 0:8d87bc453349 | 148 | #define IPH_ID(hdr) ((hdr)->_id) |
ninoderkinderen | 0:8d87bc453349 | 149 | #define IPH_OFFSET(hdr) ((hdr)->_offset) |
ninoderkinderen | 0:8d87bc453349 | 150 | #define IPH_TTL(hdr) ((hdr)->_ttl) |
ninoderkinderen | 0:8d87bc453349 | 151 | #define IPH_PROTO(hdr) ((hdr)->_proto) |
ninoderkinderen | 0:8d87bc453349 | 152 | #define IPH_CHKSUM(hdr) ((hdr)->_chksum) |
ninoderkinderen | 0:8d87bc453349 | 153 | |
ninoderkinderen | 0:8d87bc453349 | 154 | #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos))) |
ninoderkinderen | 0:8d87bc453349 | 155 | #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) |
ninoderkinderen | 0:8d87bc453349 | 156 | #define IPH_ID_SET(hdr, id) (hdr)->_id = (id) |
ninoderkinderen | 0:8d87bc453349 | 157 | #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) |
ninoderkinderen | 0:8d87bc453349 | 158 | #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl) |
ninoderkinderen | 0:8d87bc453349 | 159 | #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto) |
ninoderkinderen | 0:8d87bc453349 | 160 | #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) |
ninoderkinderen | 0:8d87bc453349 | 161 | |
ninoderkinderen | 0:8d87bc453349 | 162 | /** The interface that provided the packet for the current callback invocation. */ |
ninoderkinderen | 0:8d87bc453349 | 163 | extern struct netif *current_netif; |
ninoderkinderen | 0:8d87bc453349 | 164 | /** Header of the input packet currently being processed. */ |
ninoderkinderen | 0:8d87bc453349 | 165 | extern const struct ip_hdr *current_header; |
ninoderkinderen | 0:8d87bc453349 | 166 | /** Source IP address of current_header */ |
ninoderkinderen | 0:8d87bc453349 | 167 | extern ip_addr_t current_iphdr_src; |
ninoderkinderen | 0:8d87bc453349 | 168 | /** Destination IP address of current_header */ |
ninoderkinderen | 0:8d87bc453349 | 169 | extern ip_addr_t current_iphdr_dest; |
ninoderkinderen | 0:8d87bc453349 | 170 | |
ninoderkinderen | 0:8d87bc453349 | 171 | #define ip_init() /* Compatibility define, not init needed. */ |
ninoderkinderen | 0:8d87bc453349 | 172 | struct netif *ip_route(ip_addr_t *dest); |
ninoderkinderen | 0:8d87bc453349 | 173 | err_t ip_input(struct pbuf *p, struct netif *inp); |
ninoderkinderen | 0:8d87bc453349 | 174 | err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, |
ninoderkinderen | 0:8d87bc453349 | 175 | u8_t ttl, u8_t tos, u8_t proto); |
ninoderkinderen | 0:8d87bc453349 | 176 | err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, |
ninoderkinderen | 0:8d87bc453349 | 177 | u8_t ttl, u8_t tos, u8_t proto, |
ninoderkinderen | 0:8d87bc453349 | 178 | struct netif *netif); |
ninoderkinderen | 0:8d87bc453349 | 179 | #if LWIP_NETIF_HWADDRHINT |
ninoderkinderen | 0:8d87bc453349 | 180 | err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, |
ninoderkinderen | 0:8d87bc453349 | 181 | u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint); |
ninoderkinderen | 0:8d87bc453349 | 182 | #endif /* LWIP_NETIF_HWADDRHINT */ |
ninoderkinderen | 0:8d87bc453349 | 183 | #if IP_OPTIONS_SEND |
ninoderkinderen | 0:8d87bc453349 | 184 | err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, |
ninoderkinderen | 0:8d87bc453349 | 185 | u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, |
ninoderkinderen | 0:8d87bc453349 | 186 | u16_t optlen); |
ninoderkinderen | 0:8d87bc453349 | 187 | #endif /* IP_OPTIONS_SEND */ |
ninoderkinderen | 0:8d87bc453349 | 188 | /** Get the interface that received the current packet. |
ninoderkinderen | 0:8d87bc453349 | 189 | * This function must only be called from a receive callback (udp_recv, |
ninoderkinderen | 0:8d87bc453349 | 190 | * raw_recv, tcp_accept). It will return NULL otherwise. */ |
ninoderkinderen | 0:8d87bc453349 | 191 | #define ip_current_netif() (current_netif) |
ninoderkinderen | 0:8d87bc453349 | 192 | /** Get the IP header of the current packet. |
ninoderkinderen | 0:8d87bc453349 | 193 | * This function must only be called from a receive callback (udp_recv, |
ninoderkinderen | 0:8d87bc453349 | 194 | * raw_recv, tcp_accept). It will return NULL otherwise. */ |
ninoderkinderen | 0:8d87bc453349 | 195 | #define ip_current_header() (current_header) |
ninoderkinderen | 0:8d87bc453349 | 196 | /** Source IP address of current_header */ |
ninoderkinderen | 0:8d87bc453349 | 197 | #define ip_current_src_addr() (¤t_iphdr_src) |
ninoderkinderen | 0:8d87bc453349 | 198 | /** Destination IP address of current_header */ |
ninoderkinderen | 0:8d87bc453349 | 199 | #define ip_current_dest_addr() (¤t_iphdr_dest) |
ninoderkinderen | 0:8d87bc453349 | 200 | |
ninoderkinderen | 0:8d87bc453349 | 201 | #if IP_DEBUG |
ninoderkinderen | 0:8d87bc453349 | 202 | void ip_debug_print(struct pbuf *p); |
ninoderkinderen | 0:8d87bc453349 | 203 | #else |
ninoderkinderen | 0:8d87bc453349 | 204 | #define ip_debug_print(p) |
ninoderkinderen | 0:8d87bc453349 | 205 | #endif /* IP_DEBUG */ |
ninoderkinderen | 0:8d87bc453349 | 206 | |
ninoderkinderen | 0:8d87bc453349 | 207 | #ifdef __cplusplus |
ninoderkinderen | 0:8d87bc453349 | 208 | } |
ninoderkinderen | 0:8d87bc453349 | 209 | #endif |
ninoderkinderen | 0:8d87bc453349 | 210 | |
ninoderkinderen | 0:8d87bc453349 | 211 | #endif /* __LWIP_IP_H__ */ |
ninoderkinderen | 0:8d87bc453349 | 212 | |
ninoderkinderen | 0:8d87bc453349 | 213 |