ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
tcpip.h
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #ifndef __TCPIP_H__
17 #define __TCPIP_H__
18 
19 #include <tamtypes.h>
20 
21 /* Some portions of this header fall under the following copyright. The license
22  is compatible with that of ps2sdk.
23 
24  This port of LWIP has LWIP_DHCP defined by default. */
25 
26 #ifndef PS2IP_DNS
27 #define PS2IP_DNS
28 #endif
29 #ifndef PS2IP_DHCP
30 #define PS2IP_DHCP 1
31 #endif
32 #ifndef LWIP_DHCP
33 #define LWIP_DHCP 1
34 #endif
35 #if (!defined(LWIP_IPV4) && !defined(LWIP_IPV6))
36  #define LWIP_IPV4 1
37 #endif
38 #ifndef LWIP_TCP
39 #define LWIP_TCP 1
40 #endif
41 #ifndef LWIP_UDP
42 #define LWIP_UDP 1
43 #endif
44 
45 /*** Taken from src/include/lwip/opt.h. If changes were made to lwipopts.h, please update this section.
46  Some settings affect the fields present in structures like struct netif! ****/
47 #define MEMP_NUM_UDP_PCB 4
48 #define MEMP_NUM_TCP_PCB 5
49 #define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB+MEMP_NUM_UDP_PCB)
50 #define LWIP_NETIF_STATUS_CALLBACK 0
51 #define LWIP_NETIF_LINK_CALLBACK 0
52 #define LWIP_AUTOIP 0
53 #define LWIP_NETIF_HOSTNAME 0
54 #define LWIP_SNMP 0
55 #define LWIP_IGMP 0
56 #define LWIP_NETIF_HWADDRHINT 0
57 #define LWIP_LOOPBACK_MAX_PBUFS 0
58 #define LWIP_NUM_NETIF_CLIENT_DATA 0
59 #define LWIP_SOCKET_OFFSET 0
60 #define LWIP_IPV6_SEND_ROUTER_SOLICIT 1
61 #define DNS_MAX_SERVERS 2
62 
63 /*
64  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
65  * All rights reserved.
66  *
67  * Redistribution and use in source and binary forms, with or without modification,
68  * are permitted provided that the following conditions are met:
69  *
70  * 1. Redistributions of source code must retain the above copyright notice,
71  * this list of conditions and the following disclaimer.
72  * 2. Redistributions in binary form must reproduce the above copyright notice,
73  * this list of conditions and the following disclaimer in the documentation
74  * and/or other materials provided with the distribution.
75  * 3. The name of the author may not be used to endorse or promote products
76  * derived from this software without specific prior written permission.
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
79  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
80  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
81  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
82  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
83  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
84  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
85  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
86  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
87  * OF SUCH DAMAGE.
88  *
89  * This file is part of the lwIP TCP/IP stack.
90  *
91  * Author: Adam Dunkels <adam@sics.se>
92  *
93  */
94 
95 typedef signed char err_t; /* lwIP error type. */
96 
97 /* From src/include/lwip/pbuf.h: */
98 
99 #define PBUF_TRANSPORT_HLEN 20
100 #if LWIP_IPV6
101 #define PBUF_IP_HLEN 40
102 #else
103 #define PBUF_IP_HLEN 20
104 #endif
105 
110 typedef enum {
132  PBUF_RAW
134 
139 typedef enum {
161  PBUF_POOL
163 
165 struct pbuf {
167  struct pbuf *next;
168 
170  void *payload;
171 
180 
183 
185  u8 /*pbuf_type*/ type;
186 
189 
196 };
197 
198 /* From include/lwip/ip4_addr.h: */
201 struct ip4_addr {
203 };
204 
207 typedef struct ip4_addr ip4_addr_t;
208 typedef struct ip4_addr_packed ip4_addr_p_t;
209 
211 #define IPADDR_NONE ((u32)0xffffffffUL)
213 #define IPADDR_LOOPBACK ((u32)0x7f000001UL)
215 #define IPADDR_ANY ((u32)0x00000000UL)
217 #define IPADDR_BROADCAST ((u32)0xffffffffUL)
218 
219 /* Definitions of the bits in an Internet address integer.
220 
221  On subnets, host and network parts are found according to
222  the subnet mask, not these masks. */
223 #define IP_CLASSA(a) ((((u32)(a)) & 0x80000000UL) == 0)
224 #define IP_CLASSA_NET 0xff000000
225 #define IP_CLASSA_NSHIFT 24
226 #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
227 #define IP_CLASSA_MAX 128
228 
229 #define IP_CLASSB(a) ((((u32)(a)) & 0xc0000000UL) == 0x80000000UL)
230 #define IP_CLASSB_NET 0xffff0000
231 #define IP_CLASSB_NSHIFT 16
232 #define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
233 #define IP_CLASSB_MAX 65536
234 
235 #define IP_CLASSC(a) ((((u32)(a)) & 0xe0000000UL) == 0xc0000000UL)
236 #define IP_CLASSC_NET 0xffffff00
237 #define IP_CLASSC_NSHIFT 8
238 #define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
239 
240 #define IP_CLASSD(a) (((u32)(a) & 0xf0000000UL) == 0xe0000000UL)
241 #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
242 #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
243 #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
244 #define IP_MULTICAST(a) IP_CLASSD(a)
245 
246 #define IP_EXPERIMENTAL(a) (((u32)(a) & 0xf0000000UL) == 0xf0000000UL)
247 #define IP_BADCLASS(a) (((u32)(a) & 0xf0000000UL) == 0xf0000000UL)
248 
249 #define IP_LOOPBACKNET 127 /* official! */
250 
251 
254 #define IP4_ADDR(ipaddr, a,b,c,d) \
255  (ipaddr)->addr = ((u32)((d) & 0xff) << 24) | \
256  ((u32)((c) & 0xff) << 16) | \
257  ((u32)((b) & 0xff) << 8) | \
258  (u32)((a) & 0xff)
259 
263 #ifndef IPADDR2_COPY
264 #define IPADDR2_COPY(dest, src) memcpy(dest, src, sizeof(ip4_addr_t))
265 #endif
266 
268 #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
270 #define ip4_addr_set(dest, src) ((dest)->addr = \
271  ((src) == NULL ? 0 : \
272  (src)->addr))
274 #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
276 #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
278 #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
280 #define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32)IP_LOOPBACKNET) << 24))
283 #define ip4_addr_set_hton(dest, src) ((dest)->addr = \
284  ((src) == NULL ? 0:\
285  lwip_htonl((src)->addr)))
287 #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
289 #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
290 
292 #define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
293 
302 #define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
303  (mask)->addr) == \
304  ((addr2)->addr & \
305  (mask)->addr))
306 #define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
307 
308 #define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
309 #define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
310 
311 #define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
312 
313 #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
314 
315 #define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
316 
317 #define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
318 
319 #define ip4_addr_debug_print_parts(debug, a, b, c, d) \
320  LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
321 #define ip4_addr_debug_print(debug, ipaddr) \
322  ip4_addr_debug_print_parts(debug, \
323  (u16)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
324  (u16)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
325  (u16)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
326  (u16)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
327 #define ip4_addr_debug_print_val(debug, ipaddr) \
328  ip4_addr_debug_print_parts(debug, \
329  ip4_addr1_16(&(ipaddr)), \
330  ip4_addr2_16(&(ipaddr)), \
331  ip4_addr3_16(&(ipaddr)), \
332  ip4_addr4_16(&(ipaddr)))
333 
334 /* Get one byte from the 4-byte address */
335 #define ip4_addr1(ipaddr) (((const u8*)(&(ipaddr)->addr))[0])
336 #define ip4_addr2(ipaddr) (((const u8*)(&(ipaddr)->addr))[1])
337 #define ip4_addr3(ipaddr) (((const u8*)(&(ipaddr)->addr))[2])
338 #define ip4_addr4(ipaddr) (((const u8*)(&(ipaddr)->addr))[3])
339 /* These are cast to u16, with the intent that they are often arguments
340  * to printf using the U16_F format from cc.h. */
341 #define ip4_addr1_16(ipaddr) ((u16)ip4_addr1(ipaddr))
342 #define ip4_addr2_16(ipaddr) ((u16)ip4_addr2(ipaddr))
343 #define ip4_addr3_16(ipaddr) ((u16)ip4_addr3(ipaddr))
344 #define ip4_addr4_16(ipaddr) ((u16)ip4_addr4(ipaddr))
345 
346 #define IP4ADDR_STRLEN_MAX 16
347 
348 /* From include/lwip/ip6_addr.h: */
351 struct ip6_addr {
352  u32 addr[4];
353 };
354 
356 typedef struct ip6_addr ip6_addr_t;
357 typedef struct ip6_addr_packed ip6_addr_p_t;
358 
361 #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \
362  (ip6addr)->addr[index] = ((u32)((d) & 0xff) << 24) | \
363  ((u32)((c) & 0xff) << 16) | \
364  ((u32)((b) & 0xff) << 8) | \
365  (u32)((a) & 0xff)
366 
369 #define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
370  (ip6addr)->addr[0] = idx0; \
371  (ip6addr)->addr[1] = idx1; \
372  (ip6addr)->addr[2] = idx2; \
373  (ip6addr)->addr[3] = idx3; } while(0)
374 
376 #define IP6_ADDR_BLOCK1(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
378 #define IP6_ADDR_BLOCK2(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
380 #define IP6_ADDR_BLOCK3(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
382 #define IP6_ADDR_BLOCK4(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
384 #define IP6_ADDR_BLOCK5(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
386 #define IP6_ADDR_BLOCK6(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
388 #define IP6_ADDR_BLOCK7(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
390 #define IP6_ADDR_BLOCK8(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
391 
393 #define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
394  (dest).addr[1] = (src).addr[1]; \
395  (dest).addr[2] = (src).addr[2]; \
396  (dest).addr[3] = (src).addr[3];}while(0)
398 #define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
399  (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
400  (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
401  (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3];}while(0)
402 
404 #define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
405  (ip6addr)->addr[1] = 0; \
406  (ip6addr)->addr[2] = 0; \
407  (ip6addr)->addr[3] = 0;}while(0)
408 
410 #define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
412 #define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \
413  (ip6addr)->addr[1] = 0; \
414  (ip6addr)->addr[2] = 0; \
415  (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
418 #define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
419  (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
420  (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
421  (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]);}while(0)
422 
423 
431 #define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
432  ((addr1)->addr[1] == (addr2)->addr[1]))
433 
434 #define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
435  ((addr1)->addr[1] == (addr2)->addr[1]) && \
436  ((addr1)->addr[2] == (addr2)->addr[2]) && \
437  ((addr1)->addr[3] == (addr2)->addr[3]))
438 
439 #define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
440 
441 #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
442  ((ip6addr).addr[1] == 0) && \
443  ((ip6addr).addr[2] == 0) && \
444  ((ip6addr).addr[3] == 0))
445 #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
446 
447 #define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
448  ((ip6addr)->addr[1] == 0UL) && \
449  ((ip6addr)->addr[2] == 0UL) && \
450  ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
451 
452 #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
453 
454 #define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
455 
456 #define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
457 
458 #define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
459 
460 #define ip6_addr_isipv6mappedipv4(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
461 
462 #define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
463 #define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
464 #define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
465 #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
466 #define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
467 #define IP6_MULTICAST_SCOPE_RESERVED 0x0
468 #define IP6_MULTICAST_SCOPE_RESERVED0 0x0
469 #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
470 #define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
471 #define IP6_MULTICAST_SCOPE_RESERVED3 0x3
472 #define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
473 #define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
474 #define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
475 #define IP6_MULTICAST_SCOPE_GLOBAL 0xe
476 #define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
477 #define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
478 #define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
479 #define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
480 #define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
481 #define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
482 #define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
483 
484 /* @todo define get/set for well-know multicast addresses, e.g. ff02::1 */
485 #define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
486  ((ip6addr)->addr[1] == 0UL) && \
487  ((ip6addr)->addr[2] == 0UL) && \
488  ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
489 
490 #define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
491  ((ip6addr)->addr[1] == 0UL) && \
492  ((ip6addr)->addr[2] == 0UL) && \
493  ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
494 #define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
495  (ip6addr)->addr[1] = 0; \
496  (ip6addr)->addr[2] = 0; \
497  (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
498 
499 #define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
500  ((ip6addr)->addr[1] == 0UL) && \
501  ((ip6addr)->addr[2] == 0UL) && \
502  ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
503 #define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
504  (ip6addr)->addr[1] = 0; \
505  (ip6addr)->addr[2] = 0; \
506  (ip6addr)->addr[3] = PP_HTONL(0x00000002UL);}while(0)
507 
508 #define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
509  ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
510  (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) )
511 
512 #define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
513  (ip6addr)->addr[1] = 0; \
514  (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
515  (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id));}while(0)
516 
517 #define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
518  ((ip6addr)->addr[1] == 0) && \
519  ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
520  ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
521 
522 /* IPv6 address states. */
523 #define IP6_ADDR_INVALID 0x00
524 #define IP6_ADDR_TENTATIVE 0x08
525 #define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */
526 #define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */
527 #define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */
528 #define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */
529 #define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */
530 #define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */
531 #define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */
532 #define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */
533 #define IP6_ADDR_PREFERRED 0x30
534 #define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */
535 
536 #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
537 
538 #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
539 #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
540 #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
541 #define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
542 #define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
543 
544 #define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
545  LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
546  a, b, c, d, e, f, g, h))
547 #define ip6_addr_debug_print(debug, ipaddr) \
548  ip6_addr_debug_print_parts(debug, \
549  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
550  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
551  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
552  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
553  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
554  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
555  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
556  (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
557 #define ip6_addr_debug_print_val(debug, ipaddr) \
558  ip6_addr_debug_print_parts(debug, \
559  IP6_ADDR_BLOCK1(&(ipaddr)), \
560  IP6_ADDR_BLOCK2(&(ipaddr)), \
561  IP6_ADDR_BLOCK3(&(ipaddr)), \
562  IP6_ADDR_BLOCK4(&(ipaddr)), \
563  IP6_ADDR_BLOCK5(&(ipaddr)), \
564  IP6_ADDR_BLOCK6(&(ipaddr)), \
565  IP6_ADDR_BLOCK7(&(ipaddr)), \
566  IP6_ADDR_BLOCK8(&(ipaddr)))
567 
568 #define IP6ADDR_STRLEN_MAX 46
569 
570 /* From include/lwip/ip_addr.h: */
571 
582  IPADDR_TYPE_ANY = 46U
583 };
584 
585 #if LWIP_IPV4 && LWIP_IPV6
591 typedef struct _ip_addr {
592  union {
593  ip6_addr_t ip6;
594  ip4_addr_t ip4;
595  } uaddr;
597  u8 type;
598 } ip_addr_t;
599 
600 extern const ip_addr_t ip_addr_any_type;
601 
603 #define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_V4 }
605 #define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
606 
608 #define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
610 #define IPADDR_ANY_TYPE_INIT { { { { 0ul, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_ANY }
611 
613 #define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
615 #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
617 #define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
619 #define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
620 
621 #define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
622 #define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
623 #define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
624 
625 #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr))
626 #define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr))
627 
631 #define ip_2_ip6(ipaddr) (&((ipaddr)->uaddr.ip6))
635 #define ip_2_ip4(ipaddr) (&((ipaddr)->uaddr.ip4))
636 
638 #define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \
639  IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0)
641 #define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \
642  IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0)
643 
645 #define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
646  ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
647  ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
649 #define ip_addr_copy_from_ip6(dest, src) do{ \
650  ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0)
652 #define ip_addr_copy_from_ip4(dest, src) do{ \
653  ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }while(0)
655 #define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
656  IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
658 #define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \
659  ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0)
661 #define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \
662  ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \
663  ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }}while(0)
665 #define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src)
667 #define ip_addr_set_zero(ipaddr) do{ \
668  ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
670 #define ip_addr_set_zero_ip4(ipaddr) do{ \
671  ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }while(0)
673 #define ip_addr_set_zero_ip6(ipaddr) do{ \
674  ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }while(0)
676 #define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
677  ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
678  ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
680 #define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
681  ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
682  ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
684 #define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \
685  ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
686  ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
688 #define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \
689  ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \
690  ip4_addr_get_network(ip_2_ip4(target), ip_2_ip4(host), ip_2_ip4(netmask)); IP_SET_TYPE(target, IPADDR_TYPE_V4); }}while(0)
692 #define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
693  0 : \
694  ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
696 #define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \
697  ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
698  ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
700 #define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
701  ip6_addr_isany(ip_2_ip6(ipaddr)) : \
702  ip4_addr_isany(ip_2_ip4(ipaddr)))
704 #define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
705  ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
706  ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
708 #define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
709  0 : \
710  ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
712 #define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
713  ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
714  ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
716 #define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
717  ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
718  ip4_addr_isloopback(ip_2_ip4(ipaddr)))
720 #define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \
721  ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \
722  ip4_addr_islinklocal(ip_2_ip4(ipaddr)))
723 #define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \
724  ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \
725  ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0)
726 #define ip_addr_debug_print_val(debug, ipaddr) do { if(IP_IS_V6_VAL(ipaddr)) { \
727  ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); } else { \
728  ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); }}while(0)
730 #define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
731  ((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
733 #define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
734  ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen)))
735 int ipaddr_aton(const char *cp, ip_addr_t *addr);
736 
738 #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
739 
740 #else /* LWIP_IPV4 && LWIP_IPV6 */
741 
742 #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
743 #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1
744 
745 #if LWIP_IPV4
746 
747 typedef ip4_addr_t ip_addr_t;
748 #define IPADDR4_INIT(u32val) { u32val }
749 #define IP_IS_V4_VAL(ipaddr) 1
750 #define IP_IS_V6_VAL(ipaddr) 0
751 #define IP_IS_V4(ipaddr) 1
752 #define IP_IS_V6(ipaddr) 0
753 #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
754 #define IP_SET_TYPE_VAL(ipaddr, iptype)
755 #define IP_SET_TYPE(ipaddr, iptype)
756 #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
757 #define ip_2_ip4(ipaddr) (ipaddr)
758 #define IP_ADDR4(ipaddr,a,b,c,d) IP4_ADDR(ipaddr,a,b,c,d)
759 
760 #define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
761 #define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src)
762 #define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val)
763 #define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr))
764 #define ip_addr_set(dest, src) ip4_addr_set(dest, src)
765 #define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src)
766 #define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
767 #define ip_addr_set_zero_ip4(ipaddr) ip4_addr_set_zero(ipaddr)
768 #define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
769 #define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr)
770 #define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src)
771 #define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask)
772 #define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask)
773 #define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
774 #define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
775 #define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
776 #define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr)
777 #define ip_addr_islinklocal(ipaddr) ip4_addr_islinklocal(ipaddr)
778 #define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif)
779 #define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr)
780 #define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr)
781 #define ip_addr_debug_print_val(debug, ipaddr) ip4_addr_debug_print_val(debug, ipaddr)
782 #define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr)
783 #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen)
784 #define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
785 
786 #define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX
787 
788 #else /* LWIP_IPV4 */
789 
790 typedef ip6_addr_t ip_addr_t;
791 #define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } }
792 #define IP_IS_V4_VAL(ipaddr) 0
793 #define IP_IS_V6_VAL(ipaddr) 1
794 #define IP_IS_V4(ipaddr) 0
795 #define IP_IS_V6(ipaddr) 1
796 #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
797 #define IP_SET_TYPE_VAL(ipaddr, iptype)
798 #define IP_SET_TYPE(ipaddr, iptype)
799 #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
800 #define ip_2_ip6(ipaddr) (ipaddr)
801 #define IP_ADDR6(ipaddr,i0,i1,i2,i3) IP6_ADDR(ipaddr,i0,i1,i2,i3)
802 
803 #define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
804 #define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
805 #define ip_addr_set(dest, src) ip6_addr_set(dest, src)
806 #define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
807 #define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
808 #define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr)
809 #define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
810 #define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
811 #define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
812 #define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
813 #define ip_addr_netcmp(addr1, addr2, mask) 0
814 #define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
815 #define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
816 #define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
817 #define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
818 #define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr)
819 #define ip_addr_isbroadcast(addr, netif) 0
820 #define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
821 #define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
822 #define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr)
823 #define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
824 #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
825 #define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
826 
827 #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
828 
829 #endif /* LWIP_IPV4 */
830 #endif /* LWIP_IPV4 && LWIP_IPV6 */
831 
832 #if LWIP_IPV4
833 
834 extern const ip_addr_t ip_addr_any;
835 extern const ip_addr_t ip_addr_broadcast;
836 
841 #define IP_ADDR_ANY IP4_ADDR_ANY
847 #define IP4_ADDR_ANY (&ip_addr_any)
853 #define IP4_ADDR_ANY4 (ip_2_ip4(&ip_addr_any))
854 
856 #define IP_ADDR_BROADCAST (&ip_addr_broadcast)
858 #define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast))
859 
860 #endif /* LWIP_IPV4*/
861 
862 #if LWIP_IPV6
863 
864 extern const ip_addr_t ip6_addr_any;
865 
871 #define IP6_ADDR_ANY (&ip6_addr_any)
877 #define IP6_ADDR_ANY6 (ip_2_ip6(&ip6_addr_any))
878 
879 #if !LWIP_IPV4
881 #define IP_ADDR_ANY IP6_ADDR_ANY
882 #endif /* !LWIP_IPV4 */
883 
884 #endif
885 
886 #if LWIP_IPV4 && LWIP_IPV6
888 #define IP_ANY_TYPE (&ip_addr_any_type)
889 #else
890 #define IP_ANY_TYPE IP_ADDR_ANY
891 #endif
892 
893 /* From src/include/lwip/netif.h: */
894 
895 
896 /* Throughout this file, IP addresses are expected to be in
897  * the same byte order as in IP_PCB. */
898 
902 #ifndef NETIF_MAX_HWADDR_LEN
903 #define NETIF_MAX_HWADDR_LEN 6U
904 #endif
905 
918 #define NETIF_FLAG_UP 0x01U
921 #define NETIF_FLAG_BROADCAST 0x02U
927 #define NETIF_FLAG_LINK_UP 0x04U
931 #define NETIF_FLAG_ETHARP 0x08U
935 #define NETIF_FLAG_ETHERNET 0x10U
938 #define NETIF_FLAG_IGMP 0x20U
941 #define NETIF_FLAG_MLD6 0x40U
942 
948 {
949 #if LWIP_DHCP
951 #endif
952 #if LWIP_AUTOIP
953  LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
954 #endif
955 #if LWIP_IGMP
956  LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
957 #endif
958 #if LWIP_IPV6_MLD
959  LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
960 #endif
962 };
963 
964 #if LWIP_CHECKSUM_CTRL_PER_NETIF
965 #define NETIF_CHECKSUM_GEN_IP 0x0001
966 #define NETIF_CHECKSUM_GEN_UDP 0x0002
967 #define NETIF_CHECKSUM_GEN_TCP 0x0004
968 #define NETIF_CHECKSUM_GEN_ICMP 0x0008
969 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
970 #define NETIF_CHECKSUM_CHECK_IP 0x0100
971 #define NETIF_CHECKSUM_CHECK_UDP 0x0200
972 #define NETIF_CHECKSUM_CHECK_TCP 0x0400
973 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
974 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
975 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
976 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
977 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
978 
979 struct netif;
980 
988 };
989 
995 typedef err_t (*netif_init_fn)(struct netif *netif);
1002 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
1003 
1004 #if LWIP_IPV4
1013 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
1014  const ip4_addr_t *ipaddr);
1015 #endif /* LWIP_IPV4*/
1016 
1017 #if LWIP_IPV6
1026 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
1027  const ip6_addr_t *ipaddr);
1028 #endif /* LWIP_IPV6 */
1029 
1036 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
1038 typedef void (*netif_status_callback_fn)(struct netif *netif);
1039 #if LWIP_IPV4 && LWIP_IGMP
1041 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
1042  const ip4_addr_t *group, enum netif_mac_filter_action action);
1043 #endif /* LWIP_IPV4 && LWIP_IGMP */
1044 #if LWIP_IPV6 && LWIP_IPV6_MLD
1046 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
1047  const ip6_addr_t *group, enum netif_mac_filter_action action);
1048 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1049 
1050 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
1055 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
1059 #define netif_get_client_data(netif, id) (netif)->client_data[(id)]
1060 #endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
1061 
1065 struct netif {
1067  struct netif *next;
1068 
1069 #if LWIP_IPV4
1074 #endif /* LWIP_IPV4 */
1075 #if LWIP_IPV6
1077  ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
1080  u8 ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
1081 #endif /* LWIP_IPV6 */
1085 #if LWIP_IPV4
1091 #endif /* LWIP_IPV4 */
1096 #if LWIP_IPV6
1101  netif_output_ip6_fn output_ip6;
1102 #endif /* LWIP_IPV6 */
1103 #if LWIP_NETIF_STATUS_CALLBACK
1106  netif_status_callback_fn status_callback;
1107 #endif /* LWIP_NETIF_STATUS_CALLBACK */
1108 #if LWIP_NETIF_LINK_CALLBACK
1111  netif_status_callback_fn link_callback;
1112 #endif /* LWIP_NETIF_LINK_CALLBACK */
1113 #if LWIP_NETIF_REMOVE_CALLBACK
1115  netif_status_callback_fn remove_callback;
1116 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
1119  void *state;
1120 #ifdef netif_get_client_data
1122 #endif
1123 #if LWIP_IPV6_AUTOCONFIG
1125  u8 ip6_autoconfig_enabled;
1126 #endif /* LWIP_IPV6_AUTOCONFIG */
1127 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
1130 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
1131 #if LWIP_NETIF_HOSTNAME
1132  /* the hostname for this netif, NULL is a valid value */
1133  const char* hostname;
1134 #endif /* LWIP_NETIF_HOSTNAME */
1135 #if LWIP_CHECKSUM_CTRL_PER_NETIF
1136  u16 chksum_flags;
1137 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
1147  char name[2];
1150 #if MIB2_STATS
1152  u8 link_type;
1154  u32 link_speed;
1156  u32 ts;
1158  struct stats_mib2_netif_ctrs mib2_counters;
1159 #endif /* MIB2_STATS */
1160 #if LWIP_IPV4 && LWIP_IGMP
1163  netif_igmp_mac_filter_fn igmp_mac_filter;
1164 #endif /* LWIP_IPV4 && LWIP_IGMP */
1165 #if LWIP_IPV6 && LWIP_IPV6_MLD
1168  netif_mld_mac_filter_fn mld_mac_filter;
1169 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1170 #if LWIP_NETIF_HWADDRHINT
1171  u8 *addr_hint;
1172 #endif /* LWIP_NETIF_HWADDRHINT */
1173 #if ENABLE_LOOPBACK
1174  /* List of packets to be queued for ourselves. */
1175  struct pbuf *loop_first;
1176  struct pbuf *loop_last;
1177 #if LWIP_LOOPBACK_MAX_PBUFS
1178  u16 loop_cnt_current;
1179 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
1180 #endif /* ENABLE_LOOPBACK */
1181 };
1182 
1183 #if LWIP_CHECKSUM_CTRL_PER_NETIF
1184 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
1185  (netif)->chksum_flags = chksumflags; } while(0)
1186 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
1187 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
1188 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
1189 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
1190 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
1191 
1193 extern struct netif *netif_list;
1195 extern struct netif *netif_default;
1196 
1197 #if LWIP_IPV4
1199 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
1201 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
1203 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
1205 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
1207 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
1209 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
1210 #endif /* LWIP_IPV4 */
1211 
1215 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8)1 : (u8)0)
1216 
1218 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8)1 : (u8)0)
1219 
1220 #if LWIP_NETIF_HOSTNAME
1222 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
1224 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
1225 #endif /* LWIP_NETIF_HOSTNAME */
1226 
1227 #if LWIP_IGMP
1229 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
1230 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
1231 #endif /* LWIP_IGMP */
1232 
1233 #if LWIP_IPV6 && LWIP_IPV6_MLD
1235 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
1236 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
1237 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
1238 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1239 
1240 #if LWIP_IPV6
1242 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
1244 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
1245 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
1246 void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32 i0, u32 i1, u32 i2, u32 i3);
1247 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
1248 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
1249 #endif /* LWIP_IPV6 */
1250 
1251 #if LWIP_NETIF_HWADDRHINT
1252 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
1253 #else /* LWIP_NETIF_HWADDRHINT */
1254 #define NETIF_SET_HWADDRHINT(netif, hint)
1255 #endif /* LWIP_NETIF_HWADDRHINT */
1256 
1257 /* From include/lwip/prot/dhcp.h: */
1258 /* DHCP client states */
1259 typedef enum {
1269  DHCP_STATE_PERMANENT = 9, /* not yet implemented */
1271  DHCP_STATE_RELEASING = 11, /* not yet implemented */
1274 
1275 /* From include/lwip/inet.h: */
1276 
1277 struct in_addr {
1279 };
1280 
1281 struct in6_addr {
1282  union {
1285  } un;
1286 #define s6_addr un.u8_addr
1287 };
1288 
1290 #define INADDR_NONE IPADDR_NONE
1292 #define INADDR_LOOPBACK IPADDR_LOOPBACK
1294 #define INADDR_ANY IPADDR_ANY
1296 #define INADDR_BROADCAST IPADDR_BROADCAST
1297 
1298 /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
1299  to prevent this code from redefining it. */
1300 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
1301 typedef u8 sa_family_t;
1302 #endif
1303 /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
1304  to prevent this code from redefining it. */
1305 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
1306 typedef u16 in_port_t;
1307 #endif
1308 
1309 #if LWIP_IPV4
1310 /* members are in network byte order */
1311 struct sockaddr_in {
1315  struct in_addr sin_addr;
1316 #define SIN_ZERO_LEN 8
1318 };
1319 #endif /* LWIP_IPV4 */
1320 
1321 #if LWIP_IPV6
1322 struct sockaddr_in6 {
1323  u8 sin6_len; /* length of this structure */
1324  sa_family_t sin6_family; /* AF_INET6 */
1325  in_port_t sin6_port; /* Transport layer port # */
1326  u32 sin6_flowinfo; /* IPv6 flow information */
1327  struct in6_addr sin6_addr; /* IPv6 address */
1328  u32 sin6_scope_id; /* Set of interfaces for scope */
1329 };
1330 #endif /* LWIP_IPV6 */
1331 
1332 struct sockaddr {
1335  char sa_data[14];
1336 };
1337 
1341  char s2_data1[2];
1343 #if LWIP_IPV6
1344  u32 s2_data3[3];
1345 #endif /* LWIP_IPV6 */
1346 };
1347 
1348 /* Define SOCKLEN_T_DEFINED to prevent other code from redefining socklen_t. */
1349 #define SOCKLEN_T_DEFINED 1
1350 typedef int socklen_t;
1351 
1352 /* Socket protocol types (TCP/UDP/RAW) */
1353 #define SOCK_STREAM 1
1354 #define SOCK_DGRAM 2
1355 #define SOCK_RAW 3
1356 
1357 /*
1358  * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
1359  */
1360 #define SO_REUSEADDR 0x0004 /* Allow local address reuse */
1361 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
1362 #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
1363 
1364 
1365 /*
1366  * Additional options, not kept in so_options.
1367  */
1368 #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
1369 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
1370 #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
1371 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
1372 #define SO_LINGER 0x0080 /* linger on close if data present */
1373 #define SO_DONTLINGER ((int)(~SO_LINGER))
1374 #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
1375 #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
1376 #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
1377 #define SO_RCVBUF 0x1002 /* receive buffer size */
1378 #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
1379 #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
1380 #define SO_SNDTIMEO 0x1005 /* send timeout */
1381 #define SO_RCVTIMEO 0x1006 /* receive timeout */
1382 #define SO_ERROR 0x1007 /* get error status and clear */
1383 #define SO_TYPE 0x1008 /* get socket type */
1384 #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
1385 #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
1386 
1387 /*
1388  * Level number for (get/set)sockopt() to apply to socket itself.
1389  */
1390 #define SOL_SOCKET 0xfff /* options for socket level */
1391 
1392 #define AF_UNSPEC 0
1393 #define AF_INET 2
1394 #if LWIP_IPV6
1395 #define AF_INET6 10
1396 #else /* LWIP_IPV6 */
1397 #define AF_INET6 AF_UNSPEC
1398 #endif /* LWIP_IPV6 */
1399 #define PF_INET AF_INET
1400 #define PF_INET6 AF_INET6
1401 #define PF_UNSPEC AF_UNSPEC
1402 
1403 #define IPPROTO_IP 0
1404 #define IPPROTO_ICMP 1
1405 #define IPPROTO_TCP 6
1406 #define IPPROTO_UDP 17
1407 #if LWIP_IPV6
1408 #define IPPROTO_IPV6 41
1409 #define IPPROTO_ICMPV6 58
1410 #endif /* LWIP_IPV6 */
1411 #define IPPROTO_UDPLITE 136
1412 #define IPPROTO_RAW 255
1413 
1414 /* Flags we can use with send and recv. */
1415 #define MSG_PEEK 0x01 /* Peeks at an incoming message */
1416 #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
1417 #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
1418 #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
1419 #define MSG_MORE 0x10 /* Sender will send more */
1420 
1421 /*
1422  * Options for level IPPROTO_IP
1423  */
1424 #define IP_TOS 1
1425 #define IP_TTL 2
1426 
1427 #if LWIP_TCP
1428 /*
1429  * Options for level IPPROTO_TCP
1430  */
1431 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
1432 #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
1433 #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
1434 #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
1435 #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
1436 #endif /* LWIP_TCP */
1437 
1438 #if LWIP_IPV6
1439 /*
1440  * Options for level IPPROTO_IPV6
1441  */
1442 #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
1443 #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
1444 #endif /* LWIP_IPV6 */
1445 
1446 #if LWIP_UDP && LWIP_UDPLITE
1447 /*
1448  * Options for level IPPROTO_UDPLITE
1449  */
1450 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
1451 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
1452 #endif /* LWIP_UDP && LWIP_UDPLITE*/
1453 
1454 
1455 #if LWIP_MULTICAST_TX_OPTIONS
1456 /*
1457  * Options and types for UDP multicast traffic handling
1458  */
1459 #define IP_MULTICAST_TTL 5
1460 #define IP_MULTICAST_IF 6
1461 #define IP_MULTICAST_LOOP 7
1462 #endif /* LWIP_MULTICAST_TX_OPTIONS */
1463 
1464 #if LWIP_IGMP
1465 /*
1466  * Options and types related to multicast membership
1467  */
1468 #define IP_ADD_MEMBERSHIP 3
1469 #define IP_DROP_MEMBERSHIP 4
1470 
1471 typedef struct ip_mreq {
1472  struct in_addr imr_multiaddr; /* IP multicast address of group */
1473  struct in_addr imr_interface; /* local IP address of interface */
1474 } ip_mreq;
1475 #endif /* LWIP_IGMP */
1476 
1477 /*
1478  * The Type of Service provides an indication of the abstract
1479  * parameters of the quality of service desired. These parameters are
1480  * to be used to guide the selection of the actual service parameters
1481  * when transmitting a datagram through a particular network. Several
1482  * networks offer service precedence, which somehow treats high
1483  * precedence traffic as more important than other traffic (generally
1484  * by accepting only traffic above a certain precedence at time of high
1485  * load). The major choice is a three way tradeoff between low-delay,
1486  * high-reliability, and high-throughput.
1487  * The use of the Delay, Throughput, and Reliability indications may
1488  * increase the cost (in some sense) of the service. In many networks
1489  * better performance for one of these parameters is coupled with worse
1490  * performance on another. Except for very unusual cases at most two
1491  * of these three indications should be set.
1492  */
1493 #define IPTOS_TOS_MASK 0x1E
1494 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
1495 #define IPTOS_LOWDELAY 0x10
1496 #define IPTOS_THROUGHPUT 0x08
1497 #define IPTOS_RELIABILITY 0x04
1498 #define IPTOS_LOWCOST 0x02
1499 #define IPTOS_MINCOST IPTOS_LOWCOST
1500 
1501 /*
1502  * The Network Control precedence designation is intended to be used
1503  * within a network only. The actual use and control of that
1504  * designation is up to each network. The Internetwork Control
1505  * designation is intended for use by gateway control originators only.
1506  * If the actual use of these precedence designations is of concern to
1507  * a particular network, it is the responsibility of that network to
1508  * control the access to, and use of, those precedence designations.
1509  */
1510 #define IPTOS_PREC_MASK 0xe0
1511 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
1512 #define IPTOS_PREC_NETCONTROL 0xe0
1513 #define IPTOS_PREC_INTERNETCONTROL 0xc0
1514 #define IPTOS_PREC_CRITIC_ECP 0xa0
1515 #define IPTOS_PREC_FLASHOVERRIDE 0x80
1516 #define IPTOS_PREC_FLASH 0x60
1517 #define IPTOS_PREC_IMMEDIATE 0x40
1518 #define IPTOS_PREC_PRIORITY 0x20
1519 #define IPTOS_PREC_ROUTINE 0x00
1520 
1521 
1522 /*
1523  * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
1524  * lwip_ioctl only supports FIONREAD and FIONBIO, for now
1525  *
1526  * Ioctl's have the command encoded in the lower word,
1527  * and the size of any in or out parameters in the upper
1528  * word. The high 2 bits of the upper word are used
1529  * to encode the in/out status of the parameter; for now
1530  * we restrict parameters to at most 128 bytes.
1531  */
1532 #if !defined(FIONREAD) || !defined(FIONBIO)
1533 #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
1534 #define IOC_VOID 0x20000000UL /* no parameters */
1535 #define IOC_OUT 0x40000000UL /* copy out parameters */
1536 #define IOC_IN 0x80000000UL /* copy in parameters */
1537 #define IOC_INOUT (IOC_IN|IOC_OUT)
1538  /* 0x20000000 distinguishes new &
1539  old ioctl's */
1540 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
1541 
1542 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
1543 
1544 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
1545 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
1546 
1547 #ifndef FIONREAD
1548 #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
1549 #endif
1550 #ifndef FIONBIO
1551 #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
1552 #endif
1553 
1554 /* Socket I/O Controls: unimplemented */
1555 #ifndef SIOCSHIWAT
1556 #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
1557 #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
1558 #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
1559 #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
1560 #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
1561 #endif
1562 
1563 /* commands for fnctl */
1564 #ifndef F_GETFL
1565 #define F_GETFL 3
1566 #endif
1567 #ifndef F_SETFL
1568 #define F_SETFL 4
1569 #endif
1570 
1571 /* File status flags and file access modes for fnctl,
1572  these are bits in an int. */
1573 #ifndef O_NONBLOCK
1574 #define O_NONBLOCK 1 /* nonblocking I/O */
1575 #endif
1576 #ifndef O_NDELAY
1577 #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
1578 #endif
1579 
1580 #ifndef SHUT_RD
1581  #define SHUT_RD 0
1582  #define SHUT_WR 1
1583  #define SHUT_RDWR 2
1584 #endif
1585 
1586 /* FD_SET used for lwip_select */
1587 #ifndef FD_SET
1588 #undef FD_SETSIZE
1589 /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
1590 #define FD_SETSIZE MEMP_NUM_NETCONN
1591 #define FDSETSAFESET(n, code) do { \
1592  if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
1593  code; }} while(0)
1594 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
1595  (code) : 0)
1596 #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1597 #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1598 #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1599 #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
1600 
1601 typedef struct fd_set
1602 {
1603  unsigned char fd_bits [(FD_SETSIZE+7)/8];
1604 } fd_set;
1605 
1606 #elif LWIP_SOCKET_OFFSET
1607 #error LWIP_SOCKET_OFFSET does not work with external FD_SET!
1608 #elif FD_SETSIZE < MEMP_NUM_NETCONN
1609 #error "external FD_SETSIZE too small for number of sockets"
1610 #endif /* FD_SET */
1611 
1612 #ifdef PS2IP_DNS
1614 #define DNS_TMR_INTERVAL 1000
1615 
1616 /* DNS resolve types: */
1617 #define LWIP_DNS_ADDRTYPE_IPV4 0
1618 #define LWIP_DNS_ADDRTYPE_IPV6 1
1619 #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
1620 #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
1621 #if LWIP_IPV4 && LWIP_IPV6
1622 #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
1623 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
1624 #endif
1625 #elif defined(LWIP_IPV4)
1626 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
1627 #else
1628 #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
1629 #endif
1630 
1631 #if DNS_LOCAL_HOSTLIST
1633 struct local_hostlist_entry {
1635  const char *name;
1637  ip_addr_t addr;
1638  struct local_hostlist_entry *next;
1639 };
1640 #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
1641 #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
1642 #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
1643 #endif
1644 #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
1645 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
1646 #endif /* DNS_LOCAL_HOSTLIST */
1647 
1655 typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
1656 #endif
1657 
1658 /* From src/include/lwip/netdb.h: */
1659 /* some rarely used options */
1660 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
1661 #define LWIP_DNS_API_DECLARE_H_ERRNO 1
1662 #endif
1663 
1664 #ifndef LWIP_DNS_API_DEFINE_ERRORS
1665 #define LWIP_DNS_API_DEFINE_ERRORS 1
1666 #endif
1667 
1668 #ifndef LWIP_DNS_API_DEFINE_FLAGS
1669 #define LWIP_DNS_API_DEFINE_FLAGS 1
1670 #endif
1671 
1672 #ifndef LWIP_DNS_API_DECLARE_STRUCTS
1673 #define LWIP_DNS_API_DECLARE_STRUCTS 1
1674 #endif
1675 
1676 #if LWIP_DNS_API_DEFINE_ERRORS
1678 #define EAI_NONAME 200
1679 #define EAI_SERVICE 201
1680 #define EAI_FAIL 202
1681 #define EAI_MEMORY 203
1682 #define EAI_FAMILY 204
1683 
1684 #define HOST_NOT_FOUND 210
1685 #define NO_DATA 211
1686 #define NO_RECOVERY 212
1687 #define TRY_AGAIN 213
1688 #endif /* LWIP_DNS_API_DEFINE_ERRORS */
1689 
1690 #if LWIP_DNS_API_DEFINE_FLAGS
1691 /* input flags for struct addrinfo */
1692 #define AI_PASSIVE 0x01
1693 #define AI_CANONNAME 0x02
1694 #define AI_NUMERICHOST 0x04
1695 #define AI_NUMERICSERV 0x08
1696 #define AI_V4MAPPED 0x10
1697 #define AI_ALL 0x20
1698 #define AI_ADDRCONFIG 0x40
1699 #endif /* LWIP_DNS_API_DEFINE_FLAGS */
1700 
1701 #if LWIP_DNS_API_DECLARE_STRUCTS
1702 struct hostent {
1703  char *h_name; /* Official name of the host. */
1704  char **h_aliases; /* A pointer to an array of pointers to alternative host names,
1705  terminated by a null pointer. */
1706  int h_addrtype; /* Address type. */
1707  int h_length; /* The length, in bytes, of the address. */
1708  char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
1709  network byte order) for the host, terminated by a null pointer. */
1710 #define h_addr h_addr_list[0] /* for backward compatibility */
1711 };
1712 
1713 struct addrinfo {
1714  int ai_flags; /* Input flags. */
1715  int ai_family; /* Address family of socket. */
1716  int ai_socktype; /* Socket type. */
1717  int ai_protocol; /* Protocol of socket. */
1718  socklen_t ai_addrlen; /* Length of socket address. */
1719  struct sockaddr *ai_addr; /* Socket address of socket. */
1720  char *ai_canonname; /* Canonical name of service location. */
1721  struct addrinfo *ai_next; /* Pointer to next in list. */
1722 };
1723 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
1724 
1725 #define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
1726 
1727 /* From src/include/lwip/def.h: */
1728 #define htons(x) lwip_htons(x)
1729 #define ntohs(x) lwip_ntohs(x)
1730 #define htonl(x) lwip_htonl(x)
1731 #define ntohl(x) lwip_ntohl(x)
1732 
1733 #define lwip_htons(x) PP_HTONS(x)
1734 #define lwip_ntohs(x) PP_NTOHS(x)
1735 #define lwip_htonl(x) PP_HTONL(x)
1736 #define lwip_ntohl(x) PP_NTOHL(x)
1737 
1738 /* These macros should be calculated by the preprocessor and are used
1739  with compile-time constants only (so that there is no little-endian
1740  overhead at runtime). */
1741 #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
1742 #define PP_NTOHS(x) PP_HTONS(x)
1743 #define PP_HTONL(x) ((((x) & 0xff) << 24) | \
1744  (((x) & 0xff00) << 8) | \
1745  (((x) & 0xff0000UL) >> 8) | \
1746  (((x) & 0xff000000UL) >> 24))
1747 #define PP_NTOHL(x) PP_HTONL(x)
1748 
1750 typedef struct
1751 {
1752  char netif_name[4];
1753  struct in_addr ipaddr;
1754  struct in_addr netmask;
1755  struct in_addr gw;
1756  u32 dhcp_enabled;
1757  u32 dhcp_status;
1758  u8 hw_addr[8];
1759 } t_ip_info;
1760 
1761 #endif /* __TCPIP_H__ */
signed char s8_t
Definition: cc.h:8
char netif_name[8]
Definition: ps2ipc.c:38
char hostname[256]
Definition: ps2ipc.c:44
struct sockaddr * ai_addr
Definition: tcpip.h:1719
char * ai_canonname
Definition: tcpip.h:1720
int ai_socktype
Definition: tcpip.h:1716
int ai_protocol
Definition: tcpip.h:1717
socklen_t ai_addrlen
Definition: tcpip.h:1718
struct addrinfo * ai_next
Definition: tcpip.h:1721
int ai_flags
Definition: tcpip.h:1714
int ai_family
Definition: tcpip.h:1715
Definition: tcpip.h:1602
unsigned char fd_bits[(FD_SETSIZE+7)/8]
Definition: tcpip.h:1603
int h_addrtype
Definition: tcpip.h:1706
char * h_name
Definition: tcpip.h:1703
char ** h_addr_list
Definition: tcpip.h:1708
int h_length
Definition: tcpip.h:1707
char ** h_aliases
Definition: tcpip.h:1704
u8 u8_addr[16]
Definition: tcpip.h:1284
union in6_addr::@69 un
u32 u32_addr[4]
Definition: tcpip.h:1283
u32 s_addr
Definition: tcpip.h:1278
u32 addr
Definition: tcpip.h:202
u32 addr[4]
Definition: tcpip.h:352
Definition: tcpip.h:1065
u8 rs_count
Definition: tcpip.h:1129
u8 flags
Definition: tcpip.h:1145
char name[2]
Definition: tcpip.h:1147
ip_addr_t gw
Definition: tcpip.h:1073
ip_addr_t netmask
Definition: tcpip.h:1072
ip_addr_t ip_addr
Definition: tcpip.h:1071
netif_output_fn output
Definition: tcpip.h:1090
void * client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX+LWIP_NUM_NETIF_CLIENT_DATA]
Definition: tcpip.h:1121
void * state
Definition: tcpip.h:1119
struct netif * next
Definition: tcpip.h:1067
netif_input_fn input
Definition: tcpip.h:1084
netif_linkoutput_fn linkoutput
Definition: tcpip.h:1095
u8 hwaddr_len
Definition: tcpip.h:1141
u16 mtu
Definition: tcpip.h:1139
u8 num
Definition: tcpip.h:1149
u8 hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: tcpip.h:1143
Definition: tcpip.h:165
u8 flags
Definition: tcpip.h:188
struct pbuf * next
Definition: tcpip.h:167
u8 type
Definition: tcpip.h:185
void * payload
Definition: tcpip.h:170
u16 tot_len
Definition: tcpip.h:179
u16 len
Definition: tcpip.h:182
u16 ref
Definition: tcpip.h:195
struct in_addr sin_addr
Definition: tcpip.h:1315
u8 sin_len
Definition: tcpip.h:1312
char sin_zero[SIN_ZERO_LEN]
Definition: tcpip.h:1317
sa_family_t sin_family
Definition: tcpip.h:1313
in_port_t sin_port
Definition: tcpip.h:1314
sa_family_t ss_family
Definition: tcpip.h:1340
u32 s2_data2[3]
Definition: tcpip.h:1342
char s2_data1[2]
Definition: tcpip.h:1341
sa_family_t sa_family
Definition: tcpip.h:1334
u8 sa_len
Definition: tcpip.h:1333
char sa_data[14]
Definition: tcpip.h:1335
unsigned int u32
Definition: tamtypes.h:30
unsigned short u16
Definition: tamtypes.h:24
unsigned char u8
Definition: tamtypes.h:23
u16 in_port_t
Definition: tcpip.h:1306
struct netif * netif_list
err_t(* netif_init_fn)(struct netif *netif)
Definition: tcpip.h:995
u8 sa_family_t
Definition: tcpip.h:1301
struct netif * netif_default
void(* netif_status_callback_fn)(struct netif *netif)
Definition: tcpip.h:1038
lwip_internal_netif_client_data_index
Definition: tcpip.h:948
@ LWIP_NETIF_CLIENT_DATA_INDEX_MAX
Definition: tcpip.h:961
@ LWIP_NETIF_CLIENT_DATA_INDEX_DHCP
Definition: tcpip.h:950
signed char err_t
Definition: tcpip.h:95
const ip_addr_t ip_addr_any
Definition: ps2ipc.c:58
int socklen_t
Definition: tcpip.h:1350
#define SIN_ZERO_LEN
Definition: tcpip.h:1316
err_t(* netif_output_fn)(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
Definition: tcpip.h:1013
#define FD_SETSIZE
Definition: tcpip.h:1590
#define LWIP_NUM_NETIF_CLIENT_DATA
Definition: tcpip.h:58
#define ipaddr_aton(cp, addr)
Definition: tcpip.h:784
netif_mac_filter_action
Definition: tcpip.h:983
@ NETIF_ADD_MAC_FILTER
Definition: tcpip.h:987
@ NETIF_DEL_MAC_FILTER
Definition: tcpip.h:985
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: tcpip.h:1002
void(* dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
Definition: tcpip.h:1655
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: tcpip.h:1036
pbuf_type
Definition: tcpip.h:139
@ PBUF_ROM
Definition: tcpip.h:150
@ PBUF_RAM
Definition: tcpip.h:146
@ PBUF_REF
Definition: tcpip.h:154
@ PBUF_POOL
Definition: tcpip.h:161
#define NETIF_MAX_HWADDR_LEN
Definition: tcpip.h:903
struct ip4_addr_packed ip4_addr_p_t
Definition: tcpip.h:208
struct ip6_addr_packed ip6_addr_p_t
Definition: tcpip.h:357
u8 netif_alloc_client_data_id(void)
dhcp_state_enum_t
Definition: tcpip.h:1259
@ DHCP_STATE_OFF
Definition: tcpip.h:1260
@ DHCP_STATE_INIT
Definition: tcpip.h:1262
@ DHCP_STATE_BOUND
Definition: tcpip.h:1270
@ DHCP_STATE_BACKING_OFF
Definition: tcpip.h:1272
@ DHCP_STATE_PERMANENT
Definition: tcpip.h:1269
@ DHCP_STATE_CHECKING
Definition: tcpip.h:1268
@ DHCP_STATE_REBOOTING
Definition: tcpip.h:1263
@ DHCP_STATE_SELECTING
Definition: tcpip.h:1266
@ DHCP_STATE_REQUESTING
Definition: tcpip.h:1261
@ DHCP_STATE_RELEASING
Definition: tcpip.h:1271
@ DHCP_STATE_RENEWING
Definition: tcpip.h:1265
@ DHCP_STATE_REBINDING
Definition: tcpip.h:1264
@ DHCP_STATE_INFORMING
Definition: tcpip.h:1267
ip4_addr_t ip_addr_t
Definition: tcpip.h:747
pbuf_layer
Definition: tcpip.h:110
@ PBUF_RAW_TX
Definition: tcpip.h:129
@ PBUF_RAW
Definition: tcpip.h:132
@ PBUF_TRANSPORT
Definition: tcpip.h:114
@ PBUF_LINK
Definition: tcpip.h:123
@ PBUF_IP
Definition: tcpip.h:118
const ip_addr_t ip_addr_broadcast
lwip_ip_addr_type
Definition: tcpip.h:576
@ IPADDR_TYPE_V6
Definition: tcpip.h:580
@ IPADDR_TYPE_ANY
Definition: tcpip.h:582
@ IPADDR_TYPE_V4
Definition: tcpip.h:578