PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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#ifdef _EE
21/* Use the select related definitions fron newlib. */
22#include <sys/select.h>
23#endif
24
25/* Some portions of this header fall under the following copyright. The license
26 is compatible with that of ps2sdk.
27
28 This port of LWIP has LWIP_DHCP defined by default. */
29
30#ifndef PS2IP_DNS
31#define PS2IP_DNS
32#endif
33#ifndef PS2IP_DHCP
34#define PS2IP_DHCP 1
35#endif
36#ifndef LWIP_IPV4
37#define LWIP_IPV4 1
38#endif
39#ifndef LWIP_IPV6
40#define LWIP_IPV6 0
41#endif
42#ifndef LWIP_IPV6_MLD
43#define LWIP_IPV6_MLD 0
44#endif
45#ifndef LWIP_CHECKSUM_CTRL_PER_NETIF
46#define LWIP_CHECKSUM_CTRL_PER_NETIF 0
47#endif
48#ifndef LWIP_NETIF_REMOVE_CALLBACK
49#define LWIP_NETIF_REMOVE_CALLBACK 0
50#endif
51#ifndef LWIP_IPV6_AUTOCONFIG
52#define LWIP_IPV6_AUTOCONFIG 0
53#endif
54#ifndef LWIP_MULTICAST_TX_OPTIONS
55#define LWIP_MULTICAST_TX_OPTIONS 0
56#endif
57#ifndef LWIP_DHCP
58#define LWIP_DHCP 1
59#endif
60#ifndef LWIP_TCP
61#define LWIP_TCP 1
62#endif
63#ifndef LWIP_UDP
64#define LWIP_UDP 1
65#endif
66#ifndef LWIP_UDPLITE
67#define LWIP_UDPLITE 0
68#endif
69#ifndef MIB2_STATS
70#define MIB2_STATS 0
71#endif
72#ifndef ENABLE_LOOPBACK
73#define ENABLE_LOOPBACK 0
74#endif
75#ifndef DNS_LOCAL_HOSTLIST
76#define DNS_LOCAL_HOSTLIST 0
77#endif
78
79/*** Taken from src/include/lwip/opt.h. If changes were made to lwipopts.h, please update this section.
80 Some settings affect the fields present in structures like struct netif! ****/
81#define MEMP_NUM_UDP_PCB 4
82#define MEMP_NUM_TCP_PCB 5
83#define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB)
84#define LWIP_NETIF_STATUS_CALLBACK 0
85#define LWIP_NETIF_LINK_CALLBACK 0
86#define LWIP_AUTOIP 0
87#define LWIP_NETIF_HOSTNAME 0
88#define LWIP_SNMP 0
89#define LWIP_IGMP 0
90#define LWIP_NETIF_HWADDRHINT 0
91#define LWIP_LOOPBACK_MAX_PBUFS 0
92#define LWIP_NUM_NETIF_CLIENT_DATA 0
93#define LWIP_SOCKET_OFFSET 0
94#define LWIP_IPV6_SEND_ROUTER_SOLICIT 1
95#define DNS_MAX_SERVERS 2
96
97/*
98 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
99 * All rights reserved.
100 *
101 * Redistribution and use in source and binary forms, with or without modification,
102 * are permitted provided that the following conditions are met:
103 *
104 * 1. Redistributions of source code must retain the above copyright notice,
105 * this list of conditions and the following disclaimer.
106 * 2. Redistributions in binary form must reproduce the above copyright notice,
107 * this list of conditions and the following disclaimer in the documentation
108 * and/or other materials provided with the distribution.
109 * 3. The name of the author may not be used to endorse or promote products
110 * derived from this software without specific prior written permission.
111 *
112 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
113 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
114 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
115 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
116 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
117 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
118 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
119 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
120 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
121 * OF SUCH DAMAGE.
122 *
123 * This file is part of the lwIP TCP/IP stack.
124 *
125 * Author: Adam Dunkels <adam@sics.se>
126 *
127 */
128
129typedef signed char err_t; /* lwIP error type. */
130
131/* From src/include/lwip/pbuf.h: */
132
133#define PBUF_TRANSPORT_HLEN 20
134#if LWIP_IPV6
135#define PBUF_IP_HLEN 40
136#else
137#define PBUF_IP_HLEN 20
138#endif
139
168
197
199struct pbuf
200{
202 struct pbuf *next;
203
205 void *payload;
206
215
217 u16 len;
218
220 u8 /*pbuf_type*/ type;
221
224
230 u16 ref;
231};
232
233/* From include/lwip/ip4_addr.h: */
237{
238 u32 addr;
239};
240
243typedef struct ip4_addr ip4_addr_t;
244typedef struct ip4_addr_packed ip4_addr_p_t;
245
247#define IPADDR_NONE ((u32)0xffffffffUL)
249#define IPADDR_LOOPBACK ((u32)0x7f000001UL)
251#define IPADDR_ANY ((u32)0x00000000UL)
253#define IPADDR_BROADCAST ((u32)0xffffffffUL)
254
255/* Definitions of the bits in an Internet address integer.
256
257 On subnets, host and network parts are found according to
258 the subnet mask, not these masks. */
259#define IP_CLASSA(a) ((((u32)(a)) & 0x80000000UL) == 0)
260#define IP_CLASSA_NET 0xff000000
261#define IP_CLASSA_NSHIFT 24
262#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
263#define IP_CLASSA_MAX 128
264
265#define IP_CLASSB(a) ((((u32)(a)) & 0xc0000000UL) == 0x80000000UL)
266#define IP_CLASSB_NET 0xffff0000
267#define IP_CLASSB_NSHIFT 16
268#define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
269#define IP_CLASSB_MAX 65536
270
271#define IP_CLASSC(a) ((((u32)(a)) & 0xe0000000UL) == 0xc0000000UL)
272#define IP_CLASSC_NET 0xffffff00
273#define IP_CLASSC_NSHIFT 8
274#define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
275
276#define IP_CLASSD(a) (((u32)(a)&0xf0000000UL) == 0xe0000000UL)
277#define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
278#define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
279#define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
280#define IP_MULTICAST(a) IP_CLASSD(a)
281
282#define IP_EXPERIMENTAL(a) (((u32)(a)&0xf0000000UL) == 0xf0000000UL)
283#define IP_BADCLASS(a) (((u32)(a)&0xf0000000UL) == 0xf0000000UL)
284
285#define IP_LOOPBACKNET 127 /* official! */
286
287
290#define IP4_ADDR(ipaddr, a, b, c, d) \
291 (ipaddr)->addr = ((u32)((d)&0xff) << 24) | \
292 ((u32)((c)&0xff) << 16) | \
293 ((u32)((b)&0xff) << 8) | \
294 (u32)((a)&0xff)
295
299#ifndef IPADDR2_COPY
300#define IPADDR2_COPY(dest, src) memcpy(dest, src, sizeof(ip4_addr_t))
301#endif
302
304#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
306#define ip4_addr_set(dest, src) ((dest)->addr = \
307 ((src) == NULL ? 0 : \
308 (src)->addr))
310#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
312#define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
314#define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
316#define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32)IP_LOOPBACKNET) << 24))
319#define ip4_addr_set_hton(dest, src) ((dest)->addr = \
320 ((src) == NULL ? 0 : \
321 lwip_htonl((src)->addr)))
323#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
325#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
326
328#define ip4_addr_get_network(target, host, netmask) \
329 do { \
330 ((target)->addr = ((host)->addr) & ((netmask)->addr)); \
331 } while (0)
332
341#define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
342 (mask)->addr) == \
343 ((addr2)->addr & \
344 (mask)->addr))
345#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
346
347#define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
348#define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
349
350#define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
351
352#define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
353
354#define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
355
356#define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
357
358#define ip4_addr_debug_print_parts(debug, a, b, c, d) \
359 LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
360#define ip4_addr_debug_print(debug, ipaddr) \
361 ip4_addr_debug_print_parts(debug, \
362 (u16)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
363 (u16)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
364 (u16)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
365 (u16)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
366#define ip4_addr_debug_print_val(debug, ipaddr) \
367 ip4_addr_debug_print_parts(debug, \
368 ip4_addr1_16(&(ipaddr)), \
369 ip4_addr2_16(&(ipaddr)), \
370 ip4_addr3_16(&(ipaddr)), \
371 ip4_addr4_16(&(ipaddr)))
372
373/* Get one byte from the 4-byte address */
374#define ip4_addr1(ipaddr) (((const u8 *)(&(ipaddr)->addr))[0])
375#define ip4_addr2(ipaddr) (((const u8 *)(&(ipaddr)->addr))[1])
376#define ip4_addr3(ipaddr) (((const u8 *)(&(ipaddr)->addr))[2])
377#define ip4_addr4(ipaddr) (((const u8 *)(&(ipaddr)->addr))[3])
378/* These are cast to u16, with the intent that they are often arguments
379 * to printf using the U16_F format from cc.h. */
380#define ip4_addr1_16(ipaddr) ((u16)ip4_addr1(ipaddr))
381#define ip4_addr2_16(ipaddr) ((u16)ip4_addr2(ipaddr))
382#define ip4_addr3_16(ipaddr) ((u16)ip4_addr3(ipaddr))
383#define ip4_addr4_16(ipaddr) ((u16)ip4_addr4(ipaddr))
384
385#define IP4ADDR_STRLEN_MAX 16
386
387/* From include/lwip/ip6_addr.h: */
391{
392 u32 addr[4];
393};
394
396typedef struct ip6_addr ip6_addr_t;
397typedef struct ip6_addr_packed ip6_addr_p_t;
398
401#define IP6_ADDR_PART(ip6addr, index, a, b, c, d) \
402 (ip6addr)->addr[index] = ((u32)((d)&0xff) << 24) | \
403 ((u32)((c)&0xff) << 16) | \
404 ((u32)((b)&0xff) << 8) | \
405 (u32)((a)&0xff)
406
409#define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) \
410 do { \
411 (ip6addr)->addr[0] = idx0; \
412 (ip6addr)->addr[1] = idx1; \
413 (ip6addr)->addr[2] = idx2; \
414 (ip6addr)->addr[3] = idx3; \
415 } while (0)
416
418#define IP6_ADDR_BLOCK1(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
420#define IP6_ADDR_BLOCK2(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
422#define IP6_ADDR_BLOCK3(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
424#define IP6_ADDR_BLOCK4(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
426#define IP6_ADDR_BLOCK5(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
428#define IP6_ADDR_BLOCK6(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
430#define IP6_ADDR_BLOCK7(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
432#define IP6_ADDR_BLOCK8(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
433
435#define ip6_addr_copy(dest, src) \
436 do { \
437 (dest).addr[0] = (src).addr[0]; \
438 (dest).addr[1] = (src).addr[1]; \
439 (dest).addr[2] = (src).addr[2]; \
440 (dest).addr[3] = (src).addr[3]; \
441 } while (0)
443#define ip6_addr_set(dest, src) \
444 do { \
445 (dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
446 (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
447 (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
448 (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3]; \
449 } while (0)
450
452#define ip6_addr_set_zero(ip6addr) \
453 do { \
454 (ip6addr)->addr[0] = 0; \
455 (ip6addr)->addr[1] = 0; \
456 (ip6addr)->addr[2] = 0; \
457 (ip6addr)->addr[3] = 0; \
458 } while (0)
459
461#define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
463#define ip6_addr_set_loopback(ip6addr) \
464 do { \
465 (ip6addr)->addr[0] = 0; \
466 (ip6addr)->addr[1] = 0; \
467 (ip6addr)->addr[2] = 0; \
468 (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
469 } while (0)
472#define ip6_addr_set_hton(dest, src) \
473 do { \
474 (dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
475 (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
476 (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
477 (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]); \
478 } while (0)
479
480
488#define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
489 ((addr1)->addr[1] == (addr2)->addr[1]))
490
491#define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
492 ((addr1)->addr[1] == (addr2)->addr[1]) && \
493 ((addr1)->addr[2] == (addr2)->addr[2]) && \
494 ((addr1)->addr[3] == (addr2)->addr[3]))
495
496#define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
497
498#define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
499 ((ip6addr).addr[1] == 0) && \
500 ((ip6addr).addr[2] == 0) && \
501 ((ip6addr).addr[3] == 0))
502#define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
503
504#define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
505 ((ip6addr)->addr[1] == 0UL) && \
506 ((ip6addr)->addr[2] == 0UL) && \
507 ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
508
509#define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
510
511#define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
512
513#define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
514
515#define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
516
517#define ip6_addr_isipv6mappedipv4(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
518
519#define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
520#define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
521#define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
522#define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
523#define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
524#define IP6_MULTICAST_SCOPE_RESERVED 0x0
525#define IP6_MULTICAST_SCOPE_RESERVED0 0x0
526#define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
527#define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
528#define IP6_MULTICAST_SCOPE_RESERVED3 0x3
529#define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
530#define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
531#define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
532#define IP6_MULTICAST_SCOPE_GLOBAL 0xe
533#define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
534#define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
535#define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
536#define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
537#define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
538#define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
539#define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
540
541/* @todo define get/set for well-know multicast addresses, e.g. ff02::1 */
542#define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
543 ((ip6addr)->addr[1] == 0UL) && \
544 ((ip6addr)->addr[2] == 0UL) && \
545 ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
546
547#define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
548 ((ip6addr)->addr[1] == 0UL) && \
549 ((ip6addr)->addr[2] == 0UL) && \
550 ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
551#define ip6_addr_set_allnodes_linklocal(ip6addr) \
552 do { \
553 (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
554 (ip6addr)->addr[1] = 0; \
555 (ip6addr)->addr[2] = 0; \
556 (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
557 } while (0)
558
559#define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
560 ((ip6addr)->addr[1] == 0UL) && \
561 ((ip6addr)->addr[2] == 0UL) && \
562 ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
563#define ip6_addr_set_allrouters_linklocal(ip6addr) \
564 do { \
565 (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
566 (ip6addr)->addr[1] = 0; \
567 (ip6addr)->addr[2] = 0; \
568 (ip6addr)->addr[3] = PP_HTONL(0x00000002UL); \
569 } while (0)
570
571#define ip6_addr_issolicitednode(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
572 ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
573 (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)))
574
575#define ip6_addr_set_solicitednode(ip6addr, if_id) \
576 do { \
577 (ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
578 (ip6addr)->addr[1] = 0; \
579 (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
580 (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id)); \
581 } while (0)
582
583#define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
584 ((ip6addr)->addr[1] == 0) && \
585 ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
586 ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
587
588/* IPv6 address states. */
589#define IP6_ADDR_INVALID 0x00
590#define IP6_ADDR_TENTATIVE 0x08
591#define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */
592#define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */
593#define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */
594#define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */
595#define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */
596#define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */
597#define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */
598#define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */
599#define IP6_ADDR_PREFERRED 0x30
600#define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */
601
602#define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
603
604#define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
605#define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
606#define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
607#define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
608#define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
609
610#define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
611 LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
612 a, b, c, d, e, f, g, h))
613#define ip6_addr_debug_print(debug, ipaddr) \
614 ip6_addr_debug_print_parts(debug, \
615 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
616 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
617 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
618 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
619 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
620 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
621 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
622 (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
623#define ip6_addr_debug_print_val(debug, ipaddr) \
624 ip6_addr_debug_print_parts(debug, \
625 IP6_ADDR_BLOCK1(&(ipaddr)), \
626 IP6_ADDR_BLOCK2(&(ipaddr)), \
627 IP6_ADDR_BLOCK3(&(ipaddr)), \
628 IP6_ADDR_BLOCK4(&(ipaddr)), \
629 IP6_ADDR_BLOCK5(&(ipaddr)), \
630 IP6_ADDR_BLOCK6(&(ipaddr)), \
631 IP6_ADDR_BLOCK7(&(ipaddr)), \
632 IP6_ADDR_BLOCK8(&(ipaddr)))
633
634#define IP6ADDR_STRLEN_MAX 46
635
636/* From include/lwip/ip_addr.h: */
637
650
651#if LWIP_IPV4 && LWIP_IPV6
657typedef struct _ip_addr
658{
659 union
660 {
661 ip6_addr_t ip6;
662 ip4_addr_t ip4;
663 } uaddr;
665 u8 type;
666} ip_addr_t;
667
668extern const ip_addr_t ip_addr_any_type;
669
671#define IPADDR4_INIT(u32val) \
672 { \
673 {{{u32val, 0ul, 0ul, 0ul}}}, IPADDR_TYPE_V4 \
674 }
676#define IPADDR6_INIT(a, b, c, d) \
677 { \
678 {{{a, b, c, d}}}, IPADDR_TYPE_V6 \
679 }
680
682#define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
684#define IPADDR_ANY_TYPE_INIT \
685 { \
686 {{{0ul, 0ul, 0ul, 0ul}}}, IPADDR_TYPE_ANY \
687 }
688
690#define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
692#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
694#define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
696#define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
697
698#define IP_SET_TYPE_VAL(ipaddr, iptype) \
699 do { \
700 (ipaddr).type = (iptype); \
701 } while (0)
702#define IP_SET_TYPE(ipaddr, iptype) \
703 do { \
704 if ((ipaddr) != NULL) { \
705 IP_SET_TYPE_VAL(*(ipaddr), iptype); \
706 } \
707 } while (0)
708#define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
709
710#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr))
711#define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr))
712
716#define ip_2_ip6(ipaddr) (&((ipaddr)->uaddr.ip6))
720#define ip_2_ip4(ipaddr) (&((ipaddr)->uaddr.ip4))
721
723#define IP_ADDR4(ipaddr, a, b, c, d) \
724 do { \
725 IP4_ADDR(ip_2_ip4(ipaddr), a, b, c, d); \
726 IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); \
727 } while (0)
729#define IP_ADDR6(ipaddr, i0, i1, i2, i3) \
730 do { \
731 IP6_ADDR(ip_2_ip6(ipaddr), i0, i1, i2, i3); \
732 IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); \
733 } while (0)
734
736#define ip_addr_copy(dest, src) \
737 do { \
738 IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); \
739 if (IP_IS_V6_VAL(src)) { \
740 ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); \
741 } else { \
742 ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); \
743 } \
744 } while (0)
746#define ip_addr_copy_from_ip6(dest, src) \
747 do { \
748 ip6_addr_copy(*ip_2_ip6(&(dest)), src); \
749 IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); \
750 } while (0)
752#define ip_addr_copy_from_ip4(dest, src) \
753 do { \
754 ip4_addr_copy(*ip_2_ip4(&(dest)), src); \
755 IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); \
756 } while (0)
758#define ip_addr_set_ip4_u32(ipaddr, val) \
759 do { \
760 if (ipaddr) { \
761 ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
762 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); \
763 } \
764 } while (0)
766#define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \
767 ip4_addr_get_u32(ip_2_ip4(ipaddr)) : \
768 0)
770#define ip_addr_set(dest, src) \
771 do { \
772 IP_SET_TYPE(dest, IP_GET_TYPE(src)); \
773 if (IP_IS_V6(src)) { \
774 ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); \
775 } else { \
776 ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); \
777 } \
778 } while (0)
780#define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src)
782#define ip_addr_set_zero(ipaddr) \
783 do { \
784 ip6_addr_set_zero(ip_2_ip6(ipaddr)); \
785 IP_SET_TYPE(ipaddr, 0); \
786 } while (0)
788#define ip_addr_set_zero_ip4(ipaddr) \
789 do { \
790 ip6_addr_set_zero(ip_2_ip6(ipaddr)); \
791 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); \
792 } while (0)
794#define ip_addr_set_zero_ip6(ipaddr) \
795 do { \
796 ip6_addr_set_zero(ip_2_ip6(ipaddr)); \
797 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); \
798 } while (0)
800#define ip_addr_set_any(is_ipv6, ipaddr) \
801 do { \
802 if (is_ipv6) { \
803 ip6_addr_set_any(ip_2_ip6(ipaddr)); \
804 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); \
805 } else { \
806 ip4_addr_set_any(ip_2_ip4(ipaddr)); \
807 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); \
808 } \
809 } while (0)
811#define ip_addr_set_loopback(is_ipv6, ipaddr) \
812 do { \
813 if (is_ipv6) { \
814 ip6_addr_set_loopback(ip_2_ip6(ipaddr)); \
815 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); \
816 } else { \
817 ip4_addr_set_loopback(ip_2_ip4(ipaddr)); \
818 IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); \
819 } \
820 } while (0)
822#define ip_addr_set_hton(dest, src) \
823 do { \
824 if (IP_IS_V6(src)) { \
825 ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); \
826 IP_SET_TYPE(dest, IPADDR_TYPE_V6); \
827 } else { \
828 ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); \
829 IP_SET_TYPE(dest, IPADDR_TYPE_V4); \
830 } \
831 } while (0)
833#define ip_addr_get_network(target, host, netmask) \
834 do { \
835 if (IP_IS_V6(host)) { \
836 ip4_addr_set_zero(ip_2_ip4(target)); \
837 IP_SET_TYPE(target, IPADDR_TYPE_V6); \
838 } else { \
839 ip4_addr_get_network(ip_2_ip4(target), ip_2_ip4(host), ip_2_ip4(netmask)); \
840 IP_SET_TYPE(target, IPADDR_TYPE_V4); \
841 } \
842 } while (0)
844#define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
845 0 : \
846 ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
848#define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
850#define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
851 ip6_addr_isany(ip_2_ip6(ipaddr)) : \
852 ip4_addr_isany(ip_2_ip4(ipaddr)))
854#define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
855 ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
856 ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
858#define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
859 0 : \
860 ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
862#define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
863 ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
864 ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
866#define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
867 ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
868 ip4_addr_isloopback(ip_2_ip4(ipaddr)))
870#define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \
871 ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \
872 ip4_addr_islinklocal(ip_2_ip4(ipaddr)))
873#define ip_addr_debug_print(debug, ipaddr) \
874 do { \
875 if (IP_IS_V6(ipaddr)) { \
876 ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); \
877 } else { \
878 ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); \
879 } \
880 } while (0)
881#define ip_addr_debug_print_val(debug, ipaddr) \
882 do { \
883 if (IP_IS_V6_VAL(ipaddr)) { \
884 ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); \
885 } else { \
886 ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); \
887 } \
888 } while (0)
890#define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
891 ((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
893#define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
894 ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen)))
895int ipaddr_aton(const char *cp, ip_addr_t *addr);
896
898#define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
899
900#else /* LWIP_IPV4 && LWIP_IPV6 */
901
902#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
903#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1
904
905#if LWIP_IPV4
906
907typedef ip4_addr_t ip_addr_t;
908#define IPADDR4_INIT(u32val) \
909 { \
910 u32val \
911 }
912#define IP_IS_V4_VAL(ipaddr) 1
913#define IP_IS_V6_VAL(ipaddr) 0
914#define IP_IS_V4(ipaddr) 1
915#define IP_IS_V6(ipaddr) 0
916#define IP_IS_ANY_TYPE_VAL(ipaddr) 0
917#define IP_SET_TYPE_VAL(ipaddr, iptype)
918#define IP_SET_TYPE(ipaddr, iptype)
919#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
920#define ip_2_ip4(ipaddr) (ipaddr)
921#define IP_ADDR4(ipaddr, a, b, c, d) IP4_ADDR(ipaddr, a, b, c, d)
922
923#define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
924#define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src)
925#define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val)
926#define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr))
927#define ip_addr_set(dest, src) ip4_addr_set(dest, src)
928#define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src)
929#define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
930#define ip_addr_set_zero_ip4(ipaddr) ip4_addr_set_zero(ipaddr)
931#define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
932#define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr)
933#define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src)
934#define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask)
935#define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask)
936#define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
937#define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
938#define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
939#define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr)
940#define ip_addr_islinklocal(ipaddr) ip4_addr_islinklocal(ipaddr)
941#define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif)
942#define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr)
943#define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr)
944#define ip_addr_debug_print_val(debug, ipaddr) ip4_addr_debug_print_val(debug, ipaddr)
945#define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr)
946#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen)
947#define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
948
949#define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX
950
951#else /* LWIP_IPV4 */
952
953typedef ip6_addr_t ip_addr_t;
954#define IPADDR6_INIT(a, b, c, d) \
955 { \
956 { \
957 a, b, c, d \
958 } \
959 }
960#define IP_IS_V4_VAL(ipaddr) 0
961#define IP_IS_V6_VAL(ipaddr) 1
962#define IP_IS_V4(ipaddr) 0
963#define IP_IS_V6(ipaddr) 1
964#define IP_IS_ANY_TYPE_VAL(ipaddr) 0
965#define IP_SET_TYPE_VAL(ipaddr, iptype)
966#define IP_SET_TYPE(ipaddr, iptype)
967#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
968#define ip_2_ip6(ipaddr) (ipaddr)
969#define IP_ADDR6(ipaddr, i0, i1, i2, i3) IP6_ADDR(ipaddr, i0, i1, i2, i3)
970
971#define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
972#define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
973#define ip_addr_set(dest, src) ip6_addr_set(dest, src)
974#define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
975#define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
976#define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr)
977#define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
978#define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
979#define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
980#define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
981#define ip_addr_netcmp(addr1, addr2, mask) 0
982#define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
983#define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
984#define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
985#define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
986#define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr)
987#define ip_addr_isbroadcast(addr, netif) 0
988#define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
989#define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
990#define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr)
991#define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
992#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
993#define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
994
995#define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
996
997#endif /* LWIP_IPV4 */
998#endif /* LWIP_IPV4 && LWIP_IPV6 */
999
1000#if LWIP_IPV4
1001
1002extern const ip_addr_t ip_addr_any;
1003extern const ip_addr_t ip_addr_broadcast;
1004
1009#define IP_ADDR_ANY IP4_ADDR_ANY
1015#define IP4_ADDR_ANY (&ip_addr_any)
1021#define IP4_ADDR_ANY4 (ip_2_ip4(&ip_addr_any))
1022
1024#define IP_ADDR_BROADCAST (&ip_addr_broadcast)
1026#define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast))
1027
1028#endif /* LWIP_IPV4*/
1029
1030#if LWIP_IPV6
1031
1032extern const ip_addr_t ip6_addr_any;
1033
1039#define IP6_ADDR_ANY (&ip6_addr_any)
1045#define IP6_ADDR_ANY6 (ip_2_ip6(&ip6_addr_any))
1046
1047#if !LWIP_IPV4
1049#define IP_ADDR_ANY IP6_ADDR_ANY
1050#endif /* !LWIP_IPV4 */
1051
1052#endif
1053
1054#if LWIP_IPV4 && LWIP_IPV6
1056#define IP_ANY_TYPE (&ip_addr_any_type)
1057#else
1058#define IP_ANY_TYPE IP_ADDR_ANY
1059#endif
1060
1061/* From src/include/lwip/netif.h: */
1062
1063
1064/* Throughout this file, IP addresses are expected to be in
1065 * the same byte order as in IP_PCB. */
1066
1070#ifndef NETIF_MAX_HWADDR_LEN
1071#define NETIF_MAX_HWADDR_LEN 6U
1072#endif
1073
1086#define NETIF_FLAG_UP 0x01U
1089#define NETIF_FLAG_BROADCAST 0x02U
1095#define NETIF_FLAG_LINK_UP 0x04U
1099#define NETIF_FLAG_ETHARP 0x08U
1103#define NETIF_FLAG_ETHERNET 0x10U
1106#define NETIF_FLAG_IGMP 0x20U
1109#define NETIF_FLAG_MLD6 0x40U
1110
1115enum lwip_internal_netif_client_data_index {
1116#if LWIP_DHCP
1117 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
1118#endif
1119#if LWIP_AUTOIP
1120 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
1121#endif
1122#if LWIP_IGMP
1123 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
1124#endif
1125#if LWIP_IPV6_MLD
1126 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
1127#endif
1128 LWIP_NETIF_CLIENT_DATA_INDEX_MAX
1129};
1130
1131#if LWIP_CHECKSUM_CTRL_PER_NETIF
1132#define NETIF_CHECKSUM_GEN_IP 0x0001
1133#define NETIF_CHECKSUM_GEN_UDP 0x0002
1134#define NETIF_CHECKSUM_GEN_TCP 0x0004
1135#define NETIF_CHECKSUM_GEN_ICMP 0x0008
1136#define NETIF_CHECKSUM_GEN_ICMP6 0x0010
1137#define NETIF_CHECKSUM_CHECK_IP 0x0100
1138#define NETIF_CHECKSUM_CHECK_UDP 0x0200
1139#define NETIF_CHECKSUM_CHECK_TCP 0x0400
1140#define NETIF_CHECKSUM_CHECK_ICMP 0x0800
1141#define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
1142#define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
1143#define NETIF_CHECKSUM_DISABLE_ALL 0x0000
1144#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
1145
1146struct netif;
1147
1156
1162typedef err_t (*netif_init_fn)(struct netif *netif);
1169typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
1170
1171#if LWIP_IPV4
1180typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
1181 const ip4_addr_t *ipaddr);
1182#endif /* LWIP_IPV4*/
1183
1184#if LWIP_IPV6
1193typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
1194 const ip6_addr_t *ipaddr);
1195#endif /* LWIP_IPV6 */
1196
1203typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
1205typedef void (*netif_status_callback_fn)(struct netif *netif);
1206#if LWIP_IPV4 && LWIP_IGMP
1208typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
1209 const ip4_addr_t *group, enum netif_mac_filter_action action);
1210#endif /* LWIP_IPV4 && LWIP_IGMP */
1211#if LWIP_IPV6 && LWIP_IPV6_MLD
1213typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
1214 const ip6_addr_t *group, enum netif_mac_filter_action action);
1215#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1216
1217#if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
1218u8 netif_alloc_client_data_id(void);
1222#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
1226#define netif_get_client_data(netif, id) (netif)->client_data[(id)]
1227#endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
1228
1232struct netif
1233{
1235 struct netif *next;
1236
1237#if LWIP_IPV4
1240 ip_addr_t netmask;
1241 ip_addr_t gw;
1242#endif /* LWIP_IPV4 */
1243#if LWIP_IPV6
1245 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
1248 u8 ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
1249#endif /* LWIP_IPV6 */
1253#if LWIP_IPV4
1259#endif /* LWIP_IPV4 */
1264#if LWIP_IPV6
1269 netif_output_ip6_fn output_ip6;
1270#endif /* LWIP_IPV6 */
1271#if LWIP_NETIF_STATUS_CALLBACK
1274 netif_status_callback_fn status_callback;
1275#endif /* LWIP_NETIF_STATUS_CALLBACK */
1276#if LWIP_NETIF_LINK_CALLBACK
1279 netif_status_callback_fn link_callback;
1280#endif /* LWIP_NETIF_LINK_CALLBACK */
1281#if LWIP_NETIF_REMOVE_CALLBACK
1283 netif_status_callback_fn remove_callback;
1284#endif /* LWIP_NETIF_REMOVE_CALLBACK */
1287 void *state;
1288#ifdef netif_get_client_data
1289 void *client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
1290#endif
1291#if LWIP_IPV6_AUTOCONFIG
1293 u8 ip6_autoconfig_enabled;
1294#endif /* LWIP_IPV6_AUTOCONFIG */
1295#if LWIP_IPV6_SEND_ROUTER_SOLICIT
1298#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
1299#if LWIP_NETIF_HOSTNAME
1300 /* the hostname for this netif, NULL is a valid value */
1301 const char *hostname;
1302#endif /* LWIP_NETIF_HOSTNAME */
1303#if LWIP_CHECKSUM_CTRL_PER_NETIF
1304 u16 chksum_flags;
1305#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
1307 u16 mtu;
1315 char name[2];
1318#if MIB2_STATS
1320 u8 link_type;
1322 u32 link_speed;
1324 u32 ts;
1326 struct stats_mib2_netif_ctrs mib2_counters;
1327#endif /* MIB2_STATS */
1328#if LWIP_IPV4 && LWIP_IGMP
1331 netif_igmp_mac_filter_fn igmp_mac_filter;
1332#endif /* LWIP_IPV4 && LWIP_IGMP */
1333#if LWIP_IPV6 && LWIP_IPV6_MLD
1336 netif_mld_mac_filter_fn mld_mac_filter;
1337#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1338#if LWIP_NETIF_HWADDRHINT
1339 u8 *addr_hint;
1340#endif /* LWIP_NETIF_HWADDRHINT */
1341#if ENABLE_LOOPBACK
1342 /* List of packets to be queued for ourselves. */
1343 struct pbuf *loop_first;
1344 struct pbuf *loop_last;
1345#if LWIP_LOOPBACK_MAX_PBUFS
1346 u16 loop_cnt_current;
1347#endif /* LWIP_LOOPBACK_MAX_PBUFS */
1348#endif /* ENABLE_LOOPBACK */
1349};
1350
1351#if LWIP_CHECKSUM_CTRL_PER_NETIF
1352#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) \
1353 do { \
1354 (netif)->chksum_flags = chksumflags; \
1355 } while (0)
1356#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
1357#else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
1358#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
1359#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
1360#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
1361
1363extern struct netif *netif_list;
1365extern struct netif *netif_default;
1366
1367#if LWIP_IPV4
1369#define netif_ip4_addr(netif) ((const ip4_addr_t *)ip_2_ip4(&((netif)->ip_addr)))
1371#define netif_ip4_netmask(netif) ((const ip4_addr_t *)ip_2_ip4(&((netif)->netmask)))
1373#define netif_ip4_gw(netif) ((const ip4_addr_t *)ip_2_ip4(&((netif)->gw)))
1375#define netif_ip_addr4(netif) ((const ip_addr_t *)&((netif)->ip_addr))
1377#define netif_ip_netmask4(netif) ((const ip_addr_t *)&((netif)->netmask))
1379#define netif_ip_gw4(netif) ((const ip_addr_t *)&((netif)->gw))
1380#endif /* LWIP_IPV4 */
1381
1385#define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8)1 : (u8)0)
1386
1388#define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8)1 : (u8)0)
1389
1390#if LWIP_NETIF_HOSTNAME
1392#define netif_set_hostname(netif, name) \
1393 do { \
1394 if ((netif) != NULL) { \
1395 (netif)->hostname = name; \
1396 } \
1397 } while (0)
1399#define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
1400#endif /* LWIP_NETIF_HOSTNAME */
1401
1402#if LWIP_IGMP
1404#define netif_set_igmp_mac_filter(netif, function) \
1405 do { \
1406 if ((netif) != NULL) { \
1407 (netif)->igmp_mac_filter = function; \
1408 } \
1409 } while (0)
1410#define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
1411#endif /* LWIP_IGMP */
1412
1413#if LWIP_IPV6 && LWIP_IPV6_MLD
1415#define netif_set_mld_mac_filter(netif, function) \
1416 do { \
1417 if ((netif) != NULL) { \
1418 (netif)->mld_mac_filter = function; \
1419 } \
1420 } while (0)
1421#define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
1422#define netif_mld_mac_filter(netif, addr, action) \
1423 do { \
1424 if ((netif) && (netif)->mld_mac_filter) { \
1425 (netif)->mld_mac_filter((netif), (addr), (action)); \
1426 } \
1427 } while (0)
1428#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
1429
1430#if LWIP_IPV6
1432#define netif_ip_addr6(netif, i) ((const ip_addr_t *)(&((netif)->ip6_addr[i])))
1434#define netif_ip6_addr(netif, i) ((const ip6_addr_t *)ip_2_ip6(&((netif)->ip6_addr[i])))
1435void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
1436void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32 i0, u32 i1, u32 i2, u32 i3);
1437#define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
1438#define netif_set_ip6_autoconfig_enabled(netif, action) \
1439 do { \
1440 if (netif) { \
1441 (netif)->ip6_autoconfig_enabled = (action); \
1442 } \
1443 } while (0)
1444#endif /* LWIP_IPV6 */
1445
1446#if LWIP_NETIF_HWADDRHINT
1447#define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
1448#else /* LWIP_NETIF_HWADDRHINT */
1449#define NETIF_SET_HWADDRHINT(netif, hint)
1450#endif /* LWIP_NETIF_HWADDRHINT */
1451
1452/* From include/lwip/prot/dhcp.h: */
1453/* DHCP client states */
1454typedef enum {
1455 DHCP_STATE_OFF = 0,
1456 DHCP_STATE_REQUESTING = 1,
1457 DHCP_STATE_INIT = 2,
1458 DHCP_STATE_REBOOTING = 3,
1459 DHCP_STATE_REBINDING = 4,
1460 DHCP_STATE_RENEWING = 5,
1461 DHCP_STATE_SELECTING = 6,
1462 DHCP_STATE_INFORMING = 7,
1463 DHCP_STATE_CHECKING = 8,
1464 DHCP_STATE_PERMANENT = 9, /* not yet implemented */
1465 DHCP_STATE_BOUND = 10,
1466 DHCP_STATE_RELEASING = 11, /* not yet implemented */
1467 DHCP_STATE_BACKING_OFF = 12
1468} dhcp_state_enum_t;
1469
1470/* From include/lwip/inet.h: */
1471
1473{
1474 u32 s_addr;
1475};
1476
1478{
1479 union
1480 {
1481 u32 u32_addr[4];
1482 u8 u8_addr[16];
1483 } un;
1484#define s6_addr un.u8_addr
1485};
1486
1488#define INADDR_NONE IPADDR_NONE
1490#define INADDR_LOOPBACK IPADDR_LOOPBACK
1492#define INADDR_ANY IPADDR_ANY
1494#define INADDR_BROADCAST IPADDR_BROADCAST
1495
1496/* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
1497 to prevent this code from redefining it. */
1498#if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
1499typedef u8 sa_family_t;
1500#endif
1501/* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
1502 to prevent this code from redefining it. */
1503#if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
1504typedef u16 in_port_t;
1505#endif
1506
1507#if LWIP_IPV4
1508/* members are in network byte order */
1510{
1511 u8 sin_len;
1512 sa_family_t sin_family;
1513 in_port_t sin_port;
1514 struct in_addr sin_addr;
1515#define SIN_ZERO_LEN 8
1516 char sin_zero[SIN_ZERO_LEN];
1517};
1518#endif /* LWIP_IPV4 */
1519
1520#if LWIP_IPV6
1521struct sockaddr_in6
1522{
1523 u8 sin6_len; /* length of this structure */
1524 sa_family_t sin6_family; /* AF_INET6 */
1525 in_port_t sin6_port; /* Transport layer port # */
1526 u32 sin6_flowinfo; /* IPv6 flow information */
1527 struct in6_addr sin6_addr; /* IPv6 address */
1528 u32 sin6_scope_id; /* Set of interfaces for scope */
1529};
1530#endif /* LWIP_IPV6 */
1531
1533{
1534 u8 sa_len;
1535 sa_family_t sa_family;
1536 char sa_data[14];
1537};
1538
1540{
1541 u8 s2_len;
1542 sa_family_t ss_family;
1543 char s2_data1[2];
1544 u32 s2_data2[3];
1545#if LWIP_IPV6
1546 u32 s2_data3[3];
1547#endif /* LWIP_IPV6 */
1548};
1549
1550/* Define SOCKLEN_T_DEFINED to prevent other code from redefining socklen_t. */
1551#define SOCKLEN_T_DEFINED 1
1552typedef int socklen_t;
1553
1554/* Socket protocol types (TCP/UDP/RAW) */
1555#define SOCK_STREAM 1
1556#define SOCK_DGRAM 2
1557#define SOCK_RAW 3
1558
1559/*
1560 * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
1561 */
1562#define SO_REUSEADDR 0x0004 /* Allow local address reuse */
1563#define SO_KEEPALIVE 0x0008 /* keep connections alive */
1564#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
1565
1566
1567/*
1568 * Additional options, not kept in so_options.
1569 */
1570#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
1571#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
1572#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
1573#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
1574#define SO_LINGER 0x0080 /* linger on close if data present */
1575#define SO_DONTLINGER ((int)(~SO_LINGER))
1576#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
1577#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
1578#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
1579#define SO_RCVBUF 0x1002 /* receive buffer size */
1580#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
1581#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
1582#define SO_SNDTIMEO 0x1005 /* send timeout */
1583#define SO_RCVTIMEO 0x1006 /* receive timeout */
1584#define SO_ERROR 0x1007 /* get error status and clear */
1585#define SO_TYPE 0x1008 /* get socket type */
1586#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
1587#define SO_NO_CHECK 0x100a /* don't create UDP checksum */
1588
1589/*
1590 * Level number for (get/set)sockopt() to apply to socket itself.
1591 */
1592#define SOL_SOCKET 0xfff /* options for socket level */
1593
1594#define AF_UNSPEC 0
1595#define AF_INET 2
1596#if LWIP_IPV6
1597#define AF_INET6 10
1598#else /* LWIP_IPV6 */
1599#define AF_INET6 AF_UNSPEC
1600#endif /* LWIP_IPV6 */
1601#define PF_INET AF_INET
1602#define PF_INET6 AF_INET6
1603#define PF_UNSPEC AF_UNSPEC
1604
1605#define IPPROTO_IP 0
1606#define IPPROTO_ICMP 1
1607#define IPPROTO_TCP 6
1608#define IPPROTO_UDP 17
1609#if LWIP_IPV6
1610#define IPPROTO_IPV6 41
1611#define IPPROTO_ICMPV6 58
1612#endif /* LWIP_IPV6 */
1613#define IPPROTO_UDPLITE 136
1614#define IPPROTO_RAW 255
1615
1616/* Flags we can use with send and recv. */
1617#define MSG_PEEK 0x01 /* Peeks at an incoming message */
1618#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
1619#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
1620#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
1621#define MSG_MORE 0x10 /* Sender will send more */
1622
1623/*
1624 * Options for level IPPROTO_IP
1625 */
1626#define IP_TOS 1
1627#define IP_TTL 2
1628
1629#if LWIP_TCP
1630/*
1631 * Options for level IPPROTO_TCP
1632 */
1633#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
1634#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
1635#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
1636#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
1637#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
1638#endif /* LWIP_TCP */
1639
1640#if LWIP_IPV6
1641/*
1642 * Options for level IPPROTO_IPV6
1643 */
1644#define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
1645#define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
1646#endif /* LWIP_IPV6 */
1647
1648#if LWIP_UDP && LWIP_UDPLITE
1649/*
1650 * Options for level IPPROTO_UDPLITE
1651 */
1652#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
1653#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
1654#endif /* LWIP_UDP && LWIP_UDPLITE*/
1655
1656
1657#if LWIP_MULTICAST_TX_OPTIONS
1658/*
1659 * Options and types for UDP multicast traffic handling
1660 */
1661#define IP_MULTICAST_TTL 5
1662#define IP_MULTICAST_IF 6
1663#define IP_MULTICAST_LOOP 7
1664#endif /* LWIP_MULTICAST_TX_OPTIONS */
1665
1666#if LWIP_IGMP
1667/*
1668 * Options and types related to multicast membership
1669 */
1670#define IP_ADD_MEMBERSHIP 3
1671#define IP_DROP_MEMBERSHIP 4
1672
1673typedef struct ip_mreq
1674{
1675 struct in_addr imr_multiaddr; /* IP multicast address of group */
1676 struct in_addr imr_interface; /* local IP address of interface */
1677} ip_mreq;
1678#endif /* LWIP_IGMP */
1679
1680/*
1681 * The Type of Service provides an indication of the abstract
1682 * parameters of the quality of service desired. These parameters are
1683 * to be used to guide the selection of the actual service parameters
1684 * when transmitting a datagram through a particular network. Several
1685 * networks offer service precedence, which somehow treats high
1686 * precedence traffic as more important than other traffic (generally
1687 * by accepting only traffic above a certain precedence at time of high
1688 * load). The major choice is a three way tradeoff between low-delay,
1689 * high-reliability, and high-throughput.
1690 * The use of the Delay, Throughput, and Reliability indications may
1691 * increase the cost (in some sense) of the service. In many networks
1692 * better performance for one of these parameters is coupled with worse
1693 * performance on another. Except for very unusual cases at most two
1694 * of these three indications should be set.
1695 */
1696#define IPTOS_TOS_MASK 0x1E
1697#define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)
1698#define IPTOS_LOWDELAY 0x10
1699#define IPTOS_THROUGHPUT 0x08
1700#define IPTOS_RELIABILITY 0x04
1701#define IPTOS_LOWCOST 0x02
1702#define IPTOS_MINCOST IPTOS_LOWCOST
1703
1704/*
1705 * The Network Control precedence designation is intended to be used
1706 * within a network only. The actual use and control of that
1707 * designation is up to each network. The Internetwork Control
1708 * designation is intended for use by gateway control originators only.
1709 * If the actual use of these precedence designations is of concern to
1710 * a particular network, it is the responsibility of that network to
1711 * control the access to, and use of, those precedence designations.
1712 */
1713#define IPTOS_PREC_MASK 0xe0
1714#define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)
1715#define IPTOS_PREC_NETCONTROL 0xe0
1716#define IPTOS_PREC_INTERNETCONTROL 0xc0
1717#define IPTOS_PREC_CRITIC_ECP 0xa0
1718#define IPTOS_PREC_FLASHOVERRIDE 0x80
1719#define IPTOS_PREC_FLASH 0x60
1720#define IPTOS_PREC_IMMEDIATE 0x40
1721#define IPTOS_PREC_PRIORITY 0x20
1722#define IPTOS_PREC_ROUTINE 0x00
1723
1724
1725/*
1726 * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
1727 * lwip_ioctl only supports FIONREAD and FIONBIO, for now
1728 *
1729 * Ioctl's have the command encoded in the lower word,
1730 * and the size of any in or out parameters in the upper
1731 * word. The high 2 bits of the upper word are used
1732 * to encode the in/out status of the parameter; for now
1733 * we restrict parameters to at most 128 bytes.
1734 */
1735#if !defined(FIONREAD) || !defined(FIONBIO)
1736#define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
1737#define IOC_VOID 0x20000000UL /* no parameters */
1738#define IOC_OUT 0x40000000UL /* copy out parameters */
1739#define IOC_IN 0x80000000UL /* copy in parameters */
1740#define IOC_INOUT (IOC_IN | IOC_OUT)
1741/* 0x20000000 distinguishes new &
1742 old ioctl's */
1743#define _IO(x, y) (IOC_VOID | ((x) << 8) | (y))
1744
1745#define _IOR(x, y, t) (IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y))
1746
1747#define _IOW(x, y, t) (IOC_IN | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y))
1748#endif /* !defined(FIONREAD) || !defined(FIONBIO) */
1749
1750#ifndef FIONREAD
1751#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
1752#endif
1753#ifndef FIONBIO
1754#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
1755#endif
1756
1757/* Socket I/O Controls: unimplemented */
1758#ifndef SIOCSHIWAT
1759#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
1760#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
1761#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
1762#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
1763#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
1764#endif
1765
1766/* commands for fnctl */
1767#ifndef F_GETFL
1768#define F_GETFL 3
1769#endif
1770#ifndef F_SETFL
1771#define F_SETFL 4
1772#endif
1773
1774/* File status flags and file access modes for fnctl,
1775 these are bits in an int. */
1776#ifndef O_NONBLOCK
1777#define O_NONBLOCK 1 /* nonblocking I/O */
1778#endif
1779#ifndef O_NDELAY
1780#define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
1781#endif
1782
1783#ifndef SHUT_RD
1784#define SHUT_RD 0
1785#define SHUT_WR 1
1786#define SHUT_RDWR 2
1787#endif
1788
1789/* FD_SET used for lwip_select */
1790#ifndef FD_SET
1791#undef FD_SETSIZE
1792/* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
1793#define FD_SETSIZE MEMP_NUM_NETCONN
1794#define FDSETSAFESET(n, code) \
1795 do { \
1796 if (((n)-LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n)-LWIP_SOCKET_OFFSET) >= 0)) { \
1797 code; \
1798 } \
1799 } while (0)
1800#define FDSETSAFEGET(n, code) (((n)-LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n)-LWIP_SOCKET_OFFSET) >= 0) ? \
1801 (code) : \
1802 0)
1803#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1804#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1805#define FD_ISSET(n, p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
1806#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
1807
1808typedef struct fd_set
1809{
1810 unsigned char fd_bits[(FD_SETSIZE + 7) / 8];
1811} fd_set;
1812
1813#elif LWIP_SOCKET_OFFSET
1814#error LWIP_SOCKET_OFFSET does not work with external FD_SET!
1815#elif FD_SETSIZE < MEMP_NUM_NETCONN
1816#error "external FD_SETSIZE too small for number of sockets"
1817#endif /* FD_SET */
1818
1819#ifdef PS2IP_DNS
1821#define DNS_TMR_INTERVAL 1000
1822
1823/* DNS resolve types: */
1824#define LWIP_DNS_ADDRTYPE_IPV4 0
1825#define LWIP_DNS_ADDRTYPE_IPV6 1
1826#define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
1827#define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
1828#if LWIP_IPV4 && LWIP_IPV6
1829#ifndef LWIP_DNS_ADDRTYPE_DEFAULT
1830#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
1831#endif
1832#elif defined(LWIP_IPV4)
1833#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
1834#else
1835#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
1836#endif
1837
1838#if DNS_LOCAL_HOSTLIST
1840struct local_hostlist_entry
1841{
1843 const char *name;
1845 ip_addr_t addr;
1846 struct local_hostlist_entry *next;
1847};
1848#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
1849#ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
1850#define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
1851#endif
1852#define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
1853#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
1854#endif /* DNS_LOCAL_HOSTLIST */
1855
1863typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
1864#endif
1865
1866/* From src/include/lwip/netdb.h: */
1867/* some rarely used options */
1868#ifndef LWIP_DNS_API_DECLARE_H_ERRNO
1869#define LWIP_DNS_API_DECLARE_H_ERRNO 1
1870#endif
1871
1872#ifndef LWIP_DNS_API_DEFINE_ERRORS
1873#define LWIP_DNS_API_DEFINE_ERRORS 1
1874#endif
1875
1876#ifndef LWIP_DNS_API_DEFINE_FLAGS
1877#define LWIP_DNS_API_DEFINE_FLAGS 1
1878#endif
1879
1880#ifndef LWIP_DNS_API_DECLARE_STRUCTS
1881#define LWIP_DNS_API_DECLARE_STRUCTS 1
1882#endif
1883
1884#if LWIP_DNS_API_DEFINE_ERRORS
1886#define EAI_NONAME 200
1887#define EAI_SERVICE 201
1888#define EAI_FAIL 202
1889#define EAI_MEMORY 203
1890#define EAI_FAMILY 204
1891
1892#define HOST_NOT_FOUND 210
1893#define NO_DATA 211
1894#define NO_RECOVERY 212
1895#define TRY_AGAIN 213
1896#endif /* LWIP_DNS_API_DEFINE_ERRORS */
1897
1898#if LWIP_DNS_API_DEFINE_FLAGS
1899/* input flags for struct addrinfo */
1900#define AI_PASSIVE 0x01
1901#define AI_CANONNAME 0x02
1902#define AI_NUMERICHOST 0x04
1903#define AI_NUMERICSERV 0x08
1904#define AI_V4MAPPED 0x10
1905#define AI_ALL 0x20
1906#define AI_ADDRCONFIG 0x40
1907#endif /* LWIP_DNS_API_DEFINE_FLAGS */
1908
1909#if LWIP_DNS_API_DECLARE_STRUCTS
1911{
1912 char *h_name; /* Official name of the host. */
1913 char **h_aliases; /* A pointer to an array of pointers to alternative host names,
1914 terminated by a null pointer. */
1915 int h_addrtype; /* Address type. */
1916 int h_length; /* The length, in bytes, of the address. */
1917 char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
1918 network byte order) for the host, terminated by a null pointer. */
1919#define h_addr h_addr_list[0] /* for backward compatibility */
1920};
1921
1923{
1924 int ai_flags; /* Input flags. */
1925 int ai_family; /* Address family of socket. */
1926 int ai_socktype; /* Socket type. */
1927 int ai_protocol; /* Protocol of socket. */
1928 socklen_t ai_addrlen; /* Length of socket address. */
1929 struct sockaddr *ai_addr; /* Socket address of socket. */
1930 char *ai_canonname; /* Canonical name of service location. */
1931 struct addrinfo *ai_next; /* Pointer to next in list. */
1932};
1933#endif /* LWIP_DNS_API_DECLARE_STRUCTS */
1934
1935#define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
1936
1937/* From src/include/lwip/def.h: */
1938#define htons(x) lwip_htons(x)
1939#define ntohs(x) lwip_ntohs(x)
1940#define htonl(x) lwip_htonl(x)
1941#define ntohl(x) lwip_ntohl(x)
1942
1943#define lwip_htons(x) PP_HTONS(x)
1944#define lwip_ntohs(x) PP_NTOHS(x)
1945#define lwip_htonl(x) PP_HTONL(x)
1946#define lwip_ntohl(x) PP_NTOHL(x)
1947
1948/* These macros should be calculated by the preprocessor and are used
1949 with compile-time constants only (so that there is no little-endian
1950 overhead at runtime). */
1951#define PP_HTONS(x) ((((x)&0xff) << 8) | (((x)&0xff00) >> 8))
1952#define PP_NTOHS(x) PP_HTONS(x)
1953#define PP_HTONL(x) ((((x)&0xff) << 24) | \
1954 (((x)&0xff00) << 8) | \
1955 (((x)&0xff0000UL) >> 8) | \
1956 (((x)&0xff000000UL) >> 24))
1957#define PP_NTOHL(x) PP_HTONL(x)
1958
1960typedef struct
1961{
1962 char netif_name[4];
1963 struct in_addr ipaddr;
1964 struct in_addr netmask;
1965 struct in_addr gw;
1966 u32 dhcp_enabled;
1967 u32 dhcp_status;
1968 u8 hw_addr[8];
1969} t_ip_info;
1970
1971struct timeval;
1972
1973#endif /* __TCPIP_H__ */
u8 rs_count
Definition tcpip.h:1297
struct netif * netif_list
u16 ref
Definition tcpip.h:230
err_t(* netif_init_fn)(struct netif *netif)
Definition tcpip.h:1162
char name[2]
Definition tcpip.h:1315
struct netif * netif_default
void(* netif_status_callback_fn)(struct netif *netif)
Definition tcpip.h:1205
u8 hwaddr_len
Definition tcpip.h:1309
struct pbuf * next
Definition tcpip.h:202
u8 num
Definition tcpip.h:1317
err_t(* netif_output_fn)(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
Definition tcpip.h:1180
u8 flags
Definition tcpip.h:223
void * state
Definition tcpip.h:1287
void * payload
Definition tcpip.h:205
netif_output_fn output
Definition tcpip.h:1258
netif_input_fn input
Definition tcpip.h:1252
ip_addr_t ip_addr
Definition tcpip.h:1239
netif_mac_filter_action
Definition tcpip.h:1150
@ NETIF_ADD_MAC_FILTER
Definition tcpip.h:1154
@ NETIF_DEL_MAC_FILTER
Definition tcpip.h:1152
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition tcpip.h:1169
void(* dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
Definition tcpip.h:1863
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition tcpip.h:1203
pbuf_type
Definition tcpip.h:173
@ PBUF_ROM
Definition tcpip.h:184
@ PBUF_RAM
Definition tcpip.h:180
@ PBUF_REF
Definition tcpip.h:188
@ PBUF_POOL
Definition tcpip.h:195
#define NETIF_MAX_HWADDR_LEN
Definition tcpip.h:1071
u16 tot_len
Definition tcpip.h:214
u8 hwaddr[NETIF_MAX_HWADDR_LEN]
Definition tcpip.h:1311
u8 flags
Definition tcpip.h:1313
u8 type
Definition tcpip.h:220
netif_linkoutput_fn linkoutput
Definition tcpip.h:1263
u16 len
Definition tcpip.h:217
struct netif * next
Definition tcpip.h:1235
pbuf_layer
Definition tcpip.h:144
@ PBUF_RAW_TX
Definition tcpip.h:163
@ PBUF_RAW
Definition tcpip.h:166
@ PBUF_TRANSPORT
Definition tcpip.h:148
@ PBUF_LINK
Definition tcpip.h:157
@ PBUF_IP
Definition tcpip.h:152
lwip_ip_addr_type
Definition tcpip.h:642
@ IPADDR_TYPE_V6
Definition tcpip.h:646
@ IPADDR_TYPE_ANY
Definition tcpip.h:648
@ IPADDR_TYPE_V4
Definition tcpip.h:644
u16 mtu
Definition tcpip.h:1307
Definition tcpip.h:200
Definition time.h:29