wm_sockets2.0.3.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. #ifndef PPP_SUPPORT
  409. #define write(s,dataptr,len) send(s,dataptr,len,0)
  410. #endif
  411. /** @ingroup socket */
  412. #define close(s) closesocket(s)
  413. /** @ingroup socket */
  414. #define ioctl(s,cmd,argp) ioctlsocket(s,cmd,argp)
  415. u32_t ipaddr_addr(const char *cp);
  416. #ifdef htonl
  417. #undef htonl
  418. #endif /* htonl */
  419. #ifdef ntohl
  420. #undef ntohl
  421. #endif /* ntohl */
  422. #ifdef htons
  423. #undef htons
  424. #endif /* htons */
  425. #ifdef ntohs
  426. #undef ntohs
  427. #endif /* ntohs */
  428. #define htons(n) (((n & 0xff) << 8) | ((n & 0xff00) >> 8))
  429. #define htonl(n) (((n & 0xff) << 24) |\
  430. ((n & 0xff00) << 8) |\
  431. ((n & 0xff0000UL) >> 8) |\
  432. ((n & 0xff000000UL) >> 24))
  433. #define ntohs(n) htons(n)
  434. #define ntohl(n) htonl(n)
  435. /** Create u32_t value from bytes */
  436. #define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \
  437. ((u32_t)((b) & 0xff) << 16) | \
  438. ((u32_t)((c) & 0xff) << 8) | \
  439. (u32_t)((d) & 0xff))
  440. #define PP_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
  441. (((x) & 0x0000ff00UL) << 8) | \
  442. (((x) & 0x00ff0000UL) >> 8) | \
  443. (((x) & 0xff000000UL) >> 24))
  444. #if TLS_CONFIG_IPV4
  445. /** This is the aligned version of ip4_addr_t,
  446. used as local variable, on the stack, etc. */
  447. struct ip4_addr {
  448. u32_t addr;
  449. };
  450. /** ip4_addr_t uses a struct for convenience only, so that the same defines can
  451. * operate both on ip4_addr_t as well as on ip4_addr_p_t. */
  452. typedef struct ip4_addr ip4_addr_t;
  453. /** Set an IP address given by the four byte-parts */
  454. #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
  455. /** MEMCPY-like copying of IP addresses where addresses are known to be
  456. * 16-bit-aligned if the port is correctly configured (so a port could define
  457. * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */
  458. #ifndef IPADDR2_COPY
  459. #define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t))
  460. #endif
  461. /** Copy IP address - faster than ip4_addr_set: no NULL check */
  462. #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
  463. /** Safely copy one IP address to another (src may be NULL) */
  464. #define ip4_addr_set(dest, src) ((dest)->addr = \
  465. ((src) == NULL ? 0 : \
  466. (src)->addr))
  467. /** Set complete address to zero */
  468. #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
  469. /** Set address to IPADDR_ANY (no need for lwip_htonl()) */
  470. #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
  471. /** Set address to loopback address */
  472. #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
  473. /** Check if an address is in the loopback region */
  474. #define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
  475. /** Safely copy one IP address to another and change byte order
  476. * from host- to network-order. */
  477. #define ip4_addr_set_hton(dest, src) ((dest)->addr = \
  478. ((src) == NULL ? 0:\
  479. lwip_htonl((src)->addr)))
  480. /** IPv4 only: set the IP address given as an u32_t */
  481. #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
  482. /** IPv4 only: get the IP address as an u32_t */
  483. #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
  484. /** Get the network address by combining host address with netmask */
  485. #define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
  486. /**
  487. * @brief Determine if two address are on the same network.
  488. *
  489. * @arg addr1 IP address 1
  490. * @arg addr2 IP address 2
  491. * @arg mask network identifier mask
  492. * @return !0 if the network identifiers of both address match
  493. */
  494. #define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
  495. (mask)->addr) == \
  496. ((addr2)->addr & \
  497. (mask)->addr))
  498. #define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
  499. #define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
  500. #define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
  501. #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
  502. u8_t ip4_addr_netmask_valid(u32_t netmask);
  503. #define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
  504. #define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
  505. #define ip4_addr_debug_print_parts(debug, a, b, c, d) \
  506. LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
  507. #define ip4_addr_debug_print(debug, ipaddr) \
  508. ip4_addr_debug_print_parts(debug, \
  509. (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
  510. (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
  511. (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
  512. (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
  513. #define ip4_addr_debug_print_val(debug, ipaddr) \
  514. ip4_addr_debug_print_parts(debug, \
  515. ip4_addr1_16(&(ipaddr)), \
  516. ip4_addr2_16(&(ipaddr)), \
  517. ip4_addr3_16(&(ipaddr)), \
  518. ip4_addr4_16(&(ipaddr)))
  519. /** Get one byte from the 4-byte address */
  520. #define ip4_addr1(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[0])
  521. #define ip4_addr2(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[1])
  522. #define ip4_addr3(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[2])
  523. #define ip4_addr4(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[3])
  524. /** These are cast to u16_t, with the intent that they are often arguments
  525. * to printf using the U16_F format from cc.h. */
  526. #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
  527. #define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
  528. #define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
  529. #define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
  530. #define IP4ADDR_STRLEN_MAX 16
  531. /** For backwards compatibility */
  532. #define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
  533. u32_t ipaddr_addr(const char *cp);
  534. int ip4addr_aton(const char *cp, ip4_addr_t *addr);
  535. /** returns ptr to static buffer; not reentrant! */
  536. char *ip4addr_ntoa(const ip4_addr_t *addr);
  537. char *ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
  538. /** directly map this to the lwip internal functions */
  539. #define inet_addr(cp) ipaddr_addr(cp)
  540. #define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
  541. #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr))
  542. #endif
  543. #if TLS_CONFIG_IPV6
  544. /** This is the aligned version of ip6_addr_t,
  545. used as local variable, on the stack, etc. */
  546. struct ip6_addr {
  547. u32_t addr[4];
  548. };
  549. /** IPv6 address */
  550. typedef struct ip6_addr ip6_addr_t;
  551. /** Set an IPv6 partial address given by byte-parts */
  552. #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \
  553. (ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
  554. /** Set a full IPv6 address by passing the 4 u32_t indices in network byte order
  555. (use PP_HTONL() for constants) */
  556. #define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
  557. (ip6addr)->addr[0] = idx0; \
  558. (ip6addr)->addr[1] = idx1; \
  559. (ip6addr)->addr[2] = idx2; \
  560. (ip6addr)->addr[3] = idx3; } while(0)
  561. /** Access address in 16-bit block */
  562. #define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
  563. /** Access address in 16-bit block */
  564. #define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
  565. /** Access address in 16-bit block */
  566. #define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
  567. /** Access address in 16-bit block */
  568. #define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
  569. /** Access address in 16-bit block */
  570. #define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
  571. /** Access address in 16-bit block */
  572. #define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
  573. /** Access address in 16-bit block */
  574. #define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
  575. /** Access address in 16-bit block */
  576. #define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
  577. /** Copy IPv6 address - faster than ip6_addr_set: no NULL check */
  578. #define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
  579. (dest).addr[1] = (src).addr[1]; \
  580. (dest).addr[2] = (src).addr[2]; \
  581. (dest).addr[3] = (src).addr[3];}while(0)
  582. /** Safely copy one IPv6 address to another (src may be NULL) */
  583. #define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
  584. (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
  585. (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
  586. (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3];}while(0)
  587. /** Set complete address to zero */
  588. #define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
  589. (ip6addr)->addr[1] = 0; \
  590. (ip6addr)->addr[2] = 0; \
  591. (ip6addr)->addr[3] = 0;}while(0)
  592. /** Set address to ipv6 'any' (no need for lwip_htonl()) */
  593. #define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
  594. /** Set address to ipv6 loopback address */
  595. #define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \
  596. (ip6addr)->addr[1] = 0; \
  597. (ip6addr)->addr[2] = 0; \
  598. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  599. /** Safely copy one IPv6 address to another and change byte order
  600. * from host- to network-order. */
  601. #define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
  602. (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
  603. (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
  604. (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]);}while(0)
  605. /**
  606. * @brief Determine if two IPv6 address are on the same network.
  607. *
  608. * @arg addr1 IPv6 address 1
  609. * @arg addr2 IPv6 address 2
  610. * @return !0 if the network identifiers of both address match
  611. */
  612. #define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  613. ((addr1)->addr[1] == (addr2)->addr[1]))
  614. #define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  615. ((addr1)->addr[1] == (addr2)->addr[1]) && \
  616. ((addr1)->addr[2] == (addr2)->addr[2]) && \
  617. ((addr1)->addr[3] == (addr2)->addr[3]))
  618. #define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
  619. #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
  620. ((ip6addr).addr[1] == 0) && \
  621. ((ip6addr).addr[2] == 0) && \
  622. ((ip6addr).addr[3] == 0))
  623. #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
  624. #define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
  625. ((ip6addr)->addr[1] == 0UL) && \
  626. ((ip6addr)->addr[2] == 0UL) && \
  627. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  628. #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
  629. #define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
  630. #define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
  631. #define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
  632. #define ip6_addr_isipv4mappedipv6(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
  633. #define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
  634. #define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
  635. #define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
  636. #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
  637. #define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
  638. #define IP6_MULTICAST_SCOPE_RESERVED 0x0
  639. #define IP6_MULTICAST_SCOPE_RESERVED0 0x0
  640. #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
  641. #define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
  642. #define IP6_MULTICAST_SCOPE_RESERVED3 0x3
  643. #define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
  644. #define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
  645. #define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
  646. #define IP6_MULTICAST_SCOPE_GLOBAL 0xe
  647. #define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
  648. #define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
  649. #define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
  650. #define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
  651. #define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
  652. #define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
  653. #define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
  654. /** @todo define get/set for well-know multicast addresses, e.g. ff02::1 */
  655. #define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
  656. ((ip6addr)->addr[1] == 0UL) && \
  657. ((ip6addr)->addr[2] == 0UL) && \
  658. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  659. #define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  660. ((ip6addr)->addr[1] == 0UL) && \
  661. ((ip6addr)->addr[2] == 0UL) && \
  662. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  663. #define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  664. (ip6addr)->addr[1] = 0; \
  665. (ip6addr)->addr[2] = 0; \
  666. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  667. #define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  668. ((ip6addr)->addr[1] == 0UL) && \
  669. ((ip6addr)->addr[2] == 0UL) && \
  670. ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
  671. #define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  672. (ip6addr)->addr[1] = 0; \
  673. (ip6addr)->addr[2] = 0; \
  674. (ip6addr)->addr[3] = PP_HTONL(0x00000002UL);}while(0)
  675. #define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  676. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  677. (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) )
  678. #define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  679. (ip6addr)->addr[1] = 0; \
  680. (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
  681. (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id));}while(0)
  682. #define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  683. ((ip6addr)->addr[1] == 0) && \
  684. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  685. ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
  686. /* IPv6 address states. */
  687. #define IP6_ADDR_INVALID 0x00
  688. #define IP6_ADDR_TENTATIVE 0x08
  689. #define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */
  690. #define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */
  691. #define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */
  692. #define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */
  693. #define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */
  694. #define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */
  695. #define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */
  696. #define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */
  697. #define IP6_ADDR_PREFERRED 0x30
  698. #define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */
  699. #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
  700. #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
  701. #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
  702. #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
  703. #define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
  704. #define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
  705. #define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
  706. LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
  707. a, b, c, d, e, f, g, h))
  708. #define ip6_addr_debug_print(debug, ipaddr) \
  709. ip6_addr_debug_print_parts(debug, \
  710. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
  711. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
  712. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
  713. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
  714. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
  715. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
  716. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
  717. (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
  718. #define ip6_addr_debug_print_val(debug, ipaddr) \
  719. ip6_addr_debug_print_parts(debug, \
  720. IP6_ADDR_BLOCK1(&(ipaddr)), \
  721. IP6_ADDR_BLOCK2(&(ipaddr)), \
  722. IP6_ADDR_BLOCK3(&(ipaddr)), \
  723. IP6_ADDR_BLOCK4(&(ipaddr)), \
  724. IP6_ADDR_BLOCK5(&(ipaddr)), \
  725. IP6_ADDR_BLOCK6(&(ipaddr)), \
  726. IP6_ADDR_BLOCK7(&(ipaddr)), \
  727. IP6_ADDR_BLOCK8(&(ipaddr)))
  728. #define IP6ADDR_STRLEN_MAX 46
  729. int ip6addr_aton(const char *cp, ip6_addr_t *addr);
  730. /** returns ptr to static buffer; not reentrant! */
  731. char *ip6addr_ntoa(const ip6_addr_t *addr);
  732. char *ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen);
  733. #endif
  734. /** @ingroup ipaddr
  735. * IP address types for use in ip_addr_t.type member.
  736. * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type().
  737. */
  738. enum lwip_ip_addr_type {
  739. /** IPv4 */
  740. IPADDR_TYPE_V4 = 0U,
  741. /** IPv6 */
  742. IPADDR_TYPE_V6 = 6U,
  743. /** IPv4+IPv6 ("dual-stack") */
  744. IPADDR_TYPE_ANY = 46U
  745. };
  746. #if TLS_CONFIG_IPV4&&TLS_CONFIG_IPV6
  747. /**
  748. * @ingroup ipaddr
  749. * A union struct for both IP version's addresses.
  750. * ATTENTION: watch out for its size when adding IPv6 address scope!
  751. */
  752. typedef struct ip_addr {
  753. union {
  754. ip6_addr_t ip6;
  755. ip4_addr_t ip4;
  756. } u_addr;
  757. /** @ref lwip_ip_addr_type */
  758. u8_t type;
  759. } ip_addr_t;
  760. extern const ip_addr_t ip_addr_any_type;
  761. /** @ingroup ip4addr */
  762. #define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_V4 }
  763. /** @ingroup ip4addr */
  764. #define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d)))
  765. /** @ingroup ip6addr */
  766. #define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
  767. /** @ingroup ip6addr */
  768. #define IPADDR6_INIT_HOST(a, b, c, d) { { { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } } }, IPADDR_TYPE_V6 }
  769. /** @ingroup ipaddr */
  770. #define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
  771. /** @ingroup ipaddr */
  772. #define IPADDR_ANY_TYPE_INIT { { { { 0ul, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_ANY }
  773. /** @ingroup ip4addr */
  774. #define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
  775. /** @ingroup ip6addr */
  776. #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
  777. /** @ingroup ip4addr */
  778. #define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
  779. /** @ingroup ip6addr */
  780. #define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
  781. #define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
  782. #define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
  783. #define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
  784. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr))
  785. #define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr))
  786. /** @ingroup ip6addr
  787. * Convert generic ip address to specific protocol version
  788. */
  789. #define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
  790. /** @ingroup ip4addr
  791. * Convert generic ip address to specific protocol version
  792. */
  793. #define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
  794. /** @ingroup ip4addr */
  795. #define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \
  796. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0)
  797. /** @ingroup ip6addr */
  798. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \
  799. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0)
  800. /** @ingroup ip6addr */
  801. #define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3))
  802. /** @ingroup ipaddr */
  803. #define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
  804. ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
  805. ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
  806. /** @ingroup ip6addr */
  807. #define ip_addr_copy_from_ip6(dest, src) do{ \
  808. ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0)
  809. /** @ingroup ip4addr */
  810. #define ip_addr_copy_from_ip4(dest, src) do{ \
  811. ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }while(0)
  812. /** @ingroup ip4addr */
  813. #define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
  814. IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  815. /** @ingroup ip4addr */
  816. #define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \
  817. ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0)
  818. /** @ingroup ipaddr */
  819. #define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \
  820. ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \
  821. ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }}while(0)
  822. /** @ingroup ipaddr */
  823. #define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src)
  824. /** @ingroup ipaddr */
  825. #define ip_addr_set_zero(ipaddr) do{ \
  826. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
  827. /** @ingroup ip5addr */
  828. #define ip_addr_set_zero_ip4(ipaddr) do{ \
  829. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }while(0)
  830. /** @ingroup ip6addr */
  831. #define ip_addr_set_zero_ip6(ipaddr) do{ \
  832. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }while(0)
  833. /** @ingroup ipaddr */
  834. #define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
  835. ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  836. ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  837. /** @ingroup ipaddr */
  838. #define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
  839. ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  840. ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  841. /** @ingroup ipaddr */
  842. #define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \
  843. ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
  844. ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
  845. /** @ingroup ipaddr */
  846. #define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \
  847. ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \
  848. 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)
  849. /** @ingroup ipaddr */
  850. #define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
  851. 0 : \
  852. ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
  853. /** @ingroup ipaddr */
  854. #define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \
  855. ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
  856. ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
  857. /** @ingroup ipaddr */
  858. #define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  859. ip6_addr_isany(ip_2_ip6(ipaddr)) : \
  860. ip4_addr_isany(ip_2_ip4(ipaddr)))
  861. /** @ingroup ipaddr */
  862. #define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
  863. ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
  864. ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
  865. /** @ingroup ipaddr */
  866. #define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
  867. 0 : \
  868. ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
  869. /** @ingroup ipaddr */
  870. #define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  871. ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
  872. ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
  873. /** @ingroup ipaddr */
  874. #define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  875. ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
  876. ip4_addr_isloopback(ip_2_ip4(ipaddr)))
  877. /** @ingroup ipaddr */
  878. #define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  879. ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \
  880. ip4_addr_islinklocal(ip_2_ip4(ipaddr)))
  881. #define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \
  882. ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \
  883. ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0)
  884. #define ip_addr_debug_print_val(debug, ipaddr) do { if(IP_IS_V6_VAL(ipaddr)) { \
  885. ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); } else { \
  886. ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); }}while(0)
  887. /** @ingroup ipaddr */
  888. #define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
  889. ((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
  890. /** @ingroup ipaddr */
  891. #define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
  892. ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen)))
  893. int ipaddr_aton(const char *cp, ip_addr_t *addr);
  894. /** @ingroup ipaddr */
  895. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  896. /** @ingroup ipaddr */
  897. #define ip4_2_ipv4_mapped_ipv6(ip6addr, ip4addr) do { \
  898. (ip6addr)->addr[3] = (ip4addr)->addr; \
  899. (ip6addr)->addr[2] = PP_HTONL(0x0000FFFFUL); \
  900. (ip6addr)->addr[1] = 0; \
  901. (ip6addr)->addr[0] = 0; } while(0);
  902. /** @ingroup ipaddr */
  903. #define unmap_ipv4_mapped_ipv6(ip4addr, ip6addr) \
  904. (ip4addr)->addr = (ip6addr)->addr[3];
  905. #define IP46_ADDR_ANY(type) (((type) == IPADDR_TYPE_V6)? IP6_ADDR_ANY : IP4_ADDR_ANY)
  906. #else
  907. #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
  908. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1
  909. #if TLS_CONFIG_IPV4
  910. typedef ip4_addr_t ip_addr_t;
  911. #define IPADDR4_INIT(u32val) { u32val }
  912. #define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d)))
  913. #define IP_IS_V4_VAL(ipaddr) 1
  914. #define IP_IS_V6_VAL(ipaddr) 0
  915. #define IP_IS_V4(ipaddr) 1
  916. #define IP_IS_V6(ipaddr) 0
  917. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  918. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  919. #define IP_SET_TYPE(ipaddr, iptype)
  920. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
  921. #define ip_2_ip4(ipaddr) (ipaddr)
  922. #define IP_ADDR4(ipaddr,a,b,c,d) IP4_ADDR(ipaddr,a,b,c,d)
  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. #define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX
  949. #define IP46_ADDR_ANY(type) (IP4_ADDR_ANY)
  950. #else
  951. typedef ip6_addr_t ip_addr_t;
  952. #define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } }
  953. #define IPADDR6_INIT_HOST(a, b, c, d) { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } }
  954. #define IP_IS_V4_VAL(ipaddr) 0
  955. #define IP_IS_V6_VAL(ipaddr) 1
  956. #define IP_IS_V4(ipaddr) 0
  957. #define IP_IS_V6(ipaddr) 1
  958. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  959. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  960. #define IP_SET_TYPE(ipaddr, iptype)
  961. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
  962. #define ip_2_ip6(ipaddr) (ipaddr)
  963. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) IP6_ADDR(ipaddr,i0,i1,i2,i3)
  964. #define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3))
  965. #define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
  966. #define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
  967. #define ip_addr_set(dest, src) ip6_addr_set(dest, src)
  968. #define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
  969. #define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
  970. #define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr)
  971. #define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
  972. #define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
  973. #define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
  974. #define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
  975. #define ip_addr_netcmp(addr1, addr2, mask) 0
  976. #define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
  977. #define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
  978. #define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
  979. #define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
  980. #define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr)
  981. #define ip_addr_isbroadcast(addr, netif) 0
  982. #define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
  983. #define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
  984. #define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr)
  985. #define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
  986. #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
  987. #define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
  988. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  989. #define IP46_ADDR_ANY(type) (IP6_ADDR_ANY)
  990. #endif
  991. #endif
  992. #ifndef INET_ADDRSTRLEN
  993. #define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX
  994. #endif
  995. #if TLS_CONFIG_IPV6
  996. #ifndef INET6_ADDRSTRLEN
  997. #define INET6_ADDRSTRLEN IP6ADDR_STRLEN_MAX
  998. #endif
  999. #endif
  1000. #if TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6
  1001. /** @ingroup socket */
  1002. #define inet_ntop(af,src,dst,size) \
  1003. (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) \
  1004. : (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL))
  1005. /** @ingroup socket */
  1006. #define inet_pton(af,src,dst) \
  1007. (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) \
  1008. : (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0))
  1009. #elif TLS_CONFIG_IPV4 /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1010. #define inet_ntop(af,src,dst,size) \
  1011. (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL)
  1012. #define inet_pton(af,src,dst) \
  1013. (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
  1014. #else /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1015. #define inet_ntop(af,src,dst,size) \
  1016. (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) : NULL)
  1017. #define inet_pton(af,src,dst) \
  1018. (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) : 0)
  1019. #endif /* TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6 */
  1020. extern void print_ipaddr(ip_addr_t *ip);
  1021. extern struct netif *wm_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src);
  1022. #endif