]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/lwIP_MCF5235_GCC/lwip/src/include/ipv4/lwip/ip.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / lwIP_MCF5235_GCC / lwip / src / include / ipv4 / lwip / ip.h
1 /*\r
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.\r
3  * All rights reserved. \r
4  * \r
5  * Redistribution and use in source and binary forms, with or without modification, \r
6  * are permitted provided that the following conditions are met:\r
7  *\r
8  * 1. Redistributions of source code must retain the above copyright notice,\r
9  *    this list of conditions and the following disclaimer.\r
10  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
11  *    this list of conditions and the following disclaimer in the documentation\r
12  *    and/or other materials provided with the distribution.\r
13  * 3. The name of the author may not be used to endorse or promote products\r
14  *    derived from this software without specific prior written permission. \r
15  *\r
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \r
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT \r
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \r
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT \r
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \r
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY \r
25  * OF SUCH DAMAGE.\r
26  *\r
27  * This file is part of the lwIP TCP/IP stack.\r
28  * \r
29  * Author: Adam Dunkels <adam@sics.se>\r
30  *\r
31  */\r
32 #ifndef __LWIP_IP_H__\r
33 #define __LWIP_IP_H__\r
34 \r
35 #include "lwip/arch.h"\r
36 \r
37 #include "lwip/def.h"\r
38 #include "lwip/pbuf.h"\r
39 #include "lwip/ip_addr.h"\r
40 \r
41 #include "lwip/err.h"\r
42 \r
43 \r
44 void ip_init(void);\r
45 struct netif *ip_route(struct ip_addr *dest);\r
46 err_t ip_input(struct pbuf *p, struct netif *inp);\r
47 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,\r
48                 u8_t ttl, u8_t tos, u8_t proto);\r
49 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,\r
50                    u8_t ttl, u8_t tos, u8_t proto,\r
51        struct netif *netif);\r
52 \r
53 #define IP_HLEN 20\r
54 \r
55 #define IP_PROTO_ICMP 1\r
56 #define IP_PROTO_UDP 17\r
57 #define IP_PROTO_UDPLITE 170\r
58 #define IP_PROTO_TCP 6\r
59 \r
60 /* This is passed as the destination address to ip_output_if (not\r
61    to ip_output), meaning that an IP header already is constructed\r
62    in the pbuf. This is used when TCP retransmits. */\r
63 #ifdef IP_HDRINCL\r
64 #undef IP_HDRINCL\r
65 #endif /* IP_HDRINCL */\r
66 #define IP_HDRINCL  NULL\r
67 \r
68 \r
69 /* This is the common part of all PCB types. It needs to be at the\r
70    beginning of a PCB type definition. It is located here so that\r
71    changes to this common part are made in one location instead of\r
72    having to change all PCB structs. */\r
73 #define IP_PCB struct ip_addr local_ip; \\r
74   struct ip_addr remote_ip; \\r
75    /* Socket options */  \\r
76   u16_t so_options;      \\r
77    /* Type Of Service */ \\r
78   u8_t tos;              \\r
79   /* Time To Live */     \\r
80   u8_t ttl\r
81 \r
82 /*\r
83  * Option flags per-socket. These are the same like SO_XXX.\r
84  */\r
85 #define SOF_DEBUG           (u16_t)0x0001U              /* turn on debugging info recording */\r
86 #define SOF_ACCEPTCONN  (u16_t)0x0002U          /* socket has had listen() */\r
87 #define SOF_REUSEADDR   (u16_t)0x0004U          /* allow local address reuse */\r
88 #define SOF_KEEPALIVE   (u16_t)0x0008U          /* keep connections alive */\r
89 #define SOF_DONTROUTE   (u16_t)0x0010U          /* just use interface addresses */\r
90 #define SOF_BROADCAST   (u16_t)0x0020U          /* permit sending of broadcast msgs */\r
91 #define SOF_USELOOPBACK (u16_t)0x0040U          /* bypass hardware when possible */\r
92 #define SOF_LINGER          (u16_t)0x0080U              /* linger on close if data present */\r
93 #define SOF_OOBINLINE   (u16_t)0x0100U          /* leave received OOB data in line */\r
94 #define SOF_REUSEPORT   (u16_t)0x0200U          /* allow local address & port reuse */\r
95 \r
96 \r
97 \r
98 #ifdef PACK_STRUCT_USE_INCLUDES\r
99 #  include "arch/bpstruct.h"\r
100 #endif\r
101 PACK_STRUCT_BEGIN\r
102 struct ip_hdr {\r
103   /* version / header length / type of service */\r
104   PACK_STRUCT_FIELD(u16_t _v_hl_tos);\r
105   /* total length */\r
106   PACK_STRUCT_FIELD(u16_t _len);\r
107   /* identification */\r
108   PACK_STRUCT_FIELD(u16_t _id);\r
109   /* fragment offset field */\r
110   PACK_STRUCT_FIELD(u16_t _offset);\r
111 #define IP_RF 0x8000        /* reserved fragment flag */\r
112 #define IP_DF 0x4000        /* dont fragment flag */\r
113 #define IP_MF 0x2000        /* more fragments flag */\r
114 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */\r
115   /* time to live / protocol*/\r
116   PACK_STRUCT_FIELD(u16_t _ttl_proto);\r
117   /* checksum */\r
118   PACK_STRUCT_FIELD(u16_t _chksum);\r
119   /* source and destination IP addresses */\r
120   PACK_STRUCT_FIELD(struct ip_addr src);\r
121   PACK_STRUCT_FIELD(struct ip_addr dest); \r
122 } PACK_STRUCT_STRUCT;\r
123 PACK_STRUCT_END\r
124 #ifdef PACK_STRUCT_USE_INCLUDES\r
125 #  include "arch/epstruct.h"\r
126 #endif\r
127 \r
128 #define IPH_V(hdr)  (ntohs((hdr)->_v_hl_tos) >> 12)\r
129 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)\r
130 #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)\r
131 #define IPH_LEN(hdr) ((hdr)->_len)\r
132 #define IPH_ID(hdr) ((hdr)->_id)\r
133 #define IPH_OFFSET(hdr) ((hdr)->_offset)\r
134 #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)\r
135 #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)\r
136 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)\r
137 \r
138 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))\r
139 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)\r
140 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)\r
141 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)\r
142 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((ttl) << 8)))\r
143 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))\r
144 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)\r
145 \r
146 #if IP_DEBUG\r
147 void ip_debug_print(struct pbuf *p);\r
148 #else\r
149 #define ip_debug_print(p)\r
150 #endif /* IP_DEBUG */\r
151 \r
152 #endif /* __LWIP_IP_H__ */\r
153 \r
154 \r