[PSDK]
[reactos.git] / reactos / include / psdk / ws2tcpip.h
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 PCSTR pNodeName OPTIONAL,
66 IN PCSTR pServiceName OPTIONAL,
67 IN const ADDRINFOA *pHints OPTIONAL,
68 OUT 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 PCWSTR pNodeName OPTIONAL,
77 IN PCWSTR pServiceName OPTIONAL,
78 IN const ADDRINFOW *pHints OPTIONAL,
79 OUT 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 PCSTR pNodeName OPTIONAL,
96 IN PCSTR pServiceName OPTIONAL,
97 IN const ADDRINFOA *pHints OPTIONAL,
98 OUT PADDRINFOA *ppResult);
99
100 typedef INT
101 (WSAAPI *LPFN_GETADDRINFOW)(
102 IN PCWSTR pNodeName OPTIONAL,
103 IN PCWSTR pServiceName OPTIONAL,
104 IN const ADDRINFOW *pHints OPTIONAL,
105 OUT 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 PCSTR pName OPTIONAL,
130 IN PCSTR pServiceName OPTIONAL,
131 IN DWORD dwNameSpace,
132 IN LPGUID lpNspId OPTIONAL,
133 IN const ADDRINFOEXA *hints,
134 OUT PADDRINFOEXA *ppResult,
135 IN struct timeval *timeout OPTIONAL,
136 IN LPOVERLAPPED lpOverlapped OPTIONAL,
137 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
138 OUT LPHANDLE lpNameHandle OPTIONAL);
139
140 WINSOCK_API_LINKAGE
141 INT
142 WSAAPI
143 GetAddrInfoExW(
144 IN PCWSTR pName OPTIONAL,
145 IN PCWSTR pServiceName OPTIONAL,
146 IN DWORD dwNameSpace,
147 IN LPGUID lpNspId OPTIONAL,
148 IN const ADDRINFOEXW *hints OPTIONAL,
149 OUT PADDRINFOEXW *ppResult,
150 IN struct timeval *timeout OPTIONAL,
151 IN LPOVERLAPPED lpOverlapped OPTIONAL,
152 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
153 OUT LPHANDLE lpHandle OPTIONAL);
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 PCSTR pServiceName OPTIONAL,
167 IN DWORD dwNameSpace,
168 IN LPGUID lpNspId OPTIONAL,
169 IN const ADDRINFOEXA *hints OPTIONAL,
170 OUT PADDRINFOEXA *ppResult,
171 IN struct timeval *timeout OPTIONAL,
172 IN LPOVERLAPPED lpOverlapped OPTIONAL,
173 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
174 OUT LPHANDLE lpNameHandle OPTIONAL);
175
176 typedef INT
177 (WSAAPI *LPFN_GETADDRINFOEXW)(
178 IN PCWSTR pName,
179 IN PCWSTR pServiceName OPTIONAL,
180 IN DWORD dwNameSpace,
181 IN LPGUID lpNspId OPTIONAL,
182 IN const ADDRINFOEXW *hints OPTIONAL,
183 OUT PADDRINFOEXW *ppResult,
184 IN struct timeval *timeout OPTIONAL,
185 IN LPOVERLAPPED lpOverlapped OPTIONAL,
186 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
187 OUT LPHANDLE lpHandle OPTIONAL);
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 PCSTR pServiceName OPTIONAL,
206 IN SOCKET_ADDRESS *pAddresses OPTIONAL,
207 IN DWORD dwAddressCount,
208 IN LPBLOB lpBlob OPTIONAL,
209 IN DWORD dwFlags,
210 IN DWORD dwNameSpace,
211 IN LPGUID lpNspId OPTIONAL,
212 IN struct timeval *timeout OPTIONAL,
213 IN LPOVERLAPPED lpOverlapped OPTIONAL,
214 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
215 OUT LPHANDLE lpNameHandle OPTIONAL);
216
217 WINSOCK_API_LINKAGE
218 INT
219 WSAAPI
220 SetAddrInfoExW(
221 IN PCWSTR pName,
222 IN PCWSTR pServiceName OPTIONAL,
223 IN SOCKET_ADDRESS *pAddresses OPTIONAL,
224 IN DWORD dwAddressCount,
225 IN LPBLOB lpBlob OPTIONAL,
226 IN DWORD dwFlags,
227 IN DWORD dwNameSpace,
228 IN LPGUID lpNspId OPTIONAL,
229 IN struct timeval *timeout OPTIONAL,
230 IN LPOVERLAPPED lpOverlapped OPTIONAL,
231 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
232 OUT LPHANDLE lpNameHandle OPTIONAL);
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 PCSTR pServiceName OPTIONAL,
246 IN SOCKET_ADDRESS *pAddresses OPTIONAL,
247 IN DWORD dwAddressCount,
248 IN LPBLOB lpBlob OPTIONAL,
249 IN DWORD dwFlags,
250 IN DWORD dwNameSpace,
251 IN LPGUID lpNspId OPTIONAL,
252 IN struct timeval *timeout OPTIONAL,
253 IN LPOVERLAPPED lpOverlapped OPTIONAL,
254 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
255 OUT LPHANDLE lpNameHandle OPTIONAL);
256
257 typedef INT
258 (WSAAPI *LPFN_SETADDRINFOEXW)(
259 IN PCWSTR pName,
260 IN PCWSTR pServiceName OPTIONAL,
261 IN SOCKET_ADDRESS *pAddresses OPTIONAL,
262 IN DWORD dwAddressCount,
263 IN LPBLOB lpBlob OPTIONAL,
264 IN DWORD dwFlags,
265 IN DWORD dwNameSpace,
266 IN LPGUID lpNspId OPTIONAL,
267 IN struct timeval *timeout OPTIONAL,
268 IN LPOVERLAPPED lpOverlapped OPTIONAL,
269 IN LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL,
270 OUT LPHANDLE lpNameHandle OPTIONAL);
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 PADDRINFOA pAddrInfo OPTIONAL);
286
287 #if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
288
289 WINSOCK_API_LINKAGE
290 VOID
291 WSAAPI
292 FreeAddrInfoW(
293 IN PADDRINFOW pAddrInfo OPTIONAL);
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 PADDRINFOA pAddrInfo OPTIONAL);
309
310 typedef VOID
311 (WSAAPI *LPFN_FREEADDRINFOW)(
312 IN PADDRINFOW pAddrInfo OPTIONAL);
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 PADDRINFOEXA pAddrInfoEx OPTIONAL);
331
332 WINSOCK_API_LINKAGE
333 void
334 WSAAPI
335 FreeAddrInfoExW(
336 IN PADDRINFOEXW pAddrInfoEx OPTIONAL);
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 const SOCKADDR *pSockaddr,
371 IN socklen_t SockaddrLength,
372 OUT PCHAR pNodeBuffer OPTIONAL,
373 IN DWORD NodeBufferSize,
374 OUT 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 const SOCKADDR *pSockaddr,
385 IN socklen_t SockaddrLength,
386 OUT PWCHAR pNodeBuffer,
387 IN DWORD NodeBufferSize,
388 OUT PWCHAR pServiceBuffer OPTIONAL,
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 const SOCKADDR *pSockaddr,
407 IN socklen_t SockaddrLength,
408 OUT PCHAR pNodeBuffer,
409 IN DWORD NodeBufferSize,
410 OUT PCHAR pServiceBuffer OPTIONAL,
411 IN DWORD ServiceBufferSize,
412 IN INT Flags);
413
414 typedef INT
415 (WSAAPI *LPFN_GETNAMEINFOW)(
416 IN const SOCKADDR *pSockaddr,
417 IN socklen_t SockaddrLength,
418 OUT PWCHAR pNodeBuffer,
419 IN DWORD NodeBufferSize,
420 OUT PWCHAR pServiceBuffer OPTIONAL,
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 PVOID pAddrBuf);
442
443 INT
444 WSAAPI
445 InetPtonW(
446 IN INT Family,
447 IN PCWSTR pszAddrString,
448 OUT PVOID pAddrBuf);
449
450 PCSTR
451 WSAAPI
452 inet_ntop(
453 IN INT Family,
454 IN PVOID pAddr,
455 OUT PSTR pStringBuf,
456 IN size_t StringBufSize);
457
458 PCWSTR
459 WSAAPI
460 InetNtopW(
461 IN INT Family,
462 IN PVOID pAddr,
463 OUT 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 PVOID pAddrBuf);
484
485 typedef INT
486 (WSAAPI *LPFN_INET_PTONW)(
487 IN INT Family,
488 IN PCWSTR pszAddrString,
489 OUT PVOID pAddrBuf);
490
491 typedef PCSTR
492 (WSAAPI *LPFN_INET_NTOPA)(
493 IN INT Family,
494 IN PVOID pAddr,
495 OUT 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 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 *
528 gai_strerrorA(
529 IN int ecode)
530 {
531 DWORD dwMsgLen;
532 static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
533
534 dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
535 |FORMAT_MESSAGE_IGNORE_INSERTS
536 |FORMAT_MESSAGE_MAX_WIDTH_MASK,
537 NULL,
538 ecode,
539 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
540 (LPSTR)buff,
541 GAI_STRERROR_BUFFER_SIZE,
542 NULL);
543
544 return buff;
545 }
546
547 static __inline
548 WCHAR *
549 gai_strerrorW(
550 IN int ecode)
551 {
552 DWORD dwMsgLen;
553 static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
554
555 dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
556 |FORMAT_MESSAGE_IGNORE_INSERTS
557 |FORMAT_MESSAGE_MAX_WIDTH_MASK,
558 NULL,
559 ecode,
560 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
561 (LPWSTR)buff,
562 GAI_STRERROR_BUFFER_SIZE,
563 NULL);
564
565 return buff;
566 }
567
568 #endif /* INCL_WINSOCK_API_PROTOTYPES */
569
570 WS2TCPIP_INLINE
571 int
572 setipv4sourcefilter(
573 IN SOCKET Socket,
574 IN IN_ADDR Interface,
575 IN IN_ADDR Group,
576 IN MULTICAST_MODE_TYPE FilterMode,
577 IN ULONG SourceCount,
578 IN CONST IN_ADDR *SourceList)
579 {
580 int Error;
581 DWORD Size, Returned;
582 PIP_MSFILTER Filter;
583
584 if (SourceCount >
585 (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
586 WSASetLastError(WSAENOBUFS);
587 return SOCKET_ERROR;
588 }
589
590 Size = IP_MSFILTER_SIZE(SourceCount);
591 Filter = (PIP_MSFILTER) HeapAlloc(GetProcessHeap(), 0, Size);
592 if (Filter == NULL) {
593 WSASetLastError(WSAENOBUFS);
594 return SOCKET_ERROR;
595 }
596
597 Filter->imsf_multiaddr = Group;
598 Filter->imsf_interface = Interface;
599 Filter->imsf_fmode = FilterMode;
600 Filter->imsf_numsrc = SourceCount;
601 if (SourceCount > 0) {
602 CopyMemory(Filter->imsf_slist, SourceList,
603 SourceCount * sizeof(*SourceList));
604 }
605
606 Error = WSAIoctl(Socket, SIOCSIPMSFILTER, Filter, Size, NULL, 0,
607 &Returned, NULL, NULL);
608
609 HeapFree(GetProcessHeap(), 0, Filter);
610
611 return Error;
612 }
613
614 WS2TCPIP_INLINE
615 int
616 getipv4sourcefilter(
617 IN SOCKET Socket,
618 IN IN_ADDR Interface,
619 IN IN_ADDR Group,
620 OUT MULTICAST_MODE_TYPE *FilterMode,
621 IN OUT ULONG *SourceCount,
622 OUT IN_ADDR *SourceList)
623 {
624 int Error;
625 DWORD Size, Returned;
626 PIP_MSFILTER Filter;
627
628 if (*SourceCount >
629 (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
630 WSASetLastError(WSAENOBUFS);
631 return SOCKET_ERROR;
632 }
633
634 Size = IP_MSFILTER_SIZE(*SourceCount);
635 Filter = (PIP_MSFILTER) HeapAlloc(GetProcessHeap(), 0, Size);
636 if (Filter == NULL) {
637 WSASetLastError(WSAENOBUFS);
638 return SOCKET_ERROR;
639 }
640
641 Filter->imsf_multiaddr = Group;
642 Filter->imsf_interface = Interface;
643 Filter->imsf_numsrc = *SourceCount;
644
645 Error = WSAIoctl(Socket, SIOCGIPMSFILTER, Filter, Size, Filter, Size,
646 &Returned, NULL, NULL);
647
648 if (Error == 0) {
649 if (*SourceCount > 0) {
650 CopyMemory(SourceList, Filter->imsf_slist,
651 *SourceCount * sizeof(*SourceList));
652 *SourceCount = Filter->imsf_numsrc;
653 }
654 *FilterMode = Filter->imsf_fmode;
655 }
656
657 HeapFree(GetProcessHeap(), 0, Filter);
658
659 return Error;
660 }
661
662 #if (NTDDI_VERSION >= NTDDI_WINXP)
663
664 WS2TCPIP_INLINE
665 int
666 setsourcefilter(
667 IN SOCKET Socket,
668 IN ULONG Interface,
669 IN CONST SOCKADDR *Group,
670 IN int GroupLength,
671 IN MULTICAST_MODE_TYPE FilterMode,
672 IN ULONG SourceCount,
673 IN CONST SOCKADDR_STORAGE *SourceList)
674 {
675 int Error;
676 DWORD Size, Returned;
677 PGROUP_FILTER Filter;
678
679 if (SourceCount >= (((ULONG) (ULONG_MAX - sizeof(*Filter))) / sizeof(*SourceList))) {
680 WSASetLastError(WSAENOBUFS);
681 return SOCKET_ERROR;
682 }
683
684 Size = GROUP_FILTER_SIZE(SourceCount);
685 Filter = (PGROUP_FILTER) HeapAlloc(GetProcessHeap(), 0, Size);
686 if (Filter == NULL) {
687 WSASetLastError(WSAENOBUFS);
688 return SOCKET_ERROR;
689 }
690
691 Filter->gf_interface = Interface;
692 ZeroMemory(&Filter->gf_group, sizeof(Filter->gf_group));
693 CopyMemory(&Filter->gf_group, Group, GroupLength);
694 Filter->gf_fmode = FilterMode;
695 Filter->gf_numsrc = SourceCount;
696 if (SourceCount > 0) {
697 CopyMemory(Filter->gf_slist, SourceList, SourceCount * sizeof(*SourceList));
698 }
699
700 Error = WSAIoctl(Socket, SIOCSMSFILTER, Filter, Size, NULL, 0, &Returned, NULL, NULL);
701 HeapFree(GetProcessHeap(), 0, Filter);
702
703 return Error;
704 }
705
706 WS2TCPIP_INLINE
707 int
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 IN OUT ULONG *SourceCount,
715 OUT 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
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
769 idealsendbacklognotify(
770 IN SOCKET s,
771 IN LPWSAOVERLAPPED lpOverlapped OPTIONAL,
772 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine OPTIONAL)
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 const SOCKET_SECURITY_SETTINGS *SecuritySettings OPTIONAL,
793 IN ULONG SecuritySettingsLen,
794 IN LPWSAOVERLAPPED Overlapped OPTIONAL,
795 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL);
796
797 WINSOCK_API_LINKAGE
798 INT
799 WSAAPI
800 WSAQuerySocketSecurity(
801 IN SOCKET Socket,
802 IN const SOCKET_SECURITY_QUERY_TEMPLATE *SecurityQueryTemplate OPTIONAL,
803 IN ULONG SecurityQueryTemplateLen,
804 OUT SOCKET_SECURITY_QUERY_INFO* SecurityQueryInfo OPTIONAL,
805 IN OUT ULONG *SecurityQueryInfoLen,
806 IN LPWSAOVERLAPPED Overlapped OPTIONAL,
807 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL);
808
809 WINSOCK_API_LINKAGE
810 INT
811 WSAAPI
812 WSASetSocketPeerTargetName(
813 IN SOCKET Socket,
814 IN const SOCKET_PEER_TARGET_NAME *PeerTargetName,
815 IN ULONG PeerTargetNameLen,
816 IN LPWSAOVERLAPPED Overlapped OPTIONAL,
817 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL);
818
819 WINSOCK_API_LINKAGE
820 INT
821 WSAAPI
822 WSADeleteSocketPeerTargetName(
823 IN SOCKET Socket,
824 IN const struct sockaddr *PeerAddr,
825 IN ULONG PeerAddrLen,
826 IN LPWSAOVERLAPPED Overlapped OPTIONAL,
827 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL);
828
829 WINSOCK_API_LINKAGE
830 INT
831 WSAAPI
832 WSAImpersonateSocketPeer(
833 IN SOCKET Socket,
834 IN const struct sockaddr *PeerAddr OPTIONAL,
835 IN ULONG PeerAddrLen);
836
837 WINSOCK_API_LINKAGE
838 INT
839 WSAAPI
840 WSARevertImpersonation();
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