wm_sockets2.0.3.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. /**
  2. * @file wm_sockets2.0.3.h
  3. *
  4. * @brief sockets2.0.3 apis
  5. *
  6. * @author winnermicro
  7. *
  8. * @copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_SOCKET_API2_0_3_H
  11. #define WM_SOCKET_API2_0_3_H
  12. #include <stdio.h>
  13. #include "wm_type_def.h"
  14. #include "wm_config.h"
  15. #include <time.h>
  16. /** If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
  17. to prevent this code from redefining it. */
  18. #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
  19. typedef u8_t sa_family_t;
  20. #endif
  21. /** If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
  22. to prevent this code from redefining it. */
  23. #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
  24. typedef u16_t in_port_t;
  25. #endif
  26. /** If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED
  27. to prevent this code from redefining it. */
  28. #if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
  29. #if !defined(_NEWLIB_VERSION_H__)
  30. typedef u32_t in_addr_t;
  31. #endif
  32. #endif
  33. struct in_addr {
  34. in_addr_t s_addr;
  35. };
  36. struct in6_addr {
  37. union {
  38. u32_t u32_addr[4];
  39. u8_t u8_addr[16];
  40. } un;
  41. #define s6_addr un.u8_addr
  42. };
  43. /** 255.255.255.255 */
  44. #define IPADDR_NONE ((u32_t)0xffffffffUL)
  45. /** 127.0.0.1 */
  46. #define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
  47. /** 0.0.0.0 */
  48. #define IPADDR_ANY ((u32_t)0x00000000UL)
  49. /** 255.255.255.255 */
  50. #define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
  51. /** 255.255.255.255 */
  52. #define INADDR_NONE IPADDR_NONE
  53. /** 127.0.0.1 */
  54. #define INADDR_LOOPBACK IPADDR_LOOPBACK
  55. /** 0.0.0.0 */
  56. #define INADDR_ANY IPADDR_ANY
  57. /** 255.255.255.255 */
  58. #define INADDR_BROADCAST IPADDR_BROADCAST
  59. /** This macro can be used to initialize a variable of type struct in6_addr
  60. to the IPv6 wildcard address. */
  61. #define IN6ADDR_ANY_INIT {{{0,0,0,0}}}
  62. /** This macro can be used to initialize a variable of type struct in6_addr
  63. to the IPv6 loopback address. */
  64. #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}}
  65. /** This variable is initialized by the system to contain the wildcard IPv6 address. */
  66. extern const struct in6_addr in6addr_any;
  67. #if TLS_CONFIG_IPV4
  68. /** members are in network byte order */
  69. struct sockaddr_in {
  70. u8_t sin_len;
  71. sa_family_t sin_family;
  72. in_port_t sin_port;
  73. struct in_addr sin_addr;
  74. #define SIN_ZERO_LEN 8
  75. char sin_zero[SIN_ZERO_LEN];
  76. };
  77. #endif /* TLS_CONFIG_IPV4 */
  78. #if TLS_CONFIG_IPV6
  79. struct sockaddr_in6 {
  80. u8_t sin6_len; /* length of this structure */
  81. sa_family_t sin6_family; /* AF_INET6 */
  82. in_port_t sin6_port; /* Transport layer port # */
  83. u32_t sin6_flowinfo; /* IPv6 flow information */
  84. struct in6_addr sin6_addr; /* IPv6 address */
  85. u32_t sin6_scope_id; /* Set of interfaces for scope */
  86. };
  87. #endif /* TLS_CONFIG_IPV6 */
  88. struct sockaddr {
  89. u8_t sa_len;
  90. sa_family_t sa_family;
  91. char sa_data[14];
  92. };
  93. struct sockaddr_storage {
  94. u8_t s2_len;
  95. sa_family_t ss_family;
  96. char s2_data1[2];
  97. u32_t s2_data2[3];
  98. #if TLS_CONFIG_IPV6
  99. u32_t s2_data3[3];
  100. #endif /* TLS_CONFIG_IPV6 */
  101. };
  102. struct hostent {
  103. char *h_name; /* Official name of the host. */
  104. char **h_aliases; /* A pointer to an array of pointers to alternative host names,
  105. terminated by a null pointer. */
  106. int h_addrtype; /* Address type. */
  107. int h_length; /* The length, in bytes, of the address. */
  108. char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
  109. network byte order) for the host, terminated by a null pointer. */
  110. #define h_addr h_addr_list[0] /* for backward compatibility */
  111. };
  112. struct sockaddr_store {
  113. u8_t s2_len;
  114. sa_family_t ss_family;
  115. char s2_data1[2];
  116. u32_t s2_data2[3];
  117. #if TLS_CONFIG_IPV6
  118. u32_t s2_data3[3];
  119. #endif /* TLS_CONFIG_IPV6 */
  120. };
  121. /** If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED
  122. to prevent this code from redefining it. */
  123. #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
  124. typedef u32_t socklen_t;
  125. #endif
  126. struct lwip_sock;
  127. /** Socket protocol types (TCP/UDP/RAW) */
  128. #define SOCK_STREAM 1
  129. #define SOCK_DGRAM 2
  130. #define SOCK_RAW 3
  131. /**
  132. * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
  133. */
  134. #define SO_REUSEADDR 0x0004 /* Allow local address reuse */
  135. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  136. #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
  137. /**
  138. * Additional options, not kept in so_options.
  139. */
  140. #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
  141. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  142. #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
  143. #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
  144. #define SO_LINGER 0x0080 /* linger on close if data present */
  145. #define SO_DONTLINGER ((int)(~SO_LINGER))
  146. #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
  147. #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
  148. #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
  149. #define SO_RCVBUF 0x1002 /* receive buffer size */
  150. #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
  151. #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
  152. #define SO_SNDTIMEO 0x1005 /* send timeout */
  153. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  154. #define SO_ERROR 0x1007 /* get error status and clear */
  155. #define SO_TYPE 0x1008 /* get socket type */
  156. #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
  157. #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
  158. /**
  159. * Structure used for manipulating linger option.
  160. */
  161. struct linger {
  162. int l_onoff; /* option on/off */
  163. int l_linger; /* linger time in seconds */
  164. };
  165. /**
  166. * Level number for (get/set)sockopt() to apply to socket itself.
  167. */
  168. #define SOL_SOCKET 0xfff /* options for socket level */
  169. #define AF_UNSPEC 0
  170. #define AF_INET 2
  171. #if TLS_CONFIG_IPV6
  172. #define AF_INET6 10
  173. #else /* TLS_CONFIG_IPV6 */
  174. #define AF_INET6 AF_UNSPEC
  175. #endif /* TLS_CONFIG_IPV6 */
  176. #define PF_INET AF_INET
  177. #define PF_INET6 AF_INET6
  178. #define PF_UNSPEC AF_UNSPEC
  179. #define IPPROTO_IP 0
  180. #define IPPROTO_ICMP 1
  181. #define IPPROTO_TCP 6
  182. #define IPPROTO_UDP 17
  183. #if TLS_CONFIG_IPV6
  184. #define IPPROTO_IPV6 41
  185. #define IPPROTO_ICMPV6 58
  186. #endif /* TLS_CONFIG_IPV6 */
  187. #define IPPROTO_UDPLITE 136
  188. #define IPPROTO_RAW 255
  189. /** Flags we can use with send and recv. */
  190. #define MSG_PEEK 0x01 /* Peeks at an incoming message */
  191. #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
  192. #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
  193. #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
  194. #define MSG_MORE 0x10 /* Sender will send more */
  195. /**
  196. * Options for level IPPROTO_IP
  197. */
  198. #define IP_TOS 1
  199. #define IP_TTL 2
  200. /*
  201. * Options for level IPPROTO_TCP
  202. */
  203. #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
  204. #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
  205. #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
  206. #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
  207. #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
  208. #if TLS_CONFIG_IPV6
  209. /**
  210. * Options for level IPPROTO_IPV6
  211. */
  212. #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
  213. #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
  214. #endif /* TLS_CONFIG_IPV6 */
  215. /**
  216. * Options for level IPPROTO_UDPLITE
  217. */
  218. #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
  219. #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
  220. #if TLS_CONFIG_IGMP
  221. /**
  222. * Options and types for UDP multicast traffic handling
  223. */
  224. #define IP_MULTICAST_TTL 5
  225. #define IP_MULTICAST_IF 6
  226. #define IP_MULTICAST_LOOP 7
  227. #endif /* TLS_CONFIG_IGMP */
  228. #if 1// TLS_CONFIG_IGMP
  229. /**
  230. * Options and types related to multicast membership
  231. */
  232. #define IP_ADD_MEMBERSHIP 3
  233. #define IP_DROP_MEMBERSHIP 4
  234. typedef struct ip_mreq {
  235. struct in_addr imr_multiaddr; /* IP multicast address of group */
  236. struct in_addr imr_interface; /* local IP address of interface */
  237. } ip_mreq;
  238. #if TLS_CONFIG_IPV6
  239. #define IPV6_JOIN_GROUP 38
  240. #define IPV6_LEAVE_GROUP 39
  241. typedef struct ipv6_mreq {
  242. struct in6_addr ipv6mr_multiaddr; /* IP multicast address of group */
  243. int ipv6mr_interface; /* index of interface */
  244. } ipv6_mreq;
  245. #endif
  246. #endif /* TLS_CONFIG_IGMP */
  247. /**
  248. * @brief The Type of Service provides an indication of the abstract
  249. * parameters of the quality of service desired. These parameters are
  250. * to be used to guide the selection of the actual service parameters
  251. * when transmitting a datagram through a particular network. Several
  252. * networks offer service precedence, which somehow treats high
  253. * precedence traffic as more important than other traffic (generally
  254. * by accepting only traffic above a certain precedence at time of high
  255. * load). The major choice is a three way tradeoff between low-delay,
  256. * high-reliability, and high-throughput.
  257. * The use of the Delay, Throughput, and Reliability indications may
  258. * increase the cost (in some sense) of the service. In many networks
  259. * better performance for one of these parameters is coupled with worse
  260. * performance on another. Except for very unusual cases at most two
  261. * of these three indications should be set.
  262. */
  263. #define IPTOS_TOS_MASK 0x1E
  264. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  265. #define IPTOS_LOWDELAY 0x10
  266. #define IPTOS_THROUGHPUT 0x08
  267. #define IPTOS_RELIABILITY 0x04
  268. #define IPTOS_LOWCOST 0x02
  269. #define IPTOS_MINCOST IPTOS_LOWCOST
  270. /*
  271. * @brief The Network Control precedence designation is intended to be used
  272. * within a network only. The actual use and control of that
  273. * designation is up to each network. The Internetwork Control
  274. * designation is intended for use by gateway control originators only.
  275. * If the actual use of these precedence designations is of concern to
  276. * a particular network, it is the responsibility of that network to
  277. * control the access to, and use of, those precedence designations.
  278. */
  279. #define IPTOS_PREC_MASK 0xe0
  280. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  281. #define IPTOS_PREC_NETCONTROL 0xe0
  282. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  283. #define IPTOS_PREC_CRITIC_ECP 0xa0
  284. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  285. #define IPTOS_PREC_FLASH 0x60
  286. #define IPTOS_PREC_IMMEDIATE 0x40
  287. #define IPTOS_PREC_PRIORITY 0x20
  288. #define IPTOS_PREC_ROUTINE 0x00
  289. /*
  290. * @brief Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  291. * lwip_ioctl only supports FIONREAD and FIONBIO, for now
  292. *
  293. * Ioctl's have the command encoded in the lower word,
  294. * and the size of any in or out parameters in the upper
  295. * word. The high 2 bits of the upper word are used
  296. * to encode the in/out status of the parameter; for now
  297. * we restrict parameters to at most 128 bytes.
  298. */
  299. #if !defined(FIONREAD) || !defined(FIONBIO)
  300. #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
  301. #define IOC_VOID 0x20000000UL /* no parameters */
  302. #define IOC_OUT 0x40000000UL /* copy out parameters */
  303. #define IOC_IN 0x80000000UL /* copy in parameters */
  304. #define IOC_INOUT (IOC_IN|IOC_OUT)
  305. /* 0x20000000 distinguishes new &
  306. old ioctl's */
  307. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  308. #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  309. #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  310. #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
  311. #ifndef FIONREAD
  312. #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
  313. #endif
  314. #ifndef FIONBIO
  315. #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
  316. #endif
  317. /** Socket I/O Controls: unimplemented */
  318. #ifndef SIOCSHIWAT
  319. #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
  320. #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
  321. #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
  322. #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
  323. #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
  324. #endif
  325. /** commands for fnctl */
  326. #ifndef F_GETFL
  327. #define F_GETFL 3
  328. #endif
  329. #ifndef F_SETFL
  330. #define F_SETFL 4
  331. #endif
  332. /** File status flags and file access modes for fnctl,
  333. these are bits in an int. */
  334. #ifndef O_NONBLOCK
  335. #define O_NONBLOCK 1 /* nonblocking I/O */
  336. #endif
  337. #ifndef O_NDELAY
  338. #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
  339. #endif
  340. #ifndef SHUT_RD
  341. #define SHUT_RD 0
  342. #define SHUT_WR 1
  343. #define SHUT_RDWR 2
  344. #endif
  345. /** FD_SET used for lwip_select */
  346. #ifndef FD_SET
  347. #undef FD_SETSIZE
  348. #ifndef LWIP_SOCKET_OFFSET
  349. #define LWIP_SOCKET_OFFSET 0
  350. #endif
  351. #ifndef MEMP_NUM_NETCONN
  352. #define MEMP_NUM_NETCONN 8
  353. #endif
  354. /** Make FD_SETSIZE match NUM_SOCKETS in socket.c */
  355. #define FD_SETSIZE MEMP_NUM_NETCONN
  356. #define FDSETSAFESET(n, code) do { \
  357. if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
  358. code; }} while(0)
  359. #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
  360. (code) : 0)
  361. #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  362. #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  363. #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  364. #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
  365. typedef struct fd_set
  366. {
  367. unsigned char fd_bits [(FD_SETSIZE+7)/8];
  368. } fd_set;
  369. #elif LWIP_SOCKET_OFFSET
  370. #error LWIP_SOCKET_OFFSET does not work with external FD_SET!
  371. #endif /* FD_SET */
  372. /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
  373. * by your system, set this to 0 and include <sys/time.h> in cc.h */
  374. #ifndef LWIP_TIMEVAL_PRIVATE
  375. #define LWIP_TIMEVAL_PRIVATE 0
  376. #endif
  377. #if LWIP_TIMEVAL_PRIVATE
  378. struct timeval {
  379. long tv_sec; /* seconds */
  380. long tv_usec; /* and microseconds */
  381. };
  382. #endif /* LWIP_TIMEVAL_PRIVATE */
  383. int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  384. int bind(int s, const struct sockaddr *name, socklen_t namelen);
  385. int shutdown(int s, int how);
  386. int closesocket(int s);
  387. int connect(int s, const struct sockaddr *name, socklen_t namelen);
  388. int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
  389. int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
  390. int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
  391. int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
  392. int listen(int s, int backlog);
  393. int recv(int s, void *mem, size_t len, int flags);
  394. int recvfrom(int s, void *mem, size_t len, int flags,
  395. struct sockaddr *from, socklen_t *fromlen);
  396. int send(int s, const void *data, size_t size, int flags);
  397. int sendto(int s, const void *data, size_t size, int flags,
  398. const struct sockaddr *to, socklen_t tolen);
  399. int socket(int domain, int type, int protocol);
  400. int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
  401. struct timeval *timeout);
  402. int ioctlsocket(int s, long cmd, void *argp);
  403. int fcntl(int s, int cmd, int val);
  404. struct hostent* gethostbyname(const char *name);
  405. /** @ingroup socket */
  406. #define read(s,mem,len) recv(s,mem,len,0)
  407. /** @ingroup socket */
  408. #define write(s,dataptr,len) send(s,dataptr,len,0)
  409. /** @ingroup socket */
  410. #define close(s) closesocket(s)
  411. /** @ingroup socket */
  412. #define ioctl(s,cmd,argp) ioctlsocket(s,cmd,argp)
  413. u32_t ipaddr_addr(const char *cp);
  414. #ifdef htonl
  415. #undef htonl
  416. #endif /* htonl */
  417. #ifdef ntohl
  418. #undef ntohl
  419. #endif /* ntohl */
  420. #ifdef htons
  421. #undef htons
  422. #endif /* htons */
  423. #ifdef ntohs
  424. #undef ntohs
  425. #endif /* ntohs */
  426. #define htons(n) (((n & 0xff) << 8) | ((n & 0xff00) >> 8))
  427. #define htonl(n) (((n & 0xff) << 24) |\
  428. ((n & 0xff00) << 8) |\
  429. ((n & 0xff0000UL) >> 8) |\
  430. ((n & 0xff000000UL) >> 24))
  431. #define ntohs(n) htons(n)
  432. #define ntohl(n) htonl(n)
  433. /** Create u32_t value from bytes */
  434. #define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \
  435. ((u32_t)((b) & 0xff) << 16) | \
  436. ((u32_t)((c) & 0xff) << 8) | \
  437. (u32_t)((d) & 0xff))
  438. #define PP_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
  439. (((x) & 0x0000ff00UL) << 8) | \
  440. (((x) & 0x00ff0000UL) >> 8) | \
  441. (((x) & 0xff000000UL) >> 24))
  442. #if TLS_CONFIG_IPV4
  443. /** This is the aligned version of ip4_addr_t,
  444. used as local variable, on the stack, etc. */
  445. struct ip4_addr {
  446. u32_t addr;
  447. };
  448. /** ip4_addr_t uses a struct for convenience only, so that the same defines can
  449. * operate both on ip4_addr_t as well as on ip4_addr_p_t. */
  450. typedef struct ip4_addr ip4_addr_t;
  451. /** Set an IP address given by the four byte-parts */
  452. #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
  453. /** MEMCPY-like copying of IP addresses where addresses are known to be
  454. * 16-bit-aligned if the port is correctly configured (so a port could define
  455. * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */
  456. #ifndef IPADDR2_COPY
  457. #define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t))
  458. #endif
  459. /** Copy IP address - faster than ip4_addr_set: no NULL check */
  460. #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
  461. /** Safely copy one IP address to another (src may be NULL) */
  462. #define ip4_addr_set(dest, src) ((dest)->addr = \
  463. ((src) == NULL ? 0 : \
  464. (src)->addr))
  465. /** Set complete address to zero */
  466. #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
  467. /** Set address to IPADDR_ANY (no need for lwip_htonl()) */
  468. #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
  469. /** Set address to loopback address */
  470. #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
  471. /** Check if an address is in the loopback region */
  472. #define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
  473. /** Safely copy one IP address to another and change byte order
  474. * from host- to network-order. */
  475. #define ip4_addr_set_hton(dest, src) ((dest)->addr = \
  476. ((src) == NULL ? 0:\
  477. lwip_htonl((src)->addr)))
  478. /** IPv4 only: set the IP address given as an u32_t */
  479. #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
  480. /** IPv4 only: get the IP address as an u32_t */
  481. #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
  482. /** Get the network address by combining host address with netmask */
  483. #define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
  484. /**
  485. * @brief Determine if two address are on the same network.
  486. *
  487. * @arg addr1 IP address 1
  488. * @arg addr2 IP address 2
  489. * @arg mask network identifier mask
  490. * @return !0 if the network identifiers of both address match
  491. */
  492. #define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
  493. (mask)->addr) == \
  494. ((addr2)->addr & \
  495. (mask)->addr))
  496. #define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
  497. #define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
  498. #define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
  499. #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
  500. u8_t ip4_addr_netmask_valid(u32_t netmask);
  501. #define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
  502. #define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
  503. #define ip4_addr_debug_print_parts(debug, a, b, c, d) \
  504. LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
  505. #define ip4_addr_debug_print(debug, ipaddr) \
  506. ip4_addr_debug_print_parts(debug, \
  507. (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
  508. (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
  509. (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
  510. (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
  511. #define ip4_addr_debug_print_val(debug, ipaddr) \
  512. ip4_addr_debug_print_parts(debug, \
  513. ip4_addr1_16(&(ipaddr)), \
  514. ip4_addr2_16(&(ipaddr)), \
  515. ip4_addr3_16(&(ipaddr)), \
  516. ip4_addr4_16(&(ipaddr)))
  517. /** Get one byte from the 4-byte address */
  518. #define ip4_addr1(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[0])
  519. #define ip4_addr2(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[1])
  520. #define ip4_addr3(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[2])
  521. #define ip4_addr4(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[3])
  522. /** These are cast to u16_t, with the intent that they are often arguments
  523. * to printf using the U16_F format from cc.h. */
  524. #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
  525. #define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
  526. #define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
  527. #define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
  528. #define IP4ADDR_STRLEN_MAX 16
  529. /** For backwards compatibility */
  530. #define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
  531. u32_t ipaddr_addr(const char *cp);
  532. int ip4addr_aton(const char *cp, ip4_addr_t *addr);
  533. /** returns ptr to static buffer; not reentrant! */
  534. char *ip4addr_ntoa(const ip4_addr_t *addr);
  535. char *ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
  536. /** directly map this to the lwip internal functions */
  537. #define inet_addr(cp) ipaddr_addr(cp)
  538. #define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
  539. #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr))
  540. #endif
  541. #if TLS_CONFIG_IPV6
  542. /** This is the aligned version of ip6_addr_t,
  543. used as local variable, on the stack, etc. */
  544. struct ip6_addr {
  545. u32_t addr[4];
  546. };
  547. /** IPv6 address */
  548. typedef struct ip6_addr ip6_addr_t;
  549. /** Set an IPv6 partial address given by byte-parts */
  550. #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \
  551. (ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
  552. /** Set a full IPv6 address by passing the 4 u32_t indices in network byte order
  553. (use PP_HTONL() for constants) */
  554. #define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
  555. (ip6addr)->addr[0] = idx0; \
  556. (ip6addr)->addr[1] = idx1; \
  557. (ip6addr)->addr[2] = idx2; \
  558. (ip6addr)->addr[3] = idx3; } while(0)
  559. /** Access address in 16-bit block */
  560. #define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
  561. /** Access address in 16-bit block */
  562. #define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
  563. /** Access address in 16-bit block */
  564. #define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
  565. /** Access address in 16-bit block */
  566. #define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
  567. /** Access address in 16-bit block */
  568. #define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
  569. /** Access address in 16-bit block */
  570. #define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
  571. /** Access address in 16-bit block */
  572. #define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
  573. /** Access address in 16-bit block */
  574. #define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
  575. /** Copy IPv6 address - faster than ip6_addr_set: no NULL check */
  576. #define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
  577. (dest).addr[1] = (src).addr[1]; \
  578. (dest).addr[2] = (src).addr[2]; \
  579. (dest).addr[3] = (src).addr[3];}while(0)
  580. /** Safely copy one IPv6 address to another (src may be NULL) */
  581. #define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
  582. (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
  583. (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
  584. (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3];}while(0)
  585. /** Set complete address to zero */
  586. #define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
  587. (ip6addr)->addr[1] = 0; \
  588. (ip6addr)->addr[2] = 0; \
  589. (ip6addr)->addr[3] = 0;}while(0)
  590. /** Set address to ipv6 'any' (no need for lwip_htonl()) */
  591. #define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
  592. /** Set address to ipv6 loopback address */
  593. #define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \
  594. (ip6addr)->addr[1] = 0; \
  595. (ip6addr)->addr[2] = 0; \
  596. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  597. /** Safely copy one IPv6 address to another and change byte order
  598. * from host- to network-order. */
  599. #define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
  600. (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
  601. (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
  602. (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]);}while(0)
  603. /**
  604. * @brief Determine if two IPv6 address are on the same network.
  605. *
  606. * @arg addr1 IPv6 address 1
  607. * @arg addr2 IPv6 address 2
  608. * @return !0 if the network identifiers of both address match
  609. */
  610. #define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  611. ((addr1)->addr[1] == (addr2)->addr[1]))
  612. #define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  613. ((addr1)->addr[1] == (addr2)->addr[1]) && \
  614. ((addr1)->addr[2] == (addr2)->addr[2]) && \
  615. ((addr1)->addr[3] == (addr2)->addr[3]))
  616. #define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
  617. #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
  618. ((ip6addr).addr[1] == 0) && \
  619. ((ip6addr).addr[2] == 0) && \
  620. ((ip6addr).addr[3] == 0))
  621. #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
  622. #define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
  623. ((ip6addr)->addr[1] == 0UL) && \
  624. ((ip6addr)->addr[2] == 0UL) && \
  625. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  626. #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
  627. #define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
  628. #define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
  629. #define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
  630. #define ip6_addr_isipv4mappedipv6(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
  631. #define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
  632. #define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
  633. #define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
  634. #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
  635. #define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
  636. #define IP6_MULTICAST_SCOPE_RESERVED 0x0
  637. #define IP6_MULTICAST_SCOPE_RESERVED0 0x0
  638. #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
  639. #define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
  640. #define IP6_MULTICAST_SCOPE_RESERVED3 0x3
  641. #define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
  642. #define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
  643. #define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
  644. #define IP6_MULTICAST_SCOPE_GLOBAL 0xe
  645. #define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
  646. #define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
  647. #define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
  648. #define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
  649. #define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
  650. #define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
  651. #define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
  652. /** @todo define get/set for well-know multicast addresses, e.g. ff02::1 */
  653. #define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
  654. ((ip6addr)->addr[1] == 0UL) && \
  655. ((ip6addr)->addr[2] == 0UL) && \
  656. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  657. #define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  658. ((ip6addr)->addr[1] == 0UL) && \
  659. ((ip6addr)->addr[2] == 0UL) && \
  660. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  661. #define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  662. (ip6addr)->addr[1] = 0; \
  663. (ip6addr)->addr[2] = 0; \
  664. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  665. #define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  666. ((ip6addr)->addr[1] == 0UL) && \
  667. ((ip6addr)->addr[2] == 0UL) && \
  668. ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
  669. #define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  670. (ip6addr)->addr[1] = 0; \
  671. (ip6addr)->addr[2] = 0; \
  672. (ip6addr)->addr[3] = PP_HTONL(0x00000002UL);}while(0)
  673. #define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  674. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  675. (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) )
  676. #define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  677. (ip6addr)->addr[1] = 0; \
  678. (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
  679. (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id));}while(0)
  680. #define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  681. ((ip6addr)->addr[1] == 0) && \
  682. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  683. ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
  684. /* IPv6 address states. */
  685. #define IP6_ADDR_INVALID 0x00
  686. #define IP6_ADDR_TENTATIVE 0x08
  687. #define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */
  688. #define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */
  689. #define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */
  690. #define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */
  691. #define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */
  692. #define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */
  693. #define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */
  694. #define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */
  695. #define IP6_ADDR_PREFERRED 0x30
  696. #define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */
  697. #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
  698. #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
  699. #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
  700. #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
  701. #define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
  702. #define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
  703. #define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
  704. LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
  705. a, b, c, d, e, f, g, h))
  706. #define ip6_addr_debug_print(debug, ipaddr) \
  707. ip6_addr_debug_print_parts(debug, \
  708. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
  709. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
  710. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
  711. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
  712. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
  713. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
  714. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
  715. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
  716. #define ip6_addr_debug_print_val(debug, ipaddr) \
  717. ip6_addr_debug_print_parts(debug, \
  718. IP6_ADDR_BLOCK1(&(ipaddr)), \
  719. IP6_ADDR_BLOCK2(&(ipaddr)), \
  720. IP6_ADDR_BLOCK3(&(ipaddr)), \
  721. IP6_ADDR_BLOCK4(&(ipaddr)), \
  722. IP6_ADDR_BLOCK5(&(ipaddr)), \
  723. IP6_ADDR_BLOCK6(&(ipaddr)), \
  724. IP6_ADDR_BLOCK7(&(ipaddr)), \
  725. IP6_ADDR_BLOCK8(&(ipaddr)))
  726. #define IP6ADDR_STRLEN_MAX 46
  727. int ip6addr_aton(const char *cp, ip6_addr_t *addr);
  728. /** returns ptr to static buffer; not reentrant! */
  729. char *ip6addr_ntoa(const ip6_addr_t *addr);
  730. char *ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen);
  731. #endif
  732. /** @ingroup ipaddr
  733. * IP address types for use in ip_addr_t.type member.
  734. * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type().
  735. */
  736. enum lwip_ip_addr_type {
  737. /** IPv4 */
  738. IPADDR_TYPE_V4 = 0U,
  739. /** IPv6 */
  740. IPADDR_TYPE_V6 = 6U,
  741. /** IPv4+IPv6 ("dual-stack") */
  742. IPADDR_TYPE_ANY = 46U
  743. };
  744. #if TLS_CONFIG_IPV4&&TLS_CONFIG_IPV6
  745. /**
  746. * @ingroup ipaddr
  747. * A union struct for both IP version's addresses.
  748. * ATTENTION: watch out for its size when adding IPv6 address scope!
  749. */
  750. typedef struct ip_addr {
  751. union {
  752. ip6_addr_t ip6;
  753. ip4_addr_t ip4;
  754. } u_addr;
  755. /** @ref lwip_ip_addr_type */
  756. u8_t type;
  757. } ip_addr_t;
  758. extern const ip_addr_t ip_addr_any_type;
  759. /** @ingroup ip4addr */
  760. #define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_V4 }
  761. /** @ingroup ip4addr */
  762. #define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d)))
  763. /** @ingroup ip6addr */
  764. #define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
  765. /** @ingroup ip6addr */
  766. #define IPADDR6_INIT_HOST(a, b, c, d) { { { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } } }, IPADDR_TYPE_V6 }
  767. /** @ingroup ipaddr */
  768. #define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
  769. /** @ingroup ipaddr */
  770. #define IPADDR_ANY_TYPE_INIT { { { { 0ul, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_ANY }
  771. /** @ingroup ip4addr */
  772. #define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
  773. /** @ingroup ip6addr */
  774. #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
  775. /** @ingroup ip4addr */
  776. #define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
  777. /** @ingroup ip6addr */
  778. #define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
  779. #define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
  780. #define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
  781. #define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
  782. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr))
  783. #define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr))
  784. /** @ingroup ip6addr
  785. * Convert generic ip address to specific protocol version
  786. */
  787. #define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
  788. /** @ingroup ip4addr
  789. * Convert generic ip address to specific protocol version
  790. */
  791. #define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
  792. /** @ingroup ip4addr */
  793. #define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \
  794. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0)
  795. /** @ingroup ip6addr */
  796. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \
  797. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0)
  798. /** @ingroup ip6addr */
  799. #define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3))
  800. /** @ingroup ipaddr */
  801. #define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
  802. ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
  803. ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
  804. /** @ingroup ip6addr */
  805. #define ip_addr_copy_from_ip6(dest, src) do{ \
  806. ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0)
  807. /** @ingroup ip4addr */
  808. #define ip_addr_copy_from_ip4(dest, src) do{ \
  809. ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }while(0)
  810. /** @ingroup ip4addr */
  811. #define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
  812. IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  813. /** @ingroup ip4addr */
  814. #define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \
  815. ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0)
  816. /** @ingroup ipaddr */
  817. #define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \
  818. ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \
  819. ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }}while(0)
  820. /** @ingroup ipaddr */
  821. #define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src)
  822. /** @ingroup ipaddr */
  823. #define ip_addr_set_zero(ipaddr) do{ \
  824. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
  825. /** @ingroup ip5addr */
  826. #define ip_addr_set_zero_ip4(ipaddr) do{ \
  827. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }while(0)
  828. /** @ingroup ip6addr */
  829. #define ip_addr_set_zero_ip6(ipaddr) do{ \
  830. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }while(0)
  831. /** @ingroup ipaddr */
  832. #define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
  833. ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  834. ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  835. /** @ingroup ipaddr */
  836. #define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
  837. ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  838. ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  839. /** @ingroup ipaddr */
  840. #define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \
  841. ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
  842. ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
  843. /** @ingroup ipaddr */
  844. #define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \
  845. ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \
  846. 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)
  847. /** @ingroup ipaddr */
  848. #define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
  849. 0 : \
  850. ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
  851. /** @ingroup ipaddr */
  852. #define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \
  853. ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
  854. ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
  855. /** @ingroup ipaddr */
  856. #define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  857. ip6_addr_isany(ip_2_ip6(ipaddr)) : \
  858. ip4_addr_isany(ip_2_ip4(ipaddr)))
  859. /** @ingroup ipaddr */
  860. #define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
  861. ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
  862. ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
  863. /** @ingroup ipaddr */
  864. #define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
  865. 0 : \
  866. ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
  867. /** @ingroup ipaddr */
  868. #define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  869. ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
  870. ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
  871. /** @ingroup ipaddr */
  872. #define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  873. ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
  874. ip4_addr_isloopback(ip_2_ip4(ipaddr)))
  875. /** @ingroup ipaddr */
  876. #define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  877. ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \
  878. ip4_addr_islinklocal(ip_2_ip4(ipaddr)))
  879. #define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \
  880. ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \
  881. ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0)
  882. #define ip_addr_debug_print_val(debug, ipaddr) do { if(IP_IS_V6_VAL(ipaddr)) { \
  883. ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); } else { \
  884. ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); }}while(0)
  885. /** @ingroup ipaddr */
  886. #define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
  887. ((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
  888. /** @ingroup ipaddr */
  889. #define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
  890. ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen)))
  891. int ipaddr_aton(const char *cp, ip_addr_t *addr);
  892. /** @ingroup ipaddr */
  893. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  894. /** @ingroup ipaddr */
  895. #define ip4_2_ipv4_mapped_ipv6(ip6addr, ip4addr) do { \
  896. (ip6addr)->addr[3] = (ip4addr)->addr; \
  897. (ip6addr)->addr[2] = PP_HTONL(0x0000FFFFUL); \
  898. (ip6addr)->addr[1] = 0; \
  899. (ip6addr)->addr[0] = 0; } while(0);
  900. /** @ingroup ipaddr */
  901. #define unmap_ipv4_mapped_ipv6(ip4addr, ip6addr) \
  902. (ip4addr)->addr = (ip6addr)->addr[3];
  903. #define IP46_ADDR_ANY(type) (((type) == IPADDR_TYPE_V6)? IP6_ADDR_ANY : IP4_ADDR_ANY)
  904. #else
  905. #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
  906. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1
  907. #if TLS_CONFIG_IPV4
  908. typedef ip4_addr_t ip_addr_t;
  909. #define IPADDR4_INIT(u32val) { u32val }
  910. #define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d)))
  911. #define IP_IS_V4_VAL(ipaddr) 1
  912. #define IP_IS_V6_VAL(ipaddr) 0
  913. #define IP_IS_V4(ipaddr) 1
  914. #define IP_IS_V6(ipaddr) 0
  915. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  916. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  917. #define IP_SET_TYPE(ipaddr, iptype)
  918. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
  919. #define ip_2_ip4(ipaddr) (ipaddr)
  920. #define IP_ADDR4(ipaddr,a,b,c,d) IP4_ADDR(ipaddr,a,b,c,d)
  921. #define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
  922. #define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src)
  923. #define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val)
  924. #define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr))
  925. #define ip_addr_set(dest, src) ip4_addr_set(dest, src)
  926. #define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src)
  927. #define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
  928. #define ip_addr_set_zero_ip4(ipaddr) ip4_addr_set_zero(ipaddr)
  929. #define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
  930. #define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr)
  931. #define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src)
  932. #define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask)
  933. #define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask)
  934. #define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
  935. #define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
  936. #define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
  937. #define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr)
  938. #define ip_addr_islinklocal(ipaddr) ip4_addr_islinklocal(ipaddr)
  939. #define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif)
  940. #define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr)
  941. #define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr)
  942. #define ip_addr_debug_print_val(debug, ipaddr) ip4_addr_debug_print_val(debug, ipaddr)
  943. #define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr)
  944. #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen)
  945. #define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
  946. #define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX
  947. #define IP46_ADDR_ANY(type) (IP4_ADDR_ANY)
  948. #else
  949. typedef ip6_addr_t ip_addr_t;
  950. #define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } }
  951. #define IPADDR6_INIT_HOST(a, b, c, d) { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } }
  952. #define IP_IS_V4_VAL(ipaddr) 0
  953. #define IP_IS_V6_VAL(ipaddr) 1
  954. #define IP_IS_V4(ipaddr) 0
  955. #define IP_IS_V6(ipaddr) 1
  956. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  957. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  958. #define IP_SET_TYPE(ipaddr, iptype)
  959. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
  960. #define ip_2_ip6(ipaddr) (ipaddr)
  961. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) IP6_ADDR(ipaddr,i0,i1,i2,i3)
  962. #define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3))
  963. #define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
  964. #define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
  965. #define ip_addr_set(dest, src) ip6_addr_set(dest, src)
  966. #define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
  967. #define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
  968. #define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr)
  969. #define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
  970. #define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
  971. #define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
  972. #define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
  973. #define ip_addr_netcmp(addr1, addr2, mask) 0
  974. #define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
  975. #define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
  976. #define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
  977. #define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
  978. #define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr)
  979. #define ip_addr_isbroadcast(addr, netif) 0
  980. #define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
  981. #define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
  982. #define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr)
  983. #define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
  984. #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
  985. #define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
  986. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  987. #define IP46_ADDR_ANY(type) (IP6_ADDR_ANY)
  988. #endif
  989. #endif
  990. #ifndef INET_ADDRSTRLEN
  991. #define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX
  992. #endif
  993. #if TLS_CONFIG_IPV6
  994. #ifndef INET6_ADDRSTRLEN
  995. #define INET6_ADDRSTRLEN IP6ADDR_STRLEN_MAX
  996. #endif
  997. #endif
  998. #if TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6
  999. /** @ingroup socket */
  1000. #define inet_ntop(af,src,dst,size) \
  1001. (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) \
  1002. : (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL))
  1003. /** @ingroup socket */
  1004. #define inet_pton(af,src,dst) \
  1005. (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) \
  1006. : (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0))
  1007. #elif TLS_CONFIG_IPV4 /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1008. #define inet_ntop(af,src,dst,size) \
  1009. (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL)
  1010. #define inet_pton(af,src,dst) \
  1011. (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
  1012. #else /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1013. #define inet_ntop(af,src,dst,size) \
  1014. (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) : NULL)
  1015. #define inet_pton(af,src,dst) \
  1016. (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) : 0)
  1017. #endif /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1018. extern void print_ipaddr(ip_addr_t *ip);
  1019. extern struct netif *wm_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src);
  1020. #endif