00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _TPIPV6_
00017 #define _TPIPV6_
00018
00019 #ifdef _MSC_VER
00020 #define TPIPV6_INLINE __inline
00021 #else
00022 #define TPIPV6_INLINE extern inline
00023 #endif
00024
00025 #ifdef __cplusplus
00026 #define TPIPV6_EXTERN extern "C"
00027 #else
00028 #define TPIPV6_EXTERN extern
00029 #endif
00030
00031 #ifdef _WINSOCK2API_
00032
00033
00034 #ifndef IPPROTO_IPV6
00035
00036 #define IPPROTO_IPV6 41
00037
00038 typedef unsigned __int64 u_int64;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define _SS_MAXSIZE 128 // Maximum size.
00049 #define _SS_ALIGNSIZE (sizeof(__int64)) // Desired alignment.
00050
00051
00052
00053
00054 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (short))
00055 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (short) + _SS_PAD1SIZE \
00056 + _SS_ALIGNSIZE))
00057
00058 struct sockaddr_storage {
00059 short ss_family;
00060 char __ss_pad1[_SS_PAD1SIZE];
00061
00062
00063
00064 __int64 __ss_align;
00065 char __ss_pad2[_SS_PAD2SIZE];
00066
00067
00068
00069 };
00070
00071 typedef struct sockaddr_storage SOCKADDR_STORAGE;
00072 typedef struct sockaddr_storage *PSOCKADDR_STORAGE;
00073 typedef struct sockaddr_storage FAR *LPSOCKADDR_STORAGE;
00074
00075 #endif
00076 #endif
00077
00078 #ifdef _WS2TCPIP_H_
00079
00080
00081 #ifndef IPV6_JOIN_GROUP
00082
00083 #define in6_addr in_addr6
00084
00085
00086 #define SS_PORT(ssp) (((struct sockaddr_in*)(ssp))->sin_port)
00087
00088 #define IN6ADDR_ANY_INIT { 0 }
00089 #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
00090
00091 TPIPV6_EXTERN const struct in6_addr in6addr_any;
00092 TPIPV6_EXTERN const struct in6_addr in6addr_loopback;
00093
00094 TPIPV6_INLINE int
00095 IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b)
00096 {
00097 return (memcmp(a, b, sizeof(struct in6_addr)) == 0);
00098 }
00099
00100 TPIPV6_INLINE int
00101 IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *a)
00102 {
00103 return IN6_ADDR_EQUAL(a, &in6addr_any);
00104 }
00105
00106 TPIPV6_INLINE int
00107 IN6_IS_ADDR_LOOPBACK(const struct in6_addr *a)
00108 {
00109 return IN6_ADDR_EQUAL(a, &in6addr_loopback);
00110 }
00111
00112 TPIPV6_INLINE int
00113 IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
00114 {
00115 return (a->s6_addr[0] == 0xff);
00116 }
00117
00118 TPIPV6_INLINE int
00119 IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
00120 {
00121 return ((a->s6_addr[0] == 0xfe) &&
00122 ((a->s6_addr[1] & 0xc0) == 0x80));
00123 }
00124
00125 TPIPV6_INLINE int
00126 IN6_IS_ADDR_SITELOCAL(const struct in6_addr *a)
00127 {
00128 return ((a->s6_addr[0] == 0xfe) &&
00129 ((a->s6_addr[1] & 0xc0) == 0xc0));
00130 }
00131
00132 TPIPV6_INLINE int
00133 IN6_IS_ADDR_V4MAPPED(const struct in6_addr *a)
00134 {
00135 return ((a->s6_addr[0] == 0) &&
00136 (a->s6_addr[1] == 0) &&
00137 (a->s6_addr[2] == 0) &&
00138 (a->s6_addr[3] == 0) &&
00139 (a->s6_addr[4] == 0) &&
00140 (a->s6_addr[5] == 0) &&
00141 (a->s6_addr[6] == 0) &&
00142 (a->s6_addr[7] == 0) &&
00143 (a->s6_addr[8] == 0) &&
00144 (a->s6_addr[9] == 0) &&
00145 (a->s6_addr[10] == 0xff) &&
00146 (a->s6_addr[11] == 0xff));
00147 }
00148
00149 TPIPV6_INLINE int
00150 IN6_IS_ADDR_V4COMPAT(const struct in6_addr *a)
00151 {
00152 return ((a->s6_addr[0] == 0) &&
00153 (a->s6_addr[1] == 0) &&
00154 (a->s6_addr[2] == 0) &&
00155 (a->s6_addr[3] == 0) &&
00156 (a->s6_addr[4] == 0) &&
00157 (a->s6_addr[5] == 0) &&
00158 (a->s6_addr[6] == 0) &&
00159 (a->s6_addr[7] == 0) &&
00160 (a->s6_addr[8] == 0) &&
00161 (a->s6_addr[9] == 0) &&
00162 (a->s6_addr[10] == 0) &&
00163 (a->s6_addr[11] == 0) &&
00164 !((a->s6_addr[12] == 0) &&
00165 (a->s6_addr[13] == 0) &&
00166 (a->s6_addr[14] == 0) &&
00167 ((a->s6_addr[15] == 0) ||
00168 (a->s6_addr[15] == 1))));
00169 }
00170
00171 TPIPV6_INLINE int
00172 IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *a)
00173 {
00174 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
00175 }
00176
00177 TPIPV6_INLINE int
00178 IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *a)
00179 {
00180 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
00181 }
00182
00183 TPIPV6_INLINE int
00184 IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *a)
00185 {
00186 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
00187 }
00188
00189 TPIPV6_INLINE int
00190 IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *a)
00191 {
00192 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
00193 }
00194
00195 TPIPV6_INLINE int
00196 IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *a)
00197 {
00198 return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
00199 }
00200
00201
00202
00203 typedef struct ipv6_mreq {
00204 struct in6_addr ipv6mr_multiaddr;
00205 unsigned int ipv6mr_interface;
00206 } IPV6_MREQ;
00207
00208
00209
00210
00211 #define IPV6_UNICAST_HOPS 4 // Set/get IP unicast hop limit.
00212 #define IPV6_MULTICAST_IF 9 // Set/get IP multicast interface.
00213 #define IPV6_MULTICAST_HOPS 10 // Set/get IP multicast ttl.
00214 #define IPV6_MULTICAST_LOOP 11 // Set/get IP multicast loopback.
00215 #define IPV6_ADD_MEMBERSHIP 12 // Add an IP group membership.
00216 #define IPV6_DROP_MEMBERSHIP 13 // Drop an IP group membership.
00217 #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
00218 #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
00219
00220
00221
00222
00223 #define UDP_CHECKSUM_COVERAGE 20 // Set/get UDP-Lite checksum coverage.
00224
00225
00226
00227
00228 #define EAI_AGAIN WSATRY_AGAIN
00229 #define EAI_BADFLAGS WSAEINVAL
00230 #define EAI_FAIL WSANO_RECOVERY
00231 #define EAI_FAMILY WSAEAFNOSUPPORT
00232 #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
00233 #define EAI_NODATA WSANO_DATA
00234 #define EAI_NONAME WSAHOST_NOT_FOUND
00235 #define EAI_SERVICE WSATYPE_NOT_FOUND
00236 #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
00237
00238
00239
00240
00241 typedef struct addrinfo {
00242 int ai_flags;
00243 int ai_family;
00244 int ai_socktype;
00245 int ai_protocol;
00246 size_t ai_addrlen;
00247 char *ai_canonname;
00248 struct sockaddr *ai_addr;
00249 struct addrinfo *ai_next;
00250 } ADDRINFO, FAR * LPADDRINFO;
00251
00252
00253
00254
00255 #define AI_PASSIVE 0x1 // Socket address will be used in bind() call.
00256 #define AI_CANONNAME 0x2 // Return canonical name in first ai_canonname.
00257 #define AI_NUMERICHOST 0x4 // Nodename must be a numeric address string.
00258
00259 #ifdef __cplusplus
00260 extern "C" {
00261 #endif
00262
00263 WINSOCK_API_LINKAGE
00264 int
00265 WSAAPI
00266 getaddrinfo(
00267 IN const char FAR * nodename,
00268 IN const char FAR * servname,
00269 IN const struct addrinfo FAR * hints,
00270 OUT struct addrinfo FAR * FAR * res
00271 );
00272
00273 #if INCL_WINSOCK_API_TYPEDEFS
00274 typedef
00275 int
00276 (WSAAPI * LPFN_GETADDRINFO)(
00277 IN const char FAR * nodename,
00278 IN const char FAR * servname,
00279 IN const struct addrinfo FAR * hints,
00280 OUT struct addrinfo FAR * FAR * res
00281 );
00282 #endif
00283
00284 WINSOCK_API_LINKAGE
00285 void
00286 WSAAPI
00287 freeaddrinfo(
00288 IN struct addrinfo FAR * ai
00289 );
00290
00291 #if INCL_WINSOCK_API_TYPEDEFS
00292 typedef
00293 void
00294 (WSAAPI * LPFN_FREEADDRINFO)(
00295 IN struct addrinfo FAR * ai
00296 );
00297 #endif
00298
00299 #ifdef UNICODE
00300 #define gai_strerror gai_strerrorW
00301 #else
00302 #define gai_strerror gai_strerrorA
00303 #endif
00304
00305
00306
00307
00308
00309
00310 #define GAI_STRERROR_BUFFER_SIZE 1024
00311
00312 TPIPV6_INLINE
00313 char *
00314 gai_strerrorA(
00315 IN int ecode)
00316 {
00317 DWORD dwMsgLen;
00318 static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
00319
00320 dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
00321 |FORMAT_MESSAGE_IGNORE_INSERTS,
00322 NULL,
00323 ecode,
00324 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00325 (LPSTR)buff,
00326 GAI_STRERROR_BUFFER_SIZE,
00327 NULL);
00328
00329 return buff;
00330 }
00331
00332 TPIPV6_INLINE
00333 WCHAR *
00334 gai_strerrorW(
00335 IN int ecode
00336 )
00337 {
00338 DWORD dwMsgLen;
00339 static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
00340
00341 dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
00342 |FORMAT_MESSAGE_IGNORE_INSERTS,
00343 NULL,
00344 ecode,
00345 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00346 (LPWSTR)buff,
00347 GAI_STRERROR_BUFFER_SIZE,
00348 NULL);
00349
00350 return buff;
00351 }
00352
00353 typedef int socklen_t;
00354
00355 WINSOCK_API_LINKAGE
00356 int
00357 WSAAPI
00358 getnameinfo(
00359 IN const struct sockaddr FAR * sa,
00360 IN socklen_t salen,
00361 OUT char FAR * host,
00362 IN DWORD hostlen,
00363 OUT char FAR * serv,
00364 IN DWORD servlen,
00365 IN int flags
00366 );
00367
00368 #if INCL_WINSOCK_API_TYPEDEFS
00369 typedef
00370 int
00371 (WSAAPI * LPFN_GETNAMEINFO)(
00372 IN const struct sockaddr FAR * sa,
00373 IN socklen_t salen,
00374 OUT char FAR * host,
00375 IN DWORD hostlen,
00376 OUT char FAR * serv,
00377 IN DWORD servlen,
00378 IN int flags
00379 );
00380 #endif
00381
00382 #define NI_MAXHOST 1025 // Max size of a fully-qualified domain name.
00383 #define NI_MAXSERV 32 // Max size of a service name.
00384
00385
00386
00387
00388 #define NI_NOFQDN 0x01 // Only return nodename portion for local hosts.
00389 #define NI_NUMERICHOST 0x02 // Return numeric form of the host's address.
00390 #define NI_NAMEREQD 0x04 // Error if the host's name not in DNS.
00391 #define NI_NUMERICSERV 0x08 // Return numeric form of the service (port #).
00392 #define NI_DGRAM 0x10 // Service is a datagram service.
00393
00394 #ifdef __cplusplus
00395 }
00396 #endif
00397
00398 #endif
00399 #endif
00400
00401
00402
00403
00404
00405
00406 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)
00407 #include <wspiapi.h>
00408 #endif
00409
00410 #endif
00411