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 */
163 /* s6_addr is the standard name */
164 #define s6_addr _S6_un._S6_u8
166 /* These are GLIBC names */
167 #define s6_addr16 _S6_un._S6_u16
168 #define s6_addr32 _S6_un._S6_u16
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
175 typedef struct in6_addr IN6_ADDR
, *PIN6_ADDR
, *LPIN6_ADDR
;
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 */
184 typedef struct sockaddr_in6 SOCKADDR_IN6
, *PSOCKADDR_IN6
, *LPSOCKADDR_IN6
;
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 }
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)
198 /* Address Testing Macros
200 These macro functions all take const struct in6_addr* as arg.
201 Static inlines would allow type checking, but RFC 2553 says they
203 NB: These are written specifically for little endian host */
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))
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)) */
218 #define IN6_IS_ADDR_MULTICAST(_addr) (((const u_char *) (_addr))[0] == 0xff)
220 #define IN6_IS_ADDR_LINKLOCAL(_addr) \
221 ( (((const u_char *)(_addr))[0] == 0xfe) \
222 && ((((const u_char *)(_addr))[1] & 0xc0) == 0x80))
224 #define IN6_IS_ADDR_SITELOCAL(_addr) \
225 ( (((const u_char *)(_addr))[0] == 0xfe) \
226 && ((((const u_char *)(_addr))[1] & 0xc0) == 0xc0))
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))) */
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 ) */
243 #define IN6_IS_ADDR_MC_NODELOCAL(_addr) \
244 ( IN6_IS_ADDR_MULTICAST(_addr) \
245 && ((((const u_char *)(_addr))[1] & 0xf) == 0x1))
247 #define IN6_IS_ADDR_MC_LINKLOCAL(_addr) \
248 ( IN6_IS_ADDR_MULTICAST (_addr) \
249 && ((((const u_char *)(_addr))[1] & 0xf) == 0x2))
251 #define IN6_IS_ADDR_MC_SITELOCAL(_addr) \
252 ( IN6_IS_ADDR_MULTICAST(_addr) \
253 && ((((const u_char *)(_addr))[1] & 0xf) == 0x5))
255 #define IN6_IS_ADDR_MC_ORGLOCAL(_addr) \
256 ( IN6_IS_ADDR_MULTICAST(_addr) \
257 && ((((const u_char *)(_addr))[1] & 0xf) == 0x8))
259 #define IN6_IS_ADDR_MC_GLOBAL(_addr) \
260 ( IN6_IS_ADDR_MULTICAST(_addr) \
261 && ((((const u_char *)(_addr))[1] & 0xf) == 0xe))
264 typedef int socklen_t
;
267 struct in6_addr ipv6mr_multiaddr
;
268 unsigned int ipv6mr_interface
;
270 typedef struct ipv6_mreq IPV6_MREG
;
276 typedef struct in6_pktinfo IN6_PKTINFO
;
285 struct sockaddr
*ai_addr
;
286 struct addrinfo
*ai_next
;
289 void WSAAPI
freeaddrinfo (struct addrinfo
*);
290 int WSAAPI
getaddrinfo (const char*,const char*,const struct addrinfo
*,
293 #define GAI_STRERROR_BUFFER_SIZE 1024
295 static __inline
char*
296 gai_strerrorA(int ecode
)
298 static char buff
[GAI_STRERROR_BUFFER_SIZE
+ 1];
300 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_MAX_WIDTH_MASK
,
303 MAKELANGID(LANG_NEUTRAL
,
306 GAI_STRERROR_BUFFER_SIZE
,
312 static __inline WCHAR
*
313 gai_strerrorW(int ecode
)
315 static WCHAR buff
[GAI_STRERROR_BUFFER_SIZE
+ 1];
317 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_MAX_WIDTH_MASK
,
320 MAKELANGID(LANG_NEUTRAL
,
323 GAI_STRERROR_BUFFER_SIZE
,
330 #define gai_strerror gai_strerrorW
332 #define gai_strerror gai_strerrorA
335 int WSAAPI
getnameinfo(const struct sockaddr
*,socklen_t
,char*,DWORD
,
339 /* Some older IPv4/IPv6 compatability stuff */
341 /* This struct lacks sin6_scope_id; retained for use in sockaddr_gen */
342 struct sockaddr_in6_old
{
345 u_long sin6_flowinfo
;
346 struct in6_addr sin6_addr
;
349 typedef union sockaddr_gen
{
350 struct sockaddr Address
;
351 struct sockaddr_in AddressIn
;
352 struct sockaddr_in6_old AddressIn6
;
356 typedef struct _INTERFACE_INFO
{
358 sockaddr_gen iiAddress
;
359 sockaddr_gen iiBroadcastAddress
;
360 sockaddr_gen iiNetmask
;
361 } INTERFACE_INFO
, *LPINTERFACE_INFO
;
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.
370 The old definition causes problems on newer NT and on XP.
372 typedef struct _OLD_INTERFACE_INFO {
374 struct sockaddr iiAddress;
375 struct sockaddr iiBroadcastAddress;
376 struct sockaddr iiNetmask;
377 } OLD_INTERFACE_INFO;
384 #endif /* _WS2TCPIP_H */