[DDK]: Merge 46183 from header-branch.
[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 #ifndef _WS2TCPIP_H
10 #define _WS2TCPIP_H
11
12 #if (defined _WINSOCK_H && !defined _WINSOCK2_H)
13 #error "ws2tcpip.h is not compatable with winsock.h. Include winsock2.h instead."
14 #endif
15
16 #include <winsock2.h>
17 #include <ws2ipdef.h>
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*
23 * The IP_* macros are also defined in winsock.h, but some values are different there.
24 * The values defined in winsock.h for 1.1 and used in wsock32.dll are consistent
25 * with the original values Steve Deering defined in his document "IP Multicast Extensions
26 * for 4.3BSD UNIX related systems (MULTICAST 1.2 Release)." However, these conflicted with
27 * the definitions for some IPPROTO_IP level socket options already assigned by BSD,
28 * so Berkeley changed all the values by adding 7. WinSock2 (ws2_32.dll) uses
29 * the BSD 4.4 compatible values defined here.
30 *
31 * See also: msdn kb article Q257460
32 * http://support.microsoft.com/support/kb/articles/Q257/4/60.asp
33 */
34
35 /* This is also defined in winsock.h; value hasn't changed */
36 #define IP_OPTIONS 1
37
38 #define IP_HDRINCL 2
39 /*
40 * These are also be defined in winsock.h,
41 * but values have changed for WinSock2 interface
42 */
43 #define IP_TOS 3 /* old (winsock 1.1) value 8 */
44 #define IP_TTL 4 /* old value 7 */
45 #define IP_MULTICAST_IF 9 /* old value 2 */
46 #define IP_MULTICAST_TTL 10 /* old value 3 */
47 #define IP_MULTICAST_LOOP 11 /* old value 4 */
48 #define IP_ADD_MEMBERSHIP 12 /* old value 5 */
49 #define IP_DROP_MEMBERSHIP 13 /* old value 6 */
50 #define IP_DONTFRAGMENT 14 /* old value 9 */
51 #define IP_ADD_SOURCE_MEMBERSHIP 15
52 #define IP_DROP_SOURCE_MEMBERSHIP 16
53 #define IP_BLOCK_SOURCE 17
54 #define IP_UNBLOCK_SOURCE 18
55 #define IP_PKTINFO 19
56
57 /*
58 * As with BSD implementation, IPPROTO_IPV6 level socket options have
59 * same values as IPv4 counterparts.
60 */
61 #define IPV6_UNICAST_HOPS 4
62 #define IPV6_MULTICAST_IF 9
63 #define IPV6_MULTICAST_HOPS 10
64 #define IPV6_MULTICAST_LOOP 11
65 #define IPV6_ADD_MEMBERSHIP 12
66 #define IPV6_DROP_MEMBERSHIP 13
67 #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
68 #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
69 #define IPV6_PKTINFO 19
70
71 #define IP_DEFAULT_MULTICAST_TTL 1
72 #define IP_DEFAULT_MULTICAST_LOOP 1
73 #define IP_MAX_MEMBERSHIPS 20
74
75 #define TCP_EXPEDITED_1122 2
76
77 #define UDP_NOCHECKSUM 1
78
79 /* INTERFACE_INFO iiFlags */
80 #define IFF_UP 1
81 #define IFF_BROADCAST 2
82 #define IFF_LOOPBACK 4
83 #define IFF_POINTTOPOINT 8
84 #define IFF_MULTICAST 16
85
86 #define SIO_GET_INTERFACE_LIST _IOR('t', 127, u_long)
87
88 #define INET_ADDRSTRLEN 16
89 #define INET6_ADDRSTRLEN 46
90
91 /* getnameinfo constants */
92 #define NI_MAXHOST 1025
93 #define NI_MAXSERV 32
94
95 #define NI_NOFQDN 0x01
96 #define NI_NUMERICHOST 0x02
97 #define NI_NAMEREQD 0x04
98 #define NI_NUMERICSERV 0x08
99 #define NI_DGRAM 0x10
100
101 /* getaddrinfo constants */
102 #define AI_PASSIVE 1
103 #define AI_CANONNAME 2
104 #define AI_NUMERICHOST 4
105
106 /* getaddrinfo error codes */
107 #define EAI_AGAIN WSATRY_AGAIN
108 #define EAI_BADFLAGS WSAEINVAL
109 #define EAI_FAIL WSANO_RECOVERY
110 #define EAI_FAMILY WSAEAFNOSUPPORT
111 #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
112 #define EAI_NODATA WSANO_DATA
113 #define EAI_NONAME WSAHOST_NOT_FOUND
114 #define EAI_SERVICE WSATYPE_NOT_FOUND
115 #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
116
117 /*
118 * ip_mreq also in winsock.h for WinSock1.1,
119 * but online msdn docs say it is defined here for WinSock2.
120 */
121
122 struct ip_mreq {
123 struct in_addr imr_multiaddr;
124 struct in_addr imr_interface;
125 };
126
127 struct ip_mreq_source {
128 struct in_addr imr_multiaddr;
129 struct in_addr imr_sourceaddr;
130 struct in_addr imr_interface;
131 };
132
133 struct ip_msfilter {
134 struct in_addr imsf_multiaddr;
135 struct in_addr imsf_interface;
136 u_long imsf_fmode;
137 u_long imsf_numsrc;
138 struct in_addr imsf_slist[1];
139 };
140
141 #define IP_MSFILTER_SIZE(numsrc) \
142 (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
143 + (numsrc) * sizeof(struct in_addr))
144
145
146 /* ipv6 */
147 /* These require XP or .NET Server or use of add-on IPv6 stacks on NT 4
148 or higher */
149
150 /* This is based on the example given in RFC 2553 with stdint types
151 changed to BSD types. For now, use these field names until there
152 is some consistency in MS docs. In this file, we only use the
153 in6_addr structure start address, with casts to get the right offsets
154 when testing addresses */
155
156 struct in6_addr {
157 union {
158 u_char Byte[16];
159 u_short Word[8];
160 u_long _S6_u32[4];
161 } u;
162 };
163
164 /* s6_addr is the standard name */
165 #define s6_addr u.Byte
166
167 /* These are GLIBC names */
168 #define s6_addr16 u.Word
169 #define s6_addr32 u.Word
170
171 /* These are used in some MS code */
172 #define in_addr6 in6_addr
173 #define _s6_bytes u.Byte
174 #define _s6_words u.Word
175
176 typedef struct in6_addr IN6_ADDR, *PIN6_ADDR, *LPIN6_ADDR;
177
178 struct sockaddr_in6 {
179 short sin6_family; /* AF_INET6 */
180 u_short sin6_port; /* transport layer port # */
181 u_long sin6_flowinfo; /* IPv6 traffic class & flow info */
182 struct in6_addr sin6_addr; /* IPv6 address */
183 u_long sin6_scope_id; /* set of interfaces for a scope */
184 };
185 typedef struct sockaddr_in6 SOCKADDR_IN6, *PSOCKADDR_IN6, *LPSOCKADDR_IN6;
186
187 extern const struct in6_addr in6addr_any;
188 extern const struct in6_addr in6addr_loopback;
189 /* the above can get initialised using: */
190 #define IN6ADDR_ANY_INIT { 0 }
191 #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
192
193 /* Described in RFC 2292, but not in 2553 */
194 /* int IN6_ARE_ADDR_EQUAL(const struct in6_addr * a, const struct in6_addr * b) */
195 #define IN6_ARE_ADDR_EQUAL(a, b) \
196 (memcmp ((void*)(a), (void*)(b), sizeof (struct in6_addr)) == 0)
197
198
199 /* Address Testing Macros
200
201 These macro functions all take const struct in6_addr* as arg.
202 Static inlines would allow type checking, but RFC 2553 says they
203 macros.
204 NB: These are written specifically for little endian host */
205
206 #define IN6_IS_ADDR_UNSPECIFIED(_addr) \
207 ( (((const u_long *)(_addr))[0] == 0) \
208 && (((const u_long *)(_addr))[1] == 0) \
209 && (((const u_long *)(_addr))[2] == 0) \
210 && (((const u_long *)(_addr))[3] == 0))
211
212 #define IN6_IS_ADDR_LOOPBACK(_addr) \
213 ( (((const u_long *)(_addr))[0] == 0) \
214 && (((const u_long *)(_addr))[1] == 0) \
215 && (((const u_long *)(_addr))[2] == 0) \
216 && (((const u_long *)(_addr))[3] == 0x01000000)) /* Note byte order reversed */
217 /* (((const u_long *)(_addr))[3] == ntohl(1)) */
218
219 #define IN6_IS_ADDR_MULTICAST(_addr) (((const u_char *) (_addr))[0] == 0xff)
220
221 #define IN6_IS_ADDR_LINKLOCAL(_addr) \
222 ( (((const u_char *)(_addr))[0] == 0xfe) \
223 && ((((const u_char *)(_addr))[1] & 0xc0) == 0x80))
224
225 #define IN6_IS_ADDR_SITELOCAL(_addr) \
226 ( (((const u_char *)(_addr))[0] == 0xfe) \
227 && ((((const u_char *)(_addr))[1] & 0xc0) == 0xc0))
228
229 #define IN6_IS_ADDR_V4MAPPED(_addr) \
230 ( (((const u_long *)(_addr))[0] == 0) \
231 && (((const u_long *)(_addr))[1] == 0) \
232 && (((const u_long *)(_addr))[2] == 0xffff0000)) /* Note byte order reversed */
233 /* (((const u_long *)(_addr))[2] == ntohl(0x0000ffff))) */
234
235 #define IN6_IS_ADDR_V4COMPAT(_addr) \
236 ( (((const u_long *)(_addr))[0] == 0) \
237 && (((const u_long *)(_addr))[1] == 0) \
238 && (((const u_long *)(_addr))[2] == 0) \
239 && (((const u_long *)(_addr))[3] != 0) \
240 && (((const u_long *)(_addr))[3] != 0x01000000)) /* Note byte order reversed */
241 /* (ntohl (((const u_long *)(_addr))[3]) > 1 ) */
242
243
244 #define IN6_IS_ADDR_MC_NODELOCAL(_addr) \
245 ( IN6_IS_ADDR_MULTICAST(_addr) \
246 && ((((const u_char *)(_addr))[1] & 0xf) == 0x1))
247
248 #define IN6_IS_ADDR_MC_LINKLOCAL(_addr) \
249 ( IN6_IS_ADDR_MULTICAST (_addr) \
250 && ((((const u_char *)(_addr))[1] & 0xf) == 0x2))
251
252 #define IN6_IS_ADDR_MC_SITELOCAL(_addr) \
253 ( IN6_IS_ADDR_MULTICAST(_addr) \
254 && ((((const u_char *)(_addr))[1] & 0xf) == 0x5))
255
256 #define IN6_IS_ADDR_MC_ORGLOCAL(_addr) \
257 ( IN6_IS_ADDR_MULTICAST(_addr) \
258 && ((((const u_char *)(_addr))[1] & 0xf) == 0x8))
259
260 #define IN6_IS_ADDR_MC_GLOBAL(_addr) \
261 ( IN6_IS_ADDR_MULTICAST(_addr) \
262 && ((((const u_char *)(_addr))[1] & 0xf) == 0xe))
263
264
265 typedef int socklen_t;
266
267 struct ipv6_mreq {
268 struct in6_addr ipv6mr_multiaddr;
269 unsigned int ipv6mr_interface;
270 };
271 typedef struct ipv6_mreq IPV6_MREG;
272
273 struct in6_pktinfo {
274 IN6_ADDR ipi6_addr;
275 UINT ipi6_ifindex;
276 };
277 typedef struct in6_pktinfo IN6_PKTINFO;
278
279 typedef struct addrinfo
280 {
281 int ai_flags;
282 int ai_family;
283 int ai_socktype;
284 int ai_protocol;
285 size_t ai_addrlen;
286 char *ai_canonname;
287 struct sockaddr *ai_addr;
288 struct addrinfo *ai_next;
289 } ADDRINFOA, *PADDRINFOA;
290
291 typedef struct addrinfoW
292 {
293 int ai_flags;
294 int ai_family;
295 int ai_socktype;
296 int ai_protocol;
297 size_t ai_addrlen;
298 PWSTR ai_canonname;
299 struct sockaddr *ai_addr;
300 struct addrinfoW *ai_next;
301 } ADDRINFOW, *PADDRINFOW;
302
303 #ifdef UNICODE
304 typedef ADDRINFOW ADDRINFOT,*PADDRINFOT;
305 #else
306 typedef ADDRINFOA ADDRINFOT,*PADDRINFOT;
307 #endif
308
309 typedef ADDRINFOA ADDRINFO, FAR *LPADDRINFO;
310
311 void WSAAPI freeaddrinfo (struct addrinfo*);
312 int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
313 struct addrinfo**);
314
315 #define GAI_STRERROR_BUFFER_SIZE 1024
316
317 static __inline char*
318 gai_strerrorA(int ecode)
319 {
320 static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
321
322 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
323 NULL,
324 ecode,
325 MAKELANGID(LANG_NEUTRAL,
326 SUBLANG_DEFAULT),
327 (LPSTR)buff,
328 GAI_STRERROR_BUFFER_SIZE,
329 NULL);
330
331 return buff;
332 }
333
334 static __inline WCHAR*
335 gai_strerrorW(int ecode)
336 {
337 static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
338
339 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
340 NULL,
341 ecode,
342 MAKELANGID(LANG_NEUTRAL,
343 SUBLANG_DEFAULT),
344 (LPWSTR)buff,
345 GAI_STRERROR_BUFFER_SIZE,
346 NULL);
347
348 return buff;
349 }
350
351 #ifdef UNICODE
352 #define gai_strerror gai_strerrorW
353 #else
354 #define gai_strerror gai_strerrorA
355 #endif /* UNICODE */
356
357 int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
358 char*,DWORD,int);
359
360 #if (_WIN32_WINNT >= 0x0502)
361 INT WSAAPI GetNameInfoW(const SOCKADDR*,socklen_t,PWCHAR,DWORD,PWCHAR,DWORD,INT);
362 #define GetNameInfoA getnameinfo
363
364 #ifdef UNICODE
365 #define GetNameInfo GetNameInfoW
366 #else
367 #define GetNameInfo GetNameInfoA
368 #endif /* UNICODE */
369
370 #endif /* (_WIN32_WINNT >= 0x0502) */
371
372 /* Some older IPv4/IPv6 compatability stuff */
373
374 /* This struct lacks sin6_scope_id; retained for use in sockaddr_gen */
375 struct sockaddr_in6_old {
376 short sin6_family;
377 u_short sin6_port;
378 u_long sin6_flowinfo;
379 struct in6_addr sin6_addr;
380 };
381
382 typedef union sockaddr_gen{
383 struct sockaddr Address;
384 struct sockaddr_in AddressIn;
385 struct sockaddr_in6_old AddressIn6;
386 } sockaddr_gen;
387
388
389 typedef struct _INTERFACE_INFO {
390 u_long iiFlags;
391 sockaddr_gen iiAddress;
392 sockaddr_gen iiBroadcastAddress;
393 sockaddr_gen iiNetmask;
394 } INTERFACE_INFO, *LPINTERFACE_INFO;
395
396 /*
397 The definition above can cause problems on NT4,prior to sp4.
398 To workaround, include the following struct and typedef and
399 #define INTERFACE_INFO OLD_INTERFACE_INFO
400 See: FIX: WSAIoctl SIO_GET_INTERFACE_LIST Option Problem
401 (Q181520) in MSDN KB.
402
403 The old definition causes problems on newer NT and on XP.
404
405 typedef struct _OLD_INTERFACE_INFO {
406 u_long iiFlags;
407 struct sockaddr iiAddress;
408 struct sockaddr iiBroadcastAddress;
409 struct sockaddr iiNetmask;
410 } OLD_INTERFACE_INFO;
411 */
412
413 #ifdef __cplusplus
414 }
415 #endif
416
417 #endif /* _WS2TCPIP_H */