2 * ws2tcpip.h : TCP/IP specific extensions in Windows Sockets 2
4 * Portions Copyright (c) 1980, 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
12 #if (defined _WINSOCK_H && !defined _WINSOCK2_H)
13 #error "ws2tcpip.h is not compatable with winsock.h. Include winsock2.h instead."
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.
31 * See also: msdn kb article Q257460
32 * http://support.microsoft.com/support/kb/articles/Q257/4/60.asp
35 /* This is also defined in winsock.h; value hasn't changed */
40 * These are also be defined in winsock.h,
41 * but values have changed for WinSock2 interface
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
58 * As with BSD implementation, IPPROTO_IPV6 level socket options have
59 * same values as IPv4 counterparts.
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
71 #define IP_DEFAULT_MULTICAST_TTL 1
72 #define IP_DEFAULT_MULTICAST_LOOP 1
73 #define IP_MAX_MEMBERSHIPS 20
75 #define TCP_EXPEDITED_1122 2
77 #define UDP_NOCHECKSUM 1
79 /* INTERFACE_INFO iiFlags */
81 #define IFF_BROADCAST 2
82 #define IFF_LOOPBACK 4
83 #define IFF_POINTTOPOINT 8
84 #define IFF_MULTICAST 16
86 #define SIO_GET_INTERFACE_LIST _IOR('t', 127, u_long)
88 #define INET_ADDRSTRLEN 16
89 #define INET6_ADDRSTRLEN 46
91 /* getnameinfo constants */
92 #define NI_MAXHOST 1025
95 #define NI_NOFQDN 0x01
96 #define NI_NUMERICHOST 0x02
97 #define NI_NAMEREQD 0x04
98 #define NI_NUMERICSERV 0x08
101 /* getaddrinfo constants */
103 #define AI_CANONNAME 2
104 #define AI_NUMERICHOST 4
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
118 * ip_mreq also in winsock.h for WinSock1.1,
119 * but online msdn docs say it is defined here for WinSock2.
123 struct in_addr imr_multiaddr
;
124 struct in_addr imr_interface
;
127 struct ip_mreq_source
{
128 struct in_addr imr_multiaddr
;
129 struct in_addr imr_sourceaddr
;
130 struct in_addr imr_interface
;
134 struct in_addr imsf_multiaddr
;
135 struct in_addr imsf_interface
;
138 struct in_addr imsf_slist
[1];
141 #define IP_MSFILTER_SIZE(numsrc) \
142 (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
143 + (numsrc) * sizeof(struct in_addr))
147 /* These require XP or .NET Server or use of add-on IPv6 stacks on NT 4
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 */
164 /* s6_addr is the standard name */
165 #define s6_addr u.Byte
167 /* These are GLIBC names */
168 #define s6_addr16 u.Word
169 #define s6_addr32 u.Word
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
176 typedef struct in6_addr IN6_ADDR
, *PIN6_ADDR
, *LPIN6_ADDR
;
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 */
185 typedef struct sockaddr_in6 SOCKADDR_IN6
, *PSOCKADDR_IN6
, *LPSOCKADDR_IN6
;
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 }
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)
199 /* Address Testing Macros
201 These macro functions all take const struct in6_addr* as arg.
202 Static inlines would allow type checking, but RFC 2553 says they
204 NB: These are written specifically for little endian host */
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))
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)) */
219 #define IN6_IS_ADDR_MULTICAST(_addr) (((const u_char *) (_addr))[0] == 0xff)
221 #define IN6_IS_ADDR_LINKLOCAL(_addr) \
222 ( (((const u_char *)(_addr))[0] == 0xfe) \
223 && ((((const u_char *)(_addr))[1] & 0xc0) == 0x80))
225 #define IN6_IS_ADDR_SITELOCAL(_addr) \
226 ( (((const u_char *)(_addr))[0] == 0xfe) \
227 && ((((const u_char *)(_addr))[1] & 0xc0) == 0xc0))
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))) */
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 ) */
244 #define IN6_IS_ADDR_MC_NODELOCAL(_addr) \
245 ( IN6_IS_ADDR_MULTICAST(_addr) \
246 && ((((const u_char *)(_addr))[1] & 0xf) == 0x1))
248 #define IN6_IS_ADDR_MC_LINKLOCAL(_addr) \
249 ( IN6_IS_ADDR_MULTICAST (_addr) \
250 && ((((const u_char *)(_addr))[1] & 0xf) == 0x2))
252 #define IN6_IS_ADDR_MC_SITELOCAL(_addr) \
253 ( IN6_IS_ADDR_MULTICAST(_addr) \
254 && ((((const u_char *)(_addr))[1] & 0xf) == 0x5))
256 #define IN6_IS_ADDR_MC_ORGLOCAL(_addr) \
257 ( IN6_IS_ADDR_MULTICAST(_addr) \
258 && ((((const u_char *)(_addr))[1] & 0xf) == 0x8))
260 #define IN6_IS_ADDR_MC_GLOBAL(_addr) \
261 ( IN6_IS_ADDR_MULTICAST(_addr) \
262 && ((((const u_char *)(_addr))[1] & 0xf) == 0xe))
265 typedef int socklen_t
;
268 struct in6_addr ipv6mr_multiaddr
;
269 unsigned int ipv6mr_interface
;
271 typedef struct ipv6_mreq IPV6_MREG
;
277 typedef struct in6_pktinfo IN6_PKTINFO
;
279 typedef struct addrinfo
287 struct sockaddr
*ai_addr
;
288 struct addrinfo
*ai_next
;
289 } ADDRINFOA
, *PADDRINFOA
;
291 typedef struct addrinfoW
299 struct sockaddr
*ai_addr
;
300 struct addrinfoW
*ai_next
;
301 } ADDRINFOW
, *PADDRINFOW
;
304 typedef ADDRINFOW ADDRINFOT
,*PADDRINFOT
;
306 typedef ADDRINFOA ADDRINFOT
,*PADDRINFOT
;
309 typedef ADDRINFOA ADDRINFO
, FAR
*LPADDRINFO
;
311 void WSAAPI
freeaddrinfo (struct addrinfo
*);
312 int WSAAPI
getaddrinfo (const char*,const char*,const struct addrinfo
*,
315 #define GAI_STRERROR_BUFFER_SIZE 1024
317 static __inline
char*
318 gai_strerrorA(int ecode
)
320 static char buff
[GAI_STRERROR_BUFFER_SIZE
+ 1];
322 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_MAX_WIDTH_MASK
,
325 MAKELANGID(LANG_NEUTRAL
,
328 GAI_STRERROR_BUFFER_SIZE
,
334 static __inline WCHAR
*
335 gai_strerrorW(int ecode
)
337 static WCHAR buff
[GAI_STRERROR_BUFFER_SIZE
+ 1];
339 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_MAX_WIDTH_MASK
,
342 MAKELANGID(LANG_NEUTRAL
,
345 GAI_STRERROR_BUFFER_SIZE
,
352 #define gai_strerror gai_strerrorW
354 #define gai_strerror gai_strerrorA
357 int WSAAPI
getnameinfo(const struct sockaddr
*,socklen_t
,char*,DWORD
,
360 #if (_WIN32_WINNT >= 0x0502)
361 INT WSAAPI
GetNameInfoW(const SOCKADDR
*,socklen_t
,PWCHAR
,DWORD
,PWCHAR
,DWORD
,INT
);
362 #define GetNameInfoA getnameinfo
365 #define GetNameInfo GetNameInfoW
367 #define GetNameInfo GetNameInfoA
370 #endif /* (_WIN32_WINNT >= 0x0502) */
372 /* Some older IPv4/IPv6 compatability stuff */
374 /* This struct lacks sin6_scope_id; retained for use in sockaddr_gen */
375 struct sockaddr_in6_old
{
378 u_long sin6_flowinfo
;
379 struct in6_addr sin6_addr
;
382 typedef union sockaddr_gen
{
383 struct sockaddr Address
;
384 struct sockaddr_in AddressIn
;
385 struct sockaddr_in6_old AddressIn6
;
389 typedef struct _INTERFACE_INFO
{
391 sockaddr_gen iiAddress
;
392 sockaddr_gen iiBroadcastAddress
;
393 sockaddr_gen iiNetmask
;
394 } INTERFACE_INFO
, *LPINTERFACE_INFO
;
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.
403 The old definition causes problems on newer NT and on XP.
405 typedef struct _OLD_INTERFACE_INFO {
407 struct sockaddr iiAddress;
408 struct sockaddr iiBroadcastAddress;
409 struct sockaddr iiNetmask;
410 } OLD_INTERFACE_INFO;
417 #endif /* _WS2TCPIP_H */