Merge trunk head (r41474)
[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 _S6_u8[16];
159 u_short _S6_u16[8];
160 u_long _S6_u32[4];
161 } _S6_un;
162 };
163 /* s6_addr is the standard name */
164 #define s6_addr _S6_un._S6_u8
165
166 /* These are GLIBC names */
167 #define s6_addr16 _S6_un._S6_u16
168 #define s6_addr32 _S6_un._S6_u16
169
170 /* These are used in some MS code */
171 #define in_addr6 in6_addr
172 #define _s6_bytes _S6_un._S6_u8
173 #define _s6_words _S6_un._S6_u16
174
175 typedef struct in6_addr IN6_ADDR, *PIN6_ADDR, *LPIN6_ADDR;
176
177 struct sockaddr_in6 {
178 short sin6_family; /* AF_INET6 */
179 u_short sin6_port; /* transport layer port # */
180 u_long sin6_flowinfo; /* IPv6 traffic class & flow info */
181 struct in6_addr sin6_addr; /* IPv6 address */
182 u_long sin6_scope_id; /* set of interfaces for a scope */
183 };
184 typedef struct sockaddr_in6 SOCKADDR_IN6, *PSOCKADDR_IN6, *LPSOCKADDR_IN6;
185
186 extern const struct in6_addr in6addr_any;
187 extern const struct in6_addr in6addr_loopback;
188 /* the above can get initialised using: */
189 #define IN6ADDR_ANY_INIT { 0 }
190 #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
191
192 /* Described in RFC 2292, but not in 2553 */
193 /* int IN6_ARE_ADDR_EQUAL(const struct in6_addr * a, const struct in6_addr * b) */
194 #define IN6_ARE_ADDR_EQUAL(a, b) \
195 (memcmp ((void*)(a), (void*)(b), sizeof (struct in6_addr)) == 0)
196
197
198 /* Address Testing Macros
199
200 These macro functions all take const struct in6_addr* as arg.
201 Static inlines would allow type checking, but RFC 2553 says they
202 macros.
203 NB: These are written specifically for little endian host */
204
205 #define IN6_IS_ADDR_UNSPECIFIED(_addr) \
206 ( (((const u_long *)(_addr))[0] == 0) \
207 && (((const u_long *)(_addr))[1] == 0) \
208 && (((const u_long *)(_addr))[2] == 0) \
209 && (((const u_long *)(_addr))[3] == 0))
210
211 #define IN6_IS_ADDR_LOOPBACK(_addr) \
212 ( (((const u_long *)(_addr))[0] == 0) \
213 && (((const u_long *)(_addr))[1] == 0) \
214 && (((const u_long *)(_addr))[2] == 0) \
215 && (((const u_long *)(_addr))[3] == 0x01000000)) /* Note byte order reversed */
216 /* (((const u_long *)(_addr))[3] == ntohl(1)) */
217
218 #define IN6_IS_ADDR_MULTICAST(_addr) (((const u_char *) (_addr))[0] == 0xff)
219
220 #define IN6_IS_ADDR_LINKLOCAL(_addr) \
221 ( (((const u_char *)(_addr))[0] == 0xfe) \
222 && ((((const u_char *)(_addr))[1] & 0xc0) == 0x80))
223
224 #define IN6_IS_ADDR_SITELOCAL(_addr) \
225 ( (((const u_char *)(_addr))[0] == 0xfe) \
226 && ((((const u_char *)(_addr))[1] & 0xc0) == 0xc0))
227
228 #define IN6_IS_ADDR_V4MAPPED(_addr) \
229 ( (((const u_long *)(_addr))[0] == 0) \
230 && (((const u_long *)(_addr))[1] == 0) \
231 && (((const u_long *)(_addr))[2] == 0xffff0000)) /* Note byte order reversed */
232 /* (((const u_long *)(_addr))[2] == ntohl(0x0000ffff))) */
233
234 #define IN6_IS_ADDR_V4COMPAT(_addr) \
235 ( (((const u_long *)(_addr))[0] == 0) \
236 && (((const u_long *)(_addr))[1] == 0) \
237 && (((const u_long *)(_addr))[2] == 0) \
238 && (((const u_long *)(_addr))[3] != 0) \
239 && (((const u_long *)(_addr))[3] != 0x01000000)) /* Note byte order reversed */
240 /* (ntohl (((const u_long *)(_addr))[3]) > 1 ) */
241
242
243 #define IN6_IS_ADDR_MC_NODELOCAL(_addr) \
244 ( IN6_IS_ADDR_MULTICAST(_addr) \
245 && ((((const u_char *)(_addr))[1] & 0xf) == 0x1))
246
247 #define IN6_IS_ADDR_MC_LINKLOCAL(_addr) \
248 ( IN6_IS_ADDR_MULTICAST (_addr) \
249 && ((((const u_char *)(_addr))[1] & 0xf) == 0x2))
250
251 #define IN6_IS_ADDR_MC_SITELOCAL(_addr) \
252 ( IN6_IS_ADDR_MULTICAST(_addr) \
253 && ((((const u_char *)(_addr))[1] & 0xf) == 0x5))
254
255 #define IN6_IS_ADDR_MC_ORGLOCAL(_addr) \
256 ( IN6_IS_ADDR_MULTICAST(_addr) \
257 && ((((const u_char *)(_addr))[1] & 0xf) == 0x8))
258
259 #define IN6_IS_ADDR_MC_GLOBAL(_addr) \
260 ( IN6_IS_ADDR_MULTICAST(_addr) \
261 && ((((const u_char *)(_addr))[1] & 0xf) == 0xe))
262
263
264 typedef int socklen_t;
265
266 struct ipv6_mreq {
267 struct in6_addr ipv6mr_multiaddr;
268 unsigned int ipv6mr_interface;
269 };
270 typedef struct ipv6_mreq IPV6_MREG;
271
272 struct in6_pktinfo {
273 IN6_ADDR ipi6_addr;
274 UINT ipi6_ifindex;
275 };
276 typedef struct in6_pktinfo IN6_PKTINFO;
277
278 struct addrinfo {
279 int ai_flags;
280 int ai_family;
281 int ai_socktype;
282 int ai_protocol;
283 size_t ai_addrlen;
284 char *ai_canonname;
285 struct sockaddr *ai_addr;
286 struct addrinfo *ai_next;
287 };
288
289 void WSAAPI freeaddrinfo (struct addrinfo*);
290 int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
291 struct addrinfo**);
292
293 #define GAI_STRERROR_BUFFER_SIZE 1024
294
295 static __inline char*
296 gai_strerrorA(int ecode)
297 {
298 static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
299
300 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
301 NULL,
302 ecode,
303 MAKELANGID(LANG_NEUTRAL,
304 SUBLANG_DEFAULT),
305 (LPSTR)buff,
306 GAI_STRERROR_BUFFER_SIZE,
307 NULL);
308
309 return buff;
310 }
311
312 static __inline WCHAR*
313 gai_strerrorW(int ecode)
314 {
315 static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
316
317 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
318 NULL,
319 ecode,
320 MAKELANGID(LANG_NEUTRAL,
321 SUBLANG_DEFAULT),
322 (LPWSTR)buff,
323 GAI_STRERROR_BUFFER_SIZE,
324 NULL);
325
326 return buff;
327 }
328
329 #ifdef UNICODE
330 #define gai_strerror gai_strerrorW
331 #else
332 #define gai_strerror gai_strerrorA
333 #endif /* UNICODE */
334
335 int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
336 char*,DWORD,int);
337
338
339 /* Some older IPv4/IPv6 compatability stuff */
340
341 /* This struct lacks sin6_scope_id; retained for use in sockaddr_gen */
342 struct sockaddr_in6_old {
343 short sin6_family;
344 u_short sin6_port;
345 u_long sin6_flowinfo;
346 struct in6_addr sin6_addr;
347 };
348
349 typedef union sockaddr_gen{
350 struct sockaddr Address;
351 struct sockaddr_in AddressIn;
352 struct sockaddr_in6_old AddressIn6;
353 } sockaddr_gen;
354
355
356 typedef struct _INTERFACE_INFO {
357 u_long iiFlags;
358 sockaddr_gen iiAddress;
359 sockaddr_gen iiBroadcastAddress;
360 sockaddr_gen iiNetmask;
361 } INTERFACE_INFO, *LPINTERFACE_INFO;
362
363 /*
364 The definition above can cause problems on NT4,prior to sp4.
365 To workaround, include the following struct and typedef and
366 #define INTERFACE_INFO OLD_INTERFACE_INFO
367 See: FIX: WSAIoctl SIO_GET_INTERFACE_LIST Option Problem
368 (Q181520) in MSDN KB.
369
370 The old definition causes problems on newer NT and on XP.
371
372 typedef struct _OLD_INTERFACE_INFO {
373 u_long iiFlags;
374 struct sockaddr iiAddress;
375 struct sockaddr iiBroadcastAddress;
376 struct sockaddr iiNetmask;
377 } OLD_INTERFACE_INFO;
378 */
379
380 #ifdef __cplusplus
381 }
382 #endif
383
384 #endif /* _WS2TCPIP_H */