ws2tcpip.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the w64 mingw-runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER within this package.
  5. */
  6. #ifndef _WS2TCPIP_H
  7. #define _WS2TCPIP_H
  8. #if __GNUC__ >=3
  9. #pragma GCC system_header
  10. #endif
  11. #include <ws2ipdef.h>
  12. struct ip_msfilter {
  13. struct in_addr imsf_multiaddr;
  14. struct in_addr imsf_interface;
  15. u_long imsf_fmode;
  16. u_long imsf_numsrc;
  17. struct in_addr imsf_slist[1];
  18. };
  19. #define IP_MSFILTER_SIZE(numsrc) (sizeof(struct ip_msfilter)-sizeof(struct in_addr) + (numsrc)*sizeof(struct in_addr))
  20. #define MCAST_INCLUDE 0
  21. #define MCAST_EXCLUDE 1
  22. #define SIO_GET_INTERFACE_LIST _IOR('t',127,u_long)
  23. #define SIO_GET_INTERFACE_LIST_EX _IOR('t',126,u_long)
  24. #define SIO_SET_MULTICAST_FILTER _IOW('t',125,u_long)
  25. #define SIO_GET_MULTICAST_FILTER _IOW('t',124 | IOC_IN,u_long)
  26. #define IP_OPTIONS 1
  27. #define IP_HDRINCL 2
  28. #define IP_TOS 3
  29. #define IP_TTL 4
  30. #define IP_MULTICAST_IF 9
  31. #define IP_MULTICAST_TTL 10
  32. #define IP_MULTICAST_LOOP 11
  33. #define IP_ADD_MEMBERSHIP 12
  34. #define IP_DROP_MEMBERSHIP 13
  35. #define IP_DONTFRAGMENT 14
  36. #define IP_ADD_SOURCE_MEMBERSHIP 15
  37. #define IP_DROP_SOURCE_MEMBERSHIP 16
  38. #define IP_BLOCK_SOURCE 17
  39. #define IP_UNBLOCK_SOURCE 18
  40. #define IP_PKTINFO 19
  41. #define IP_RECEIVE_BROADCAST 22
  42. #define IPV6_HDRINCL 2
  43. #define IPV6_UNICAST_HOPS 4
  44. #define IPV6_MULTICAST_IF 9
  45. #define IPV6_MULTICAST_HOPS 10
  46. #define IPV6_MULTICAST_LOOP 11
  47. #define IPV6_ADD_MEMBERSHIP 12
  48. #define IPV6_DROP_MEMBERSHIP 13
  49. #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
  50. #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
  51. #define IPV6_PKTINFO 19
  52. #define IPV6_HOPLIMIT 21
  53. #define IPV6_PROTECTION_LEVEL 23
  54. #define PROTECTION_LEVEL_UNRESTRICTED 10
  55. #define PROTECTION_LEVEL_DEFAULT 20
  56. #define PROTECTION_LEVEL_RESTRICTED 30
  57. #define UDP_NOCHECKSUM 1
  58. #define UDP_CHECKSUM_COVERAGE 20
  59. #define TCP_EXPEDITED_1122 0x0002
  60. #ifndef s6_addr
  61. struct in6_addr {
  62. __MINGW_EXTENSION union {
  63. u_char Byte[16];
  64. u_short Word[8];
  65. } u;
  66. };
  67. #define in_addr6 in6_addr
  68. #define _S6_un u
  69. #define _S6_u8 Byte
  70. #define s6_addr _S6_un._S6_u8
  71. #define s6_bytes u.Byte
  72. #define s6_words u.Word
  73. #endif
  74. typedef struct ipv6_mreq {
  75. struct in6_addr ipv6mr_multiaddr;
  76. unsigned int ipv6mr_interface;
  77. } IPV6_MREQ;
  78. struct sockaddr_in6_old {
  79. short sin6_family;
  80. u_short sin6_port;
  81. u_long sin6_flowinfo;
  82. struct in6_addr sin6_addr;
  83. };
  84. struct sockaddr_in6 {
  85. short sin6_family;
  86. u_short sin6_port;
  87. u_long sin6_flowinfo;
  88. struct in6_addr sin6_addr;
  89. u_long sin6_scope_id;
  90. };
  91. typedef struct in6_addr IN6_ADDR;
  92. typedef struct in6_addr *PIN6_ADDR;
  93. typedef struct in6_addr *LPIN6_ADDR;
  94. typedef struct sockaddr_in6 SOCKADDR_IN6;
  95. typedef struct sockaddr_in6 *PSOCKADDR_IN6;
  96. typedef struct sockaddr_in6 *LPSOCKADDR_IN6;
  97. #define SS_PORT(ssp) (((struct sockaddr_in*)(ssp))->sin_port)
  98. #define IN6ADDR_ANY_INIT { 0 }
  99. #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
  100. #ifdef __cplusplus
  101. extern "C" {
  102. #endif
  103. extern const struct in6_addr in6addr_any;
  104. extern const struct in6_addr in6addr_loopback;
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #define WS2TCPIP_INLINE __CRT_INLINE
  109. int IN6_ADDR_EQUAL(const struct in6_addr *,const struct in6_addr *);
  110. int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *);
  111. int IN6_IS_ADDR_LOOPBACK(const struct in6_addr *);
  112. int IN6_IS_ADDR_MULTICAST(const struct in6_addr *);
  113. int IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *);
  114. int IN6_IS_ADDR_SITELOCAL(const struct in6_addr *);
  115. int IN6_IS_ADDR_V4MAPPED(const struct in6_addr *);
  116. int IN6_IS_ADDR_V4COMPAT(const struct in6_addr *);
  117. int IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *);
  118. int IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *);
  119. int IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *);
  120. int IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *);
  121. int IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *);
  122. int IN6ADDR_ISANY(const struct sockaddr_in6 *);
  123. int IN6ADDR_ISLOOPBACK(const struct sockaddr_in6 *);
  124. void IN6_SET_ADDR_UNSPECIFIED(struct in6_addr *);
  125. void IN6_SET_ADDR_LOOPBACK(struct in6_addr *);
  126. void IN6ADDR_SETANY(struct sockaddr_in6 *);
  127. void IN6ADDR_SETLOOPBACK(struct sockaddr_in6 *);
  128. #ifndef __CRT__NO_INLINE
  129. WS2TCPIP_INLINE int IN6_ADDR_EQUAL(const struct in6_addr *a,const struct in6_addr *b) { return (memcmp(a,b,sizeof(struct in6_addr))==0); }
  130. WS2TCPIP_INLINE int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *a) { return ((a->s6_words[0]==0) && (a->s6_words[1]==0) && (a->s6_words[2]==0) && (a->s6_words[3]==0) && (a->s6_words[4]==0) && (a->s6_words[5]==0) && (a->s6_words[6]==0) && (a->s6_words[7]==0)); }
  131. WS2TCPIP_INLINE int IN6_IS_ADDR_LOOPBACK(const struct in6_addr *a) { return ((a->s6_words[0]==0) && (a->s6_words[1]==0) && (a->s6_words[2]==0) && (a->s6_words[3]==0) && (a->s6_words[4]==0) && (a->s6_words[5]==0) && (a->s6_words[6]==0) && (a->s6_words[7]==0x0100)); }
  132. WS2TCPIP_INLINE int IN6_IS_ADDR_MULTICAST(const struct in6_addr *a) { return (a->s6_bytes[0]==0xff); }
  133. WS2TCPIP_INLINE int IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a) { return ((a->s6_bytes[0]==0xfe) && ((a->s6_bytes[1] & 0xc0)==0x80)); }
  134. WS2TCPIP_INLINE int IN6_IS_ADDR_SITELOCAL(const struct in6_addr *a) { return ((a->s6_bytes[0]==0xfe) && ((a->s6_bytes[1] & 0xc0)==0xc0)); }
  135. WS2TCPIP_INLINE int IN6_IS_ADDR_V4MAPPED(const struct in6_addr *a) { return ((a->s6_words[0]==0) && (a->s6_words[1]==0) && (a->s6_words[2]==0) && (a->s6_words[3]==0) && (a->s6_words[4]==0) && (a->s6_words[5]==0xffff)); }
  136. WS2TCPIP_INLINE int IN6_IS_ADDR_V4COMPAT(const struct in6_addr *a) { return ((a->s6_words[0]==0) && (a->s6_words[1]==0) && (a->s6_words[2]==0) && (a->s6_words[3]==0) && (a->s6_words[4]==0) && (a->s6_words[5]==0) && !((a->s6_words[6]==0) && (a->s6_addr[14]==0) && ((a->s6_addr[15]==0) || (a->s6_addr[15]==1)))); }
  137. WS2TCPIP_INLINE int IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *a) { return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_bytes[1] & 0xf)==1); }
  138. WS2TCPIP_INLINE int IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *a) { return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_bytes[1] & 0xf)==2); }
  139. WS2TCPIP_INLINE int IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *a) { return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_bytes[1] & 0xf)==5); }
  140. WS2TCPIP_INLINE int IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *a) { return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_bytes[1] & 0xf)==8); }
  141. WS2TCPIP_INLINE int IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *a) { return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_bytes[1] & 0xf)==0xe); }
  142. WS2TCPIP_INLINE int IN6ADDR_ISANY(const struct sockaddr_in6 *a) { return ((a->sin6_family==AF_INET6) && IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr)); }
  143. WS2TCPIP_INLINE int IN6ADDR_ISLOOPBACK(const struct sockaddr_in6 *a) { return ((a->sin6_family==AF_INET6) && IN6_IS_ADDR_LOOPBACK(&a->sin6_addr)); }
  144. WS2TCPIP_INLINE void IN6_SET_ADDR_UNSPECIFIED(struct in6_addr *a) { memset(a->s6_bytes,0,sizeof(struct in6_addr)); }
  145. WS2TCPIP_INLINE void IN6_SET_ADDR_LOOPBACK(struct in6_addr *a) {
  146. memset(a->s6_bytes,0,sizeof(struct in6_addr));
  147. a->s6_bytes[15] = 1;
  148. }
  149. WS2TCPIP_INLINE void IN6ADDR_SETANY(struct sockaddr_in6 *a) {
  150. a->sin6_family = AF_INET6;
  151. a->sin6_port = 0;
  152. a->sin6_flowinfo = 0;
  153. IN6_SET_ADDR_UNSPECIFIED(&a->sin6_addr);
  154. a->sin6_scope_id = 0;
  155. }
  156. WS2TCPIP_INLINE void IN6ADDR_SETLOOPBACK(struct sockaddr_in6 *a) {
  157. a->sin6_family = AF_INET6;
  158. a->sin6_port = 0;
  159. a->sin6_flowinfo = 0;
  160. IN6_SET_ADDR_LOOPBACK(&a->sin6_addr);
  161. a->sin6_scope_id = 0;
  162. }
  163. #endif /* !__CRT__NO_INLINE */
  164. typedef union sockaddr_gen {
  165. struct sockaddr Address;
  166. struct sockaddr_in AddressIn;
  167. struct sockaddr_in6_old AddressIn6;
  168. } sockaddr_gen;
  169. typedef struct _INTERFACE_INFO {
  170. u_long iiFlags;
  171. sockaddr_gen iiAddress;
  172. sockaddr_gen iiBroadcastAddress;
  173. sockaddr_gen iiNetmask;
  174. } INTERFACE_INFO,*LPINTERFACE_INFO;
  175. typedef struct _INTERFACE_INFO_EX {
  176. u_long iiFlags;
  177. SOCKET_ADDRESS iiAddress;
  178. SOCKET_ADDRESS iiBroadcastAddress;
  179. SOCKET_ADDRESS iiNetmask;
  180. } INTERFACE_INFO_EX,*LPINTERFACE_INFO_EX;
  181. #define IFF_UP 0x00000001
  182. #define IFF_BROADCAST 0x00000002
  183. #define IFF_LOOPBACK 0x00000004
  184. #define IFF_POINTTOPOINT 0x00000008
  185. #define IFF_MULTICAST 0x00000010
  186. typedef struct in_pktinfo {
  187. IN_ADDR ipi_addr;
  188. UINT ipi_ifindex;
  189. } IN_PKTINFO;
  190. C_ASSERT(sizeof(IN_PKTINFO)==8);
  191. typedef struct in6_pktinfo {
  192. IN6_ADDR ipi6_addr;
  193. UINT ipi6_ifindex;
  194. } IN6_PKTINFO;
  195. C_ASSERT(sizeof(IN6_PKTINFO)==20);
  196. #define EAI_AGAIN WSATRY_AGAIN
  197. #define EAI_BADFLAGS WSAEINVAL
  198. #define EAI_FAIL WSANO_RECOVERY
  199. #define EAI_FAMILY WSAEAFNOSUPPORT
  200. #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
  201. #define EAI_NONAME WSAHOST_NOT_FOUND
  202. #define EAI_SERVICE WSATYPE_NOT_FOUND
  203. #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
  204. #define EAI_NODATA EAI_NONAME
  205. typedef struct addrinfo {
  206. int ai_flags;
  207. int ai_family;
  208. int ai_socktype;
  209. int ai_protocol;
  210. size_t ai_addrlen;
  211. char *ai_canonname;
  212. struct sockaddr *ai_addr;
  213. struct addrinfo *ai_next;
  214. } ADDRINFOA,*PADDRINFOA;
  215. typedef struct addrinfoW {
  216. int ai_flags;
  217. int ai_family;
  218. int ai_socktype;
  219. int ai_protocol;
  220. size_t ai_addrlen;
  221. PWSTR ai_canonname;
  222. struct sockaddr *ai_addr;
  223. struct addrinfoW *ai_next;
  224. } ADDRINFOW,*PADDRINFOW;
  225. #ifdef UNICODE
  226. typedef ADDRINFOW ADDRINFOT,*PADDRINFOT;
  227. #else
  228. typedef ADDRINFOA ADDRINFOT,*PADDRINFOT;
  229. #endif
  230. typedef ADDRINFOA ADDRINFO,*LPADDRINFO;
  231. #define AI_PASSIVE 0x1
  232. #define AI_CANONNAME 0x2
  233. #define AI_NUMERICHOST 0x4
  234. #ifdef __cplusplus
  235. extern "C" {
  236. #endif
  237. #ifdef UNICODE
  238. #define GetAddrInfo GetAddrInfoW
  239. #else
  240. #define GetAddrInfo GetAddrInfoA
  241. #endif
  242. WINSOCK_API_LINKAGE int WSAAPI getaddrinfo(const char *nodename,const char *servname,const struct addrinfo *hints,struct addrinfo **res);
  243. WINSOCK_API_LINKAGE int WSAAPI GetAddrInfoW(PCWSTR pNodeName,PCWSTR pServiceName,const ADDRINFOW *pHints,PADDRINFOW *ppResult);
  244. #define GetAddrInfoA getaddrinfo
  245. #if INCL_WINSOCK_API_TYPEDEFS
  246. typedef int (WSAAPI *LPFN_GETADDRINFO)(const char *nodename,const char *servname,const struct addrinfo *hints,struct addrinfo **res);
  247. typedef int (WSAAPI *LPFN_GETADDRINFOW)(PCWSTR pNodeName,PCWSTR pServiceName,const ADDRINFOW *pHints,PADDRINFOW *ppResult);
  248. #define LPFN_GETADDRINFOA LPFN_GETADDRINFO
  249. #ifdef UNICODE
  250. #define LPFN_GETADDRINFOT LPFN_GETADDRINFOW
  251. #else
  252. #define LPFN_GETADDRINFOT LPFN_GETADDRINFOA
  253. #endif
  254. #endif
  255. #ifdef UNICODE
  256. #define FreeAddrInfo FreeAddrInfoW
  257. #else
  258. #define FreeAddrInfo FreeAddrInfoA
  259. #endif
  260. WINSOCK_API_LINKAGE void WSAAPI freeaddrinfo(LPADDRINFO pAddrInfo);
  261. WINSOCK_API_LINKAGE void WSAAPI FreeAddrInfoW(PADDRINFOW pAddrInfo);
  262. #define FreeAddrInfoA freeaddrinfo
  263. #if INCL_WINSOCK_API_TYPEDEFS
  264. typedef void (WSAAPI *LPFN_FREEADDRINFO)(struct addrinfo *ai);
  265. typedef void (WSAAPI *LPFN_FREEADDRINFOW)(PADDRINFOW pAddrInfo);
  266. #define LPFN_FREEADDRINFOA LPFN_FREEADDRINFO
  267. #ifdef UNICODE
  268. #define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOW
  269. #else
  270. #define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOA
  271. #endif
  272. #endif
  273. #pragma push_macro("socklen_t")
  274. #undef socklen_t
  275. typedef int socklen_t;
  276. #ifdef UNICODE
  277. #define GetNameInfo GetNameInfoW
  278. #else
  279. #define GetNameInfo GetNameInfoA
  280. #endif
  281. WINSOCK_API_LINKAGE int WSAAPI getnameinfo(const struct sockaddr *sa,socklen_t salen,char *host,DWORD hostlen,char *serv,DWORD servlen,int flags);
  282. WINSOCK_API_LINKAGE INT WSAAPI GetNameInfoW(const SOCKADDR *pSockaddr,socklen_t SockaddrLength,PWCHAR pNodeBuffer,DWORD NodeBufferSize,PWCHAR pServiceBuffer,DWORD ServiceBufferSize,INT Flags);
  283. #define GetNameInfoA getnameinfo
  284. #if INCL_WINSOCK_API_TYPEDEFS
  285. typedef int (WSAAPI *LPFN_GETNAMEINFO)(const struct sockaddr *sa,socklen_t salen,char *host,DWORD hostlen,char *serv,DWORD servlen,int flags);
  286. typedef INT (WSAAPI *LPFN_GETNAMEINFOW)(const SOCKADDR *pSockaddr,socklen_t SockaddrLength,PWCHAR pNodeBuffer,DWORD NodeBufferSize,PWCHAR pServiceBuffer,DWORD ServiceBufferSize,INT Flags);
  287. #define LPFN_GETNAMEINFOA LPFN_GETNAMEINFO
  288. #ifdef UNICODE
  289. #define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOW
  290. #else
  291. #define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOA
  292. #endif
  293. #endif
  294. #pragma pop_macro("socklen_t")
  295. #ifdef UNICODE
  296. #define gai_strerror gai_strerrorW
  297. #else
  298. #define gai_strerror gai_strerrorA
  299. #endif
  300. #define GAI_STRERROR_BUFFER_SIZE 1024
  301. char *gai_strerrorA (int);
  302. WCHAR *gai_strerrorW(int);
  303. #define NI_MAXHOST 1025
  304. #define NI_MAXSERV 32
  305. #define INET_ADDRSTRLEN 22
  306. #define INET6_ADDRSTRLEN 65
  307. #define NI_NOFQDN 0x01
  308. #define NI_NUMERICHOST 0x02
  309. #define NI_NAMEREQD 0x04
  310. #define NI_NUMERICSERV 0x08
  311. #define NI_DGRAM 0x10
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif