]> git.sur5r.net Git - freertos/blob - Demo/Common/ethernet/lwIP_130/src/include/ipv4/lwip/ip_addr.h
6b53968d076a4bc73ba1d6ca94d7b50e0cc44d26
[freertos] / Demo / Common / ethernet / lwIP_130 / src / include / ipv4 / lwip / ip_addr.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_ADDR_H__\r
33 #define __LWIP_IP_ADDR_H__\r
34 \r
35 #include "lwip/opt.h"\r
36 \r
37 #ifdef __cplusplus\r
38 extern "C" {\r
39 #endif\r
40 \r
41 #ifdef PACK_STRUCT_USE_INCLUDES\r
42 #  include "arch/bpstruct.h"\r
43 #endif\r
44 PACK_STRUCT_BEGIN\r
45 struct ip_addr {\r
46   PACK_STRUCT_FIELD(u32_t addr);\r
47 } PACK_STRUCT_STRUCT;\r
48 PACK_STRUCT_END\r
49 #ifdef PACK_STRUCT_USE_INCLUDES\r
50 #  include "arch/epstruct.h"\r
51 #endif\r
52 \r
53 /*\r
54  * struct ipaddr2 is used in the definition of the ARP packet format in\r
55  * order to support compilers that don't have structure packing.\r
56  */\r
57 #ifdef PACK_STRUCT_USE_INCLUDES\r
58 #  include "arch/bpstruct.h"\r
59 #endif\r
60 PACK_STRUCT_BEGIN\r
61 struct ip_addr2 {\r
62   PACK_STRUCT_FIELD(u16_t addrw[2]);\r
63 } PACK_STRUCT_STRUCT;\r
64 PACK_STRUCT_END\r
65 #ifdef PACK_STRUCT_USE_INCLUDES\r
66 #  include "arch/epstruct.h"\r
67 #endif\r
68 \r
69 /* For compatibility with BSD code */\r
70 struct in_addr {\r
71   u32_t s_addr;\r
72 };\r
73 \r
74 struct netif;\r
75 \r
76 extern const struct ip_addr ip_addr_any;\r
77 extern const struct ip_addr ip_addr_broadcast;\r
78 \r
79 /** IP_ADDR_ can be used as a fixed IP address\r
80  *  for the wildcard and the broadcast address\r
81  */\r
82 #define IP_ADDR_ANY         ((struct ip_addr *)&ip_addr_any)\r
83 #define IP_ADDR_BROADCAST   ((struct ip_addr *)&ip_addr_broadcast)\r
84 \r
85 #define INADDR_NONE         ((u32_t)0xffffffffUL)  /* 255.255.255.255 */\r
86 #define INADDR_LOOPBACK     ((u32_t)0x7f000001UL)  /* 127.0.0.1 */\r
87 \r
88 /* Definitions of the bits in an Internet address integer.\r
89 \r
90    On subnets, host and network parts are found according to\r
91    the subnet mask, not these masks.  */\r
92 \r
93 #define IN_CLASSA(a)        ((((u32_t)(a)) & 0x80000000UL) == 0)\r
94 #define IN_CLASSA_NET       0xff000000\r
95 #define IN_CLASSA_NSHIFT    24\r
96 #define IN_CLASSA_HOST      (0xffffffff & ~IN_CLASSA_NET)\r
97 #define IN_CLASSA_MAX       128\r
98 \r
99 #define IN_CLASSB(a)        ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)\r
100 #define IN_CLASSB_NET       0xffff0000\r
101 #define IN_CLASSB_NSHIFT    16\r
102 #define IN_CLASSB_HOST      (0xffffffff & ~IN_CLASSB_NET)\r
103 #define IN_CLASSB_MAX       65536\r
104 \r
105 #define IN_CLASSC(a)        ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)\r
106 #define IN_CLASSC_NET       0xffffff00\r
107 #define IN_CLASSC_NSHIFT    8\r
108 #define IN_CLASSC_HOST      (0xffffffff & ~IN_CLASSC_NET)\r
109 \r
110 #define IN_CLASSD(a)        (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)\r
111 #define IN_CLASSD_NET       0xf0000000          /* These ones aren't really */\r
112 #define IN_CLASSD_NSHIFT    28                  /*   net and host fields, but */\r
113 #define IN_CLASSD_HOST      0x0fffffff          /*   routing needn't know. */\r
114 #define IN_MULTICAST(a)     IN_CLASSD(a)\r
115 \r
116 #define IN_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)\r
117 #define IN_BADCLASS(a)      (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)\r
118 \r
119 #define IN_LOOPBACKNET      127                 /* official! */\r
120 \r
121 #define IP4_ADDR(ipaddr, a,b,c,d) \\r
122         (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \\r
123                                ((u32_t)((b) & 0xff) << 16) | \\r
124                                ((u32_t)((c) & 0xff) << 8) | \\r
125                                 (u32_t)((d) & 0xff))\r
126 \r
127 #define ip_addr_set(dest, src) (dest)->addr = \\r
128                                ((src) == NULL? 0:\\r
129                                (src)->addr)\r
130 /**\r
131  * Determine if two address are on the same network.\r
132  *\r
133  * @arg addr1 IP address 1\r
134  * @arg addr2 IP address 2\r
135  * @arg mask network identifier mask\r
136  * @return !0 if the network identifiers of both address match\r
137  */\r
138 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \\r
139                                               (mask)->addr) == \\r
140                                              ((addr2)->addr & \\r
141                                               (mask)->addr))\r
142 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)\r
143 \r
144 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)\r
145 \r
146 u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);\r
147 \r
148 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))\r
149 \r
150 #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))\r
151 \r
152 #define ip_addr_debug_print(debug, ipaddr) \\r
153         LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \\r
154                 ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \\r
155                 ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \\r
156                 ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \\r
157                 ipaddr ? (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))\r
158 \r
159 /* These are cast to u16_t, with the intent that they are often arguments\r
160  * to printf using the U16_F format from cc.h. */\r
161 #define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)\r
162 #define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)\r
163 #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)\r
164 #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)\r
165 \r
166 #ifdef __cplusplus\r
167 }\r
168 #endif\r
169 \r
170 #endif /* __LWIP_IP_ADDR_H__ */\r