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