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