/header/Microsoft SDKs/Windows/v7.0A/Include/WS2tcpip.h

https://github.com/nihon-tc/Rtest · C Header · 963 lines · 768 code · 146 blank · 49 comment · 24 complexity · 3d37201632398dd1efde0c6dcda7308f MD5 · raw file

  1. /*
  2. ** WS2TCPIP.H - WinSock2 Extension for TCP/IP protocols
  3. **
  4. ** This file contains TCP/IP specific information for use
  5. ** by WinSock2 compatible applications.
  6. **
  7. ** Copyright (c) Microsoft Corporation. All rights reserved.
  8. **
  9. ** To provide the backward compatibility, all the TCP/IP
  10. ** specific definitions that were included in the WINSOCK.H
  11. ** file are now included in WINSOCK2.H file. WS2TCPIP.H
  12. ** file includes only the definitions introduced in the
  13. ** "WinSock 2 Protocol-Specific Annex" document.
  14. **
  15. ** Rev 0.3 Nov 13, 1995
  16. ** Rev 0.4 Dec 15, 1996
  17. */
  18. #ifndef _WS2TCPIP_H_
  19. #define _WS2TCPIP_H_
  20. #if _MSC_VER > 1000
  21. #pragma once
  22. #endif
  23. #include <winsock2.h>
  24. #include <ws2ipdef.h>
  25. #include <limits.h>
  26. /* Option to use with [gs]etsockopt at the IPPROTO_UDP level */
  27. #define UDP_NOCHECKSUM 1
  28. #define UDP_CHECKSUM_COVERAGE 20 /* Set/get UDP-Lite checksum coverage */
  29. #ifdef _MSC_VER
  30. #define WS2TCPIP_INLINE __inline
  31. #else
  32. #define WS2TCPIP_INLINE extern inline /* GNU style */
  33. #endif
  34. /* Error codes from getaddrinfo() */
  35. #define EAI_AGAIN WSATRY_AGAIN
  36. #define EAI_BADFLAGS WSAEINVAL
  37. #define EAI_FAIL WSANO_RECOVERY
  38. #define EAI_FAMILY WSAEAFNOSUPPORT
  39. #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
  40. #define EAI_NOSECURENAME WSA_SECURE_HOST_NOT_FOUND
  41. //#define EAI_NODATA WSANO_DATA
  42. #define EAI_NONAME WSAHOST_NOT_FOUND
  43. #define EAI_SERVICE WSATYPE_NOT_FOUND
  44. #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
  45. #define EAI_IPSECPOLICY WSA_IPSEC_NAME_POLICY_ERROR
  46. //
  47. // DCR_FIX: EAI_NODATA remove or fix
  48. //
  49. // EAI_NODATA was removed from rfc2553bis
  50. // need to find out from the authors why and
  51. // determine the error for "no records of this type"
  52. // temporarily, we'll keep #define to avoid changing
  53. // code that could change back; use NONAME
  54. //
  55. #define EAI_NODATA EAI_NONAME
  56. // Switchable definition for GetAddrInfo()
  57. #ifdef UNICODE
  58. typedef ADDRINFOW ADDRINFOT, *PADDRINFOT;
  59. #else
  60. typedef ADDRINFOA ADDRINFOT, *PADDRINFOT;
  61. #endif
  62. // RFC standard definition for getaddrinfo()
  63. typedef ADDRINFOA ADDRINFO, FAR * LPADDRINFO;
  64. #if (_WIN32_WINNT >= 0x0600)
  65. #ifdef UNICODE
  66. typedef ADDRINFOEXW ADDRINFOEX, *PADDRINFOEX;
  67. #else
  68. typedef ADDRINFOEXA ADDRINFOEX, *PADDRINFOEX;
  69. #endif
  70. #endif
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. WINSOCK_API_LINKAGE
  75. INT
  76. WSAAPI
  77. getaddrinfo(
  78. __in_opt PCSTR pNodeName,
  79. __in_opt PCSTR pServiceName,
  80. __in_opt const ADDRINFOA * pHints,
  81. __deref_out PADDRINFOA * ppResult
  82. );
  83. #if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
  84. WINSOCK_API_LINKAGE
  85. INT
  86. WSAAPI
  87. GetAddrInfoW(
  88. __in_opt PCWSTR pNodeName,
  89. __in_opt PCWSTR pServiceName,
  90. __in_opt const ADDRINFOW * pHints,
  91. __deref_out PADDRINFOW * ppResult
  92. );
  93. #define GetAddrInfoA getaddrinfo
  94. #ifdef UNICODE
  95. #define GetAddrInfo GetAddrInfoW
  96. #else
  97. #define GetAddrInfo GetAddrInfoA
  98. #endif
  99. #endif
  100. #if INCL_WINSOCK_API_TYPEDEFS
  101. typedef
  102. INT
  103. (WSAAPI * LPFN_GETADDRINFO)(
  104. __in_opt PCSTR pNodeName,
  105. __in_opt PCSTR pServiceName,
  106. __in_opt const ADDRINFOA * pHints,
  107. __deref_out PADDRINFOA * ppResult
  108. );
  109. typedef
  110. INT
  111. (WSAAPI * LPFN_GETADDRINFOW)(
  112. __in_opt PCWSTR pNodeName,
  113. __in_opt PCWSTR pServiceName,
  114. __in_opt const ADDRINFOW * pHints,
  115. __deref_out PADDRINFOW * ppResult
  116. );
  117. #define LPFN_GETADDRINFOA LPFN_GETADDRINFO
  118. #ifdef UNICODE
  119. #define LPFN_GETADDRINFOT LPFN_GETADDRINFOW
  120. #else
  121. #define LPFN_GETADDRINFOT LPFN_GETADDRINFOA
  122. #endif
  123. #endif
  124. #if (_WIN32_WINNT >= 0x0600)
  125. typedef
  126. void
  127. (CALLBACK * LPLOOKUPSERVICE_COMPLETION_ROUTINE)(
  128. __in DWORD dwError,
  129. __in DWORD dwBytes,
  130. __in LPWSAOVERLAPPED lpOverlapped
  131. );
  132. WINSOCK_API_LINKAGE
  133. INT
  134. WSAAPI
  135. GetAddrInfoExA(
  136. __in_opt PCSTR pName,
  137. __in_opt PCSTR pServiceName,
  138. __in DWORD dwNameSpace,
  139. __in_opt LPGUID lpNspId,
  140. __in_opt const ADDRINFOEXA *hints,
  141. __deref_out PADDRINFOEXA * ppResult,
  142. __in_opt struct timeval *timeout,
  143. __in_opt LPOVERLAPPED lpOverlapped,
  144. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  145. __out_opt LPHANDLE lpNameHandle
  146. );
  147. WINSOCK_API_LINKAGE
  148. INT
  149. WSAAPI
  150. GetAddrInfoExW(
  151. __in_opt PCWSTR pName,
  152. __in_opt PCWSTR pServiceName,
  153. __in DWORD dwNameSpace,
  154. __in_opt LPGUID lpNspId,
  155. __in_opt const ADDRINFOEXW *hints,
  156. __deref_out PADDRINFOEXW * ppResult,
  157. __in_opt struct timeval *timeout,
  158. __in_opt LPOVERLAPPED lpOverlapped,
  159. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  160. __out_opt LPHANDLE lpHandle
  161. );
  162. #ifdef UNICODE
  163. #define GetAddrInfoEx GetAddrInfoExW
  164. #else
  165. #define GetAddrInfoEx GetAddrInfoExA
  166. #endif
  167. #if INCL_WINSOCK_API_TYPEDEFS
  168. typedef
  169. INT
  170. (WSAAPI *LPFN_GETADDRINFOEXA)(
  171. __in PCSTR pName,
  172. __in_opt PCSTR pServiceName,
  173. __in DWORD dwNameSpace,
  174. __in_opt LPGUID lpNspId,
  175. __in_opt const ADDRINFOEXA *hints,
  176. __deref_out PADDRINFOEXA *ppResult,
  177. __in_opt struct timeval *timeout,
  178. __in_opt LPOVERLAPPED lpOverlapped,
  179. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  180. __out_opt LPHANDLE lpNameHandle
  181. );
  182. typedef
  183. INT
  184. (WSAAPI *LPFN_GETADDRINFOEXW)(
  185. __in PCWSTR pName,
  186. __in_opt PCWSTR pServiceName,
  187. __in DWORD dwNameSpace,
  188. __in_opt LPGUID lpNspId,
  189. __in_opt const ADDRINFOEXW *hints,
  190. __deref_out PADDRINFOEXW *ppResult,
  191. __in_opt struct timeval *timeout,
  192. __in_opt LPOVERLAPPED lpOverlapped,
  193. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  194. __out_opt LPHANDLE lpHandle
  195. );
  196. #ifdef UNICODE
  197. #define LPFN_GETADDRINFOEX LPFN_GETADDRINFOEXW
  198. #else
  199. #define LPFN_GETADDRINFOEX LPFN_GETADDRINFOEXA
  200. #endif
  201. #endif
  202. #endif
  203. #if (_WIN32_WINNT >= 0x0600)
  204. WINSOCK_API_LINKAGE
  205. INT
  206. WSAAPI
  207. SetAddrInfoExA(
  208. __in PCSTR pName,
  209. __in_opt PCSTR pServiceName,
  210. __in_opt SOCKET_ADDRESS *pAddresses,
  211. __in DWORD dwAddressCount,
  212. __in_opt LPBLOB lpBlob,
  213. __in DWORD dwFlags,
  214. __in DWORD dwNameSpace,
  215. __in_opt LPGUID lpNspId,
  216. __in_opt struct timeval *timeout,
  217. __in_opt LPOVERLAPPED lpOverlapped,
  218. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  219. __out_opt LPHANDLE lpNameHandle
  220. );
  221. WINSOCK_API_LINKAGE
  222. INT
  223. WSAAPI
  224. SetAddrInfoExW(
  225. __in PCWSTR pName,
  226. __in_opt PCWSTR pServiceName,
  227. __in_opt SOCKET_ADDRESS *pAddresses,
  228. __in DWORD dwAddressCount,
  229. __in_opt LPBLOB lpBlob,
  230. __in DWORD dwFlags,
  231. __in DWORD dwNameSpace,
  232. __in_opt LPGUID lpNspId,
  233. __in_opt struct timeval *timeout,
  234. __in_opt LPOVERLAPPED lpOverlapped,
  235. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  236. __out_opt LPHANDLE lpNameHandle
  237. );
  238. #ifdef UNICODE
  239. #define SetAddrInfoEx SetAddrInfoExW
  240. #else
  241. #define SetAddrInfoEx SetAddrInfoExA
  242. #endif
  243. #if INCL_WINSOCK_API_TYPEDEFS
  244. typedef
  245. INT
  246. (WSAAPI *LPFN_SETADDRINFOEXA)(
  247. __in PCSTR pName,
  248. __in_opt PCSTR pServiceName,
  249. __in_opt SOCKET_ADDRESS *pAddresses,
  250. __in DWORD dwAddressCount,
  251. __in_opt LPBLOB lpBlob,
  252. __in DWORD dwFlags,
  253. __in DWORD dwNameSpace,
  254. __in_opt LPGUID lpNspId,
  255. __in_opt struct timeval *timeout,
  256. __in_opt LPOVERLAPPED lpOverlapped,
  257. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  258. __out_opt LPHANDLE lpNameHandle
  259. );
  260. typedef
  261. INT
  262. (WSAAPI *LPFN_SETADDRINFOEXW)(
  263. __in PCWSTR pName,
  264. __in_opt PCWSTR pServiceName,
  265. __in_opt SOCKET_ADDRESS *pAddresses,
  266. __in DWORD dwAddressCount,
  267. __in_opt LPBLOB lpBlob,
  268. __in DWORD dwFlags,
  269. __in DWORD dwNameSpace,
  270. __in_opt LPGUID lpNspId,
  271. __in_opt struct timeval *timeout,
  272. __in_opt LPOVERLAPPED lpOverlapped,
  273. __in_opt LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
  274. __out_opt LPHANDLE lpNameHandle
  275. );
  276. #ifdef UNICODE
  277. #define LPFN_SETADDRINFOEX LPFN_SETADDRINFOEXW
  278. #else
  279. #define LPFN_SETADDRINFOEX LPFN_SETADDRINFOEXA
  280. #endif
  281. #endif
  282. #endif
  283. WINSOCK_API_LINKAGE
  284. VOID
  285. WSAAPI
  286. freeaddrinfo(
  287. __in_opt PADDRINFOA pAddrInfo
  288. );
  289. #if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
  290. WINSOCK_API_LINKAGE
  291. VOID
  292. WSAAPI
  293. FreeAddrInfoW(
  294. __in_opt PADDRINFOW pAddrInfo
  295. );
  296. #define FreeAddrInfoA freeaddrinfo
  297. #ifdef UNICODE
  298. #define FreeAddrInfo FreeAddrInfoW
  299. #else
  300. #define FreeAddrInfo FreeAddrInfoA
  301. #endif
  302. #endif
  303. #if INCL_WINSOCK_API_TYPEDEFS
  304. typedef
  305. VOID
  306. (WSAAPI * LPFN_FREEADDRINFO)(
  307. __in_opt PADDRINFOA pAddrInfo
  308. );
  309. typedef
  310. VOID
  311. (WSAAPI * LPFN_FREEADDRINFOW)(
  312. __in_opt PADDRINFOW pAddrInfo
  313. );
  314. #define LPFN_FREEADDRINFOA LPFN_FREEADDRINFO
  315. #ifdef UNICODE
  316. #define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOW
  317. #else
  318. #define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOA
  319. #endif
  320. #endif
  321. #if (_WIN32_WINNT >= 0x0600)
  322. WINSOCK_API_LINKAGE
  323. void
  324. WSAAPI
  325. FreeAddrInfoEx(
  326. __in_opt PADDRINFOEXA pAddrInfoEx
  327. );
  328. WINSOCK_API_LINKAGE
  329. void
  330. WSAAPI
  331. FreeAddrInfoExW(
  332. __in_opt PADDRINFOEXW pAddrInfoEx
  333. );
  334. #define FreeAddrInfoExA FreeAddrInfoEx
  335. #ifdef UNICODE
  336. #define FreeAddrInfoEx FreeAddrInfoExW
  337. #endif
  338. #ifdef INCL_WINSOCK_API_TYPEDEFS
  339. typedef
  340. void
  341. (WSAAPI *LPFN_FREEADDRINFOEXA)(
  342. __in PADDRINFOEXA pAddrInfoEx
  343. );
  344. typedef
  345. void
  346. (WSAAPI *LPFN_FREEADDRINFOEXW)(
  347. __in PADDRINFOEXW pAddrInfoEx
  348. );
  349. #ifdef UNICODE
  350. #define LPFN_FREEADDRINFOEX LPFN_FREEADDRINFOEXW
  351. #else
  352. #define LPFN_FREEADDRINFOEX LPFN_FREEADDRINFOEXA
  353. #endif
  354. #endif
  355. #endif
  356. typedef int socklen_t;
  357. WINSOCK_API_LINKAGE
  358. INT
  359. WSAAPI
  360. getnameinfo(
  361. __in_bcount(SockaddrLength) const SOCKADDR * pSockaddr,
  362. __in socklen_t SockaddrLength,
  363. __out_ecount_opt(NodeBufferSize) PCHAR pNodeBuffer,
  364. __in DWORD NodeBufferSize,
  365. __out_ecount_opt(ServiceBufferSize) PCHAR pServiceBuffer,
  366. __in DWORD ServiceBufferSize,
  367. __in INT Flags
  368. );
  369. #if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
  370. WINSOCK_API_LINKAGE
  371. INT
  372. WSAAPI
  373. GetNameInfoW(
  374. __in_bcount(SockaddrLength) const SOCKADDR * pSockaddr,
  375. __in socklen_t SockaddrLength,
  376. __out_ecount_opt(NodeBufferSize) PWCHAR pNodeBuffer,
  377. __in DWORD NodeBufferSize,
  378. __out_ecount_opt(ServiceBufferSize) PWCHAR pServiceBuffer,
  379. __in DWORD ServiceBufferSize,
  380. __in INT Flags
  381. );
  382. #define GetNameInfoA getnameinfo
  383. #ifdef UNICODE
  384. #define GetNameInfo GetNameInfoW
  385. #else
  386. #define GetNameInfo GetNameInfoA
  387. #endif
  388. #endif
  389. #if INCL_WINSOCK_API_TYPEDEFS
  390. typedef
  391. int
  392. (WSAAPI * LPFN_GETNAMEINFO)(
  393. __in_bcount(SockaddrLength) const SOCKADDR * pSockaddr,
  394. __in socklen_t SockaddrLength,
  395. __out_ecount_opt(NodeBufferSize) PCHAR pNodeBuffer,
  396. __in DWORD NodeBufferSize,
  397. __out_ecount_opt(ServiceBufferSize) PCHAR pServiceBuffer,
  398. __in DWORD ServiceBufferSize,
  399. __in INT Flags
  400. );
  401. typedef
  402. INT
  403. (WSAAPI * LPFN_GETNAMEINFOW)(
  404. __in_bcount(SockaddrLength) const SOCKADDR * pSockaddr,
  405. __in socklen_t SockaddrLength,
  406. __out_ecount_opt(NodeBufferSize) PWCHAR pNodeBuffer,
  407. __in DWORD NodeBufferSize,
  408. __out_ecount_opt(ServiceBufferSize) PWCHAR pServiceBuffer,
  409. __in DWORD ServiceBufferSize,
  410. __in INT Flags
  411. );
  412. #define LPFN_GETNAMEINFOA LPFN_GETNAMEINFO
  413. #ifdef UNICODE
  414. #define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOW
  415. #else
  416. #define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOA
  417. #endif
  418. #endif
  419. #if (NTDDI_VERSION >= NTDDI_VISTA)
  420. WINSOCK_API_LINKAGE
  421. INT
  422. WSAAPI
  423. inet_pton(
  424. __in INT Family,
  425. __in PCSTR pszAddrString,
  426. __out_bcount(sizeof(IN6_ADDR)) PVOID pAddrBuf
  427. );
  428. INT
  429. WSAAPI
  430. InetPtonW(
  431. __in INT Family,
  432. __in PCWSTR pszAddrString,
  433. __out_bcount(sizeof(IN6_ADDR)) PVOID pAddrBuf
  434. );
  435. PCSTR
  436. WSAAPI
  437. inet_ntop(
  438. __in INT Family,
  439. __in PVOID pAddr,
  440. __out_ecount(StringBufSize) PSTR pStringBuf,
  441. __in size_t StringBufSize
  442. );
  443. PCWSTR
  444. WSAAPI
  445. InetNtopW(
  446. __in INT Family,
  447. __in PVOID pAddr,
  448. __out_ecount(StringBufSize) PWSTR pStringBuf,
  449. __in size_t StringBufSize
  450. );
  451. #define InetPtonA inet_pton
  452. #define InetNtopA inet_ntop
  453. #ifdef UNICODE
  454. #define InetPton InetPtonW
  455. #define InetNtop InetNtopW
  456. #else
  457. #define InetPton InetPtonA
  458. #define InetNtop InetNtopA
  459. #endif
  460. #if INCL_WINSOCK_API_TYPEDEFS
  461. typedef
  462. INT
  463. (WSAAPI * LPFN_INET_PTONA)(
  464. __in INT Family,
  465. __in PCSTR pszAddrString,
  466. __out_bcount(sizeof(IN6_ADDR)) PVOID pAddrBuf
  467. );
  468. typedef
  469. INT
  470. (WSAAPI * LPFN_INET_PTONW)(
  471. __in INT Family,
  472. __in PCWSTR pszAddrString,
  473. __out_bcount(sizeof(IN6_ADDR)) PVOID pAddrBuf
  474. );
  475. typedef
  476. PCSTR
  477. (WSAAPI * LPFN_INET_NTOPA)(
  478. __in INT Family,
  479. __in PVOID pAddr,
  480. __out_ecount(StringBufSize) PSTR pStringBuf,
  481. __in size_t StringBufSize
  482. );
  483. typedef
  484. PCWSTR
  485. (WSAAPI * LPFN_INET_NTOPW)(
  486. __in INT Family,
  487. __in PVOID pAddr,
  488. __out_ecount(StringBufSize) PWSTR pStringBuf,
  489. __in size_t StringBufSize
  490. );
  491. #ifdef UNICODE
  492. #define LPFN_INET_PTON LPFN_INET_PTONW
  493. #define LPFN_INET_NTOP LPFN_INET_NTOPW
  494. #else
  495. #define LPFN_INET_PTON LPFN_INET_PTONA
  496. #define LPFN_INET_NTOP LPFN_INET_NTOPA
  497. #endif
  498. #endif // TYPEDEFS
  499. #endif // (NTDDI_VERSION >= NTDDI_VISTA)
  500. #if INCL_WINSOCK_API_PROTOTYPES
  501. #ifdef UNICODE
  502. #define gai_strerror gai_strerrorW
  503. #else
  504. #define gai_strerror gai_strerrorA
  505. #endif /* UNICODE */
  506. // WARNING: The gai_strerror inline functions below use static buffers,
  507. // and hence are not thread-safe. We'll use buffers long enough to hold
  508. // 1k characters. Any system error messages longer than this will be
  509. // returned as empty strings. However 1k should work for the error codes
  510. // used by getaddrinfo().
  511. #define GAI_STRERROR_BUFFER_SIZE 1024
  512. WS2TCPIP_INLINE
  513. char *
  514. gai_strerrorA(
  515. __in int ecode)
  516. {
  517. DWORD dwMsgLen;
  518. static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
  519. dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
  520. |FORMAT_MESSAGE_IGNORE_INSERTS
  521. |FORMAT_MESSAGE_MAX_WIDTH_MASK,
  522. NULL,
  523. ecode,
  524. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  525. (LPSTR)buff,
  526. GAI_STRERROR_BUFFER_SIZE,
  527. NULL);
  528. return buff;
  529. }
  530. WS2TCPIP_INLINE
  531. WCHAR *
  532. gai_strerrorW(
  533. __in int ecode
  534. )
  535. {
  536. DWORD dwMsgLen;
  537. static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
  538. dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
  539. |FORMAT_MESSAGE_IGNORE_INSERTS
  540. |FORMAT_MESSAGE_MAX_WIDTH_MASK,
  541. NULL,
  542. ecode,
  543. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  544. (LPWSTR)buff,
  545. GAI_STRERROR_BUFFER_SIZE,
  546. NULL);
  547. return buff;
  548. }
  549. #endif /* INCL_WINSOCK_API_PROTOTYPES */
  550. /* Multicast source filter APIs from RFC 3678. */
  551. WS2TCPIP_INLINE
  552. int
  553. setipv4sourcefilter(
  554. __in SOCKET Socket,
  555. __in IN_ADDR Interface,
  556. __in IN_ADDR Group,
  557. __in MULTICAST_MODE_TYPE FilterMode,
  558. __in ULONG SourceCount,
  559. __in CONST IN_ADDR *SourceList
  560. )
  561. {
  562. int Error;
  563. DWORD Size, Returned;
  564. PIP_MSFILTER Filter;
  565. if (SourceCount >
  566. (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
  567. WSASetLastError(WSAENOBUFS);
  568. return SOCKET_ERROR;
  569. }
  570. Size = IP_MSFILTER_SIZE(SourceCount);
  571. Filter = (PIP_MSFILTER) HeapAlloc(GetProcessHeap(), 0, Size);
  572. if (Filter == NULL) {
  573. WSASetLastError(WSAENOBUFS);
  574. return SOCKET_ERROR;
  575. }
  576. Filter->imsf_multiaddr = Group;
  577. Filter->imsf_interface = Interface;
  578. Filter->imsf_fmode = FilterMode;
  579. Filter->imsf_numsrc = SourceCount;
  580. if (SourceCount > 0) {
  581. CopyMemory(Filter->imsf_slist, SourceList,
  582. SourceCount * sizeof(*SourceList));
  583. }
  584. Error = WSAIoctl(Socket, SIOCSIPMSFILTER, Filter, Size, NULL, 0,
  585. &Returned, NULL, NULL);
  586. HeapFree(GetProcessHeap(), 0, Filter);
  587. return Error;
  588. }
  589. WS2TCPIP_INLINE
  590. int
  591. getipv4sourcefilter(
  592. __in SOCKET Socket,
  593. __in IN_ADDR Interface,
  594. __in IN_ADDR Group,
  595. __out MULTICAST_MODE_TYPE *FilterMode,
  596. __inout ULONG *SourceCount,
  597. __out IN_ADDR *SourceList
  598. )
  599. {
  600. int Error;
  601. DWORD Size, Returned;
  602. PIP_MSFILTER Filter;
  603. if (*SourceCount >
  604. (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
  605. WSASetLastError(WSAENOBUFS);
  606. return SOCKET_ERROR;
  607. }
  608. Size = IP_MSFILTER_SIZE(*SourceCount);
  609. Filter = (PIP_MSFILTER) HeapAlloc(GetProcessHeap(), 0, Size);
  610. if (Filter == NULL) {
  611. WSASetLastError(WSAENOBUFS);
  612. return SOCKET_ERROR;
  613. }
  614. Filter->imsf_multiaddr = Group;
  615. Filter->imsf_interface = Interface;
  616. Filter->imsf_numsrc = *SourceCount;
  617. Error = WSAIoctl(Socket, SIOCGIPMSFILTER, Filter, Size, Filter, Size,
  618. &Returned, NULL, NULL);
  619. if (Error == 0) {
  620. if (*SourceCount > 0) {
  621. CopyMemory(SourceList, Filter->imsf_slist,
  622. *SourceCount * sizeof(*SourceList));
  623. *SourceCount = Filter->imsf_numsrc;
  624. }
  625. *FilterMode = Filter->imsf_fmode;
  626. }
  627. HeapFree(GetProcessHeap(), 0, Filter);
  628. return Error;
  629. }
  630. #if (NTDDI_VERSION >= NTDDI_WINXP)
  631. WS2TCPIP_INLINE
  632. int
  633. setsourcefilter(
  634. __in SOCKET Socket,
  635. __in ULONG Interface,
  636. __in CONST SOCKADDR *Group,
  637. __in int GroupLength,
  638. __in MULTICAST_MODE_TYPE FilterMode,
  639. __in ULONG SourceCount,
  640. __in CONST SOCKADDR_STORAGE *SourceList
  641. )
  642. {
  643. int Error;
  644. DWORD Size, Returned;
  645. PGROUP_FILTER Filter;
  646. if (SourceCount >=
  647. (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
  648. WSASetLastError(WSAENOBUFS);
  649. return SOCKET_ERROR;
  650. }
  651. Size = GROUP_FILTER_SIZE(SourceCount);
  652. Filter = (PGROUP_FILTER) HeapAlloc(GetProcessHeap(), 0, Size);
  653. if (Filter == NULL) {
  654. WSASetLastError(WSAENOBUFS);
  655. return SOCKET_ERROR;
  656. }
  657. Filter->gf_interface = Interface;
  658. ZeroMemory(&Filter->gf_group, sizeof(Filter->gf_group));
  659. CopyMemory(&Filter->gf_group, Group, GroupLength);
  660. Filter->gf_fmode = FilterMode;
  661. Filter->gf_numsrc = SourceCount;
  662. if (SourceCount > 0) {
  663. CopyMemory(Filter->gf_slist, SourceList,
  664. SourceCount * sizeof(*SourceList));
  665. }
  666. Error = WSAIoctl(Socket, SIOCSMSFILTER, Filter, Size, NULL, 0,
  667. &Returned, NULL, NULL);
  668. HeapFree(GetProcessHeap(), 0, Filter);
  669. return Error;
  670. }
  671. WS2TCPIP_INLINE
  672. int
  673. getsourcefilter(
  674. __in SOCKET Socket,
  675. __in ULONG Interface,
  676. __in CONST SOCKADDR *Group,
  677. __in int GroupLength,
  678. __out MULTICAST_MODE_TYPE *FilterMode,
  679. __inout ULONG *SourceCount,
  680. __out SOCKADDR_STORAGE *SourceList
  681. )
  682. {
  683. int Error;
  684. DWORD Size, Returned;
  685. PGROUP_FILTER Filter;
  686. if (*SourceCount >
  687. (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
  688. WSASetLastError(WSAENOBUFS);
  689. return SOCKET_ERROR;
  690. }
  691. Size = GROUP_FILTER_SIZE(*SourceCount);
  692. Filter = (PGROUP_FILTER) HeapAlloc(GetProcessHeap(), 0, Size);
  693. if (Filter == NULL) {
  694. WSASetLastError(WSAENOBUFS);
  695. return SOCKET_ERROR;
  696. }
  697. Filter->gf_interface = Interface;
  698. ZeroMemory(&Filter->gf_group, sizeof(Filter->gf_group));
  699. CopyMemory(&Filter->gf_group, Group, GroupLength);
  700. Filter->gf_numsrc = *SourceCount;
  701. Error = WSAIoctl(Socket, SIOCGMSFILTER, Filter, Size, Filter, Size,
  702. &Returned, NULL, NULL);
  703. if (Error == 0) {
  704. if (*SourceCount > 0) {
  705. CopyMemory(SourceList, Filter->gf_slist,
  706. *SourceCount * sizeof(*SourceList));
  707. *SourceCount = Filter->gf_numsrc;
  708. }
  709. *FilterMode = Filter->gf_fmode;
  710. }
  711. HeapFree(GetProcessHeap(), 0, Filter);
  712. return Error;
  713. }
  714. #endif
  715. #ifdef IDEAL_SEND_BACKLOG_IOCTLS
  716. //
  717. // Wrapper functions for the ideal send backlog query and change notification
  718. // ioctls
  719. //
  720. WS2TCPIP_INLINE
  721. int
  722. idealsendbacklogquery(
  723. __in SOCKET s,
  724. __out ULONG *pISB
  725. )
  726. {
  727. DWORD bytes;
  728. return WSAIoctl(s, SIO_IDEAL_SEND_BACKLOG_QUERY,
  729. NULL, 0, pISB, sizeof(*pISB), &bytes, NULL, NULL);
  730. }
  731. WS2TCPIP_INLINE
  732. int
  733. idealsendbacklognotify(
  734. __in SOCKET s,
  735. __in_opt LPWSAOVERLAPPED lpOverlapped,
  736. __in_opt LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  737. )
  738. {
  739. DWORD bytes;
  740. return WSAIoctl(s, SIO_IDEAL_SEND_BACKLOG_CHANGE,
  741. NULL, 0, NULL, 0, &bytes,
  742. lpOverlapped, lpCompletionRoutine);
  743. }
  744. #endif
  745. #if (_WIN32_WINNT >= 0x0600)
  746. #ifdef _SECURE_SOCKET_TYPES_DEFINED_
  747. //
  748. // Secure socket API definitions
  749. //
  750. WINSOCK_API_LINKAGE
  751. INT
  752. WSAAPI
  753. WSASetSocketSecurity (
  754. __in SOCKET Socket,
  755. __in_bcount_opt(SecuritySettingsLen) const SOCKET_SECURITY_SETTINGS* SecuritySettings,
  756. __in ULONG SecuritySettingsLen,
  757. __in_opt LPWSAOVERLAPPED Overlapped,
  758. __in_opt LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
  759. );
  760. WINSOCK_API_LINKAGE
  761. INT
  762. WSAAPI
  763. WSAQuerySocketSecurity (
  764. __in SOCKET Socket,
  765. __in_bcount_opt(SecurityQueryTemplateLen) const SOCKET_SECURITY_QUERY_TEMPLATE* SecurityQueryTemplate,
  766. __in ULONG SecurityQueryTemplateLen,
  767. __out_bcount_part_opt(*SecurityQueryInfoLen, *SecurityQueryInfoLen) SOCKET_SECURITY_QUERY_INFO* SecurityQueryInfo,
  768. __inout ULONG* SecurityQueryInfoLen,
  769. __in_opt LPWSAOVERLAPPED Overlapped,
  770. __in_opt LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
  771. );
  772. WINSOCK_API_LINKAGE
  773. INT
  774. WSAAPI
  775. WSASetSocketPeerTargetName (
  776. __in SOCKET Socket,
  777. __in_bcount(PeerTargetNameLen) const SOCKET_PEER_TARGET_NAME* PeerTargetName,
  778. __in ULONG PeerTargetNameLen,
  779. __in_opt LPWSAOVERLAPPED Overlapped,
  780. __in_opt LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
  781. );
  782. WINSOCK_API_LINKAGE
  783. INT
  784. WSAAPI
  785. WSADeleteSocketPeerTargetName (
  786. __in SOCKET Socket,
  787. __in_bcount(PeerAddrLen) const struct sockaddr* PeerAddr,
  788. __in ULONG PeerAddrLen,
  789. __in_opt LPWSAOVERLAPPED Overlapped,
  790. __in_opt LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
  791. );
  792. WINSOCK_API_LINKAGE
  793. INT
  794. WSAAPI
  795. WSAImpersonateSocketPeer (
  796. __in SOCKET Socket,
  797. __in_bcount_opt(PeerAddrLen) const struct sockaddr* PeerAddr,
  798. __in ULONG PeerAddrLen
  799. );
  800. WINSOCK_API_LINKAGE
  801. INT
  802. WSAAPI
  803. WSARevertImpersonation ();
  804. #endif //_SECURE_SOCKET_TYPES_DEFINED_
  805. #endif //(_WIN32_WINNT >= 0x0600)
  806. #ifdef __cplusplus
  807. }
  808. #endif
  809. //
  810. // Unless the build environment is explicitly targeting only
  811. // platforms that include built-in getaddrinfo() support, include
  812. // the backwards-compatibility version of the relevant APIs.
  813. //
  814. #if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)
  815. #include <wspiapi.h>
  816. #endif
  817. #endif /* _WS2TCPIP_H_ */