#ifndef _TPIPV6_
#define _TPIPV6_
#ifdef _MSC_VER
#define TPIPV6_INLINE __inline
#else
#define TPIPV6_INLINE extern inline
#endif
#ifdef __cplusplus
#define TPIPV6_EXTERN extern "C"
#else
#define TPIPV6_EXTERN extern
#endif
#ifdef _WINSOCK2API_
#ifndef IPPROTO_IPV6
#define IPPROTO_IPV6 41
typedef unsigned __int64 u_int64;
#define _SS_MAXSIZE 128
#define _SS_ALIGNSIZE (sizeof(__int64))
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (short))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (short) + _SS_PAD1SIZE \
+ _SS_ALIGNSIZE))
struct sockaddr_storage {
short ss_family; char __ss_pad1[_SS_PAD1SIZE]; __int64 __ss_align; char __ss_pad2[_SS_PAD2SIZE]; };
typedef struct sockaddr_storage SOCKADDR_STORAGE;
typedef struct sockaddr_storage *PSOCKADDR_STORAGE;
typedef struct sockaddr_storage FAR *LPSOCKADDR_STORAGE;
#endif
#endif
#ifdef _WS2TCPIP_H_
#ifndef IPV6_JOIN_GROUP
#define in6_addr in_addr6
#define SS_PORT(ssp) (((struct sockaddr_in*)(ssp))->sin_port)
#define IN6ADDR_ANY_INIT { 0 }
#define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
const struct in6_addr in6addr_any;
const struct in6_addr in6addr_loopback;
TPIPV6_INLINE int
IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b)
{
return (memcmp(a, b, sizeof(struct in6_addr)) == 0);
}
TPIPV6_INLINE int
IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *a)
{
return IN6_ADDR_EQUAL(a, &in6addr_any);
}
TPIPV6_INLINE int
IN6_IS_ADDR_LOOPBACK(const struct in6_addr *a)
{
return IN6_ADDR_EQUAL(a, &in6addr_loopback);
}
TPIPV6_INLINE int
IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
{
return (a->s6_addr[0] == 0xff);
}
TPIPV6_INLINE int
IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
{
return ((a->s6_addr[0] == 0xfe) &&
((a->s6_addr[1] & 0xc0) == 0x80));
}
TPIPV6_INLINE int
IN6_IS_ADDR_SITELOCAL(const struct in6_addr *a)
{
return ((a->s6_addr[0] == 0xfe) &&
((a->s6_addr[1] & 0xc0) == 0xc0));
}
TPIPV6_INLINE int
IN6_IS_ADDR_V4MAPPED(const struct in6_addr *a)
{
return ((a->s6_addr[0] == 0) &&
(a->s6_addr[1] == 0) &&
(a->s6_addr[2] == 0) &&
(a->s6_addr[3] == 0) &&
(a->s6_addr[4] == 0) &&
(a->s6_addr[5] == 0) &&
(a->s6_addr[6] == 0) &&
(a->s6_addr[7] == 0) &&
(a->s6_addr[8] == 0) &&
(a->s6_addr[9] == 0) &&
(a->s6_addr[10] == 0xff) &&
(a->s6_addr[11] == 0xff));
}
TPIPV6_INLINE int
IN6_IS_ADDR_V4COMPAT(const struct in6_addr *a)
{
return ((a->s6_addr[0] == 0) &&
(a->s6_addr[1] == 0) &&
(a->s6_addr[2] == 0) &&
(a->s6_addr[3] == 0) &&
(a->s6_addr[4] == 0) &&
(a->s6_addr[5] == 0) &&
(a->s6_addr[6] == 0) &&
(a->s6_addr[7] == 0) &&
(a->s6_addr[8] == 0) &&
(a->s6_addr[9] == 0) &&
(a->s6_addr[10] == 0) &&
(a->s6_addr[11] == 0) &&
!((a->s6_addr[12] == 0) &&
(a->s6_addr[13] == 0) &&
(a->s6_addr[14] == 0) &&
((a->s6_addr[15] == 0) ||
(a->s6_addr[15] == 1))));
}
TPIPV6_INLINE int
IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *a)
{
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
}
TPIPV6_INLINE int
IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *a)
{
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
}
TPIPV6_INLINE int
IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *a)
{
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
}
TPIPV6_INLINE int
IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *a)
{
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
}
TPIPV6_INLINE int
IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *a)
{
return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
}
typedef struct ipv6_mreq {
struct in6_addr ipv6mr_multiaddr; unsigned int ipv6mr_interface; } IPV6_MREQ;
#define IPV6_UNICAST_HOPS 4
#define IPV6_MULTICAST_IF 9
#define IPV6_MULTICAST_HOPS 10
#define IPV6_MULTICAST_LOOP 11
#define IPV6_ADD_MEMBERSHIP 12
#define IPV6_DROP_MEMBERSHIP 13
#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
#define UDP_CHECKSUM_COVERAGE 20
#define EAI_AGAIN WSATRY_AGAIN
#define EAI_BADFLAGS WSAEINVAL
#define EAI_FAIL WSANO_RECOVERY
#define EAI_FAMILY WSAEAFNOSUPPORT
#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
#define EAI_NODATA WSANO_DATA
#define EAI_NONAME WSAHOST_NOT_FOUND
#define EAI_SERVICE WSATYPE_NOT_FOUND
#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
typedef struct addrinfo {
int ai_flags; int ai_family; int ai_socktype; int ai_protocol; size_t ai_addrlen; char *ai_canonname; struct sockaddr *ai_addr; struct addrinfo *ai_next; } ADDRINFO, FAR * LPADDRINFO;
#define AI_PASSIVE 0x1
#define AI_CANONNAME 0x2
#define AI_NUMERICHOST 0x4
#ifdef __cplusplus
extern "C" {
#endif
WINSOCK_API_LINKAGE
int
WSAAPI
getaddrinfo(
IN const char FAR * nodename,
IN const char FAR * servname,
IN const struct addrinfo FAR * hints,
OUT struct addrinfo FAR * FAR * res
);
#if INCL_WINSOCK_API_TYPEDEFS
typedef
int
(WSAAPI * LPFN_GETADDRINFO)(
IN const char FAR * nodename,
IN const char FAR * servname,
IN const struct addrinfo FAR * hints,
OUT struct addrinfo FAR * FAR * res
);
#endif
WINSOCK_API_LINKAGE
void
WSAAPI
freeaddrinfo(
IN struct addrinfo FAR * ai
);
#if INCL_WINSOCK_API_TYPEDEFS
typedef
void
(WSAAPI * LPFN_FREEADDRINFO)(
IN struct addrinfo FAR * ai
);
#endif
#ifdef UNICODE
#define gai_strerror gai_strerrorW
#else
#define gai_strerror gai_strerrorA
#endif
#define GAI_STRERROR_BUFFER_SIZE 1024
TPIPV6_INLINE
char *
gai_strerrorA(
IN int ecode)
{
DWORD dwMsgLen;
static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
TPIPV6_INLINE
WCHAR *
gai_strerrorW(
IN int ecode
)
{
DWORD dwMsgLen;
static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
typedef int socklen_t;
WINSOCK_API_LINKAGE
int
WSAAPI
getnameinfo(
IN const struct sockaddr FAR * sa,
IN socklen_t salen,
OUT char FAR * host,
IN DWORD hostlen,
OUT char FAR * serv,
IN DWORD servlen,
IN int flags
);
#if INCL_WINSOCK_API_TYPEDEFS
typedef
int
(WSAAPI * LPFN_GETNAMEINFO)(
IN const struct sockaddr FAR * sa,
IN socklen_t salen,
OUT char FAR * host,
IN DWORD hostlen,
OUT char FAR * serv,
IN DWORD servlen,
IN int flags
);
#endif
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
#define NI_NOFQDN 0x01
#define NI_NUMERICHOST 0x02
#define NI_NAMEREQD 0x04
#define NI_NUMERICSERV 0x08
#define NI_DGRAM 0x10
#ifdef __cplusplus
}
#endif
#endif
#endif
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)
#include "wspiapi.h"
#endif
#endif