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