ws2tcpip.h
来自「本源码是vc环境下的usb程序」· C头文件 代码 · 共 772 行 · 第 1/2 页
H
772 行
#define IFF_LOOPBACK 0x00000004 /* this is loopback interface */
#define IFF_POINTTOPOINT 0x00000008 /*this is point-to-point interface*/
#define IFF_MULTICAST 0x00000010 /* multicast is supported */
// structure for IP_PKTINFO option
//
typedef struct in_pktinfo {
IN_ADDR ipi_addr; // destination IPv4 address
UINT ipi_ifindex; // received interface index
} IN_PKTINFO;
C_ASSERT(sizeof(IN_PKTINFO) == 8);
// structure for IPV6_PKTINFO option
//
typedef struct in6_pktinfo {
IN6_ADDR ipi6_addr; // destination IPv6 address
UINT ipi6_ifindex; // received interface index
} IN6_PKTINFO;
C_ASSERT(sizeof(IN6_PKTINFO) == 20);
/* Error codes from getaddrinfo() */
#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
//
// DCR_FIX: EAI_NODATA remove or fix
//
// EAI_NODATA was removed from rfc2553bis
// need to find out from the authors why and
// determine the error for "no records of this type"
// temporarily, we'll keep #define to avoid changing
// code that could change back; use NONAME
//
#define EAI_NODATA EAI_NONAME
/* Structure used in getaddrinfo() call */
typedef struct addrinfo
{
int ai_flags; // AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
int ai_family; // PF_xxx
int ai_socktype; // SOCK_xxx
int ai_protocol; // 0 or IPPROTO_xxx for IPv4 and IPv6
size_t ai_addrlen; // Length of ai_addr
char * ai_canonname; // Canonical name for nodename
struct sockaddr * ai_addr; // Binary address
struct addrinfo * ai_next; // Next structure in linked list
}
ADDRINFOA, *PADDRINFOA;
typedef struct addrinfoW
{
int ai_flags; // AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
int ai_family; // PF_xxx
int ai_socktype; // SOCK_xxx
int ai_protocol; // 0 or IPPROTO_xxx for IPv4 and IPv6
size_t ai_addrlen; // Length of ai_addr
PWSTR ai_canonname; // Canonical name for nodename
struct sockaddr * ai_addr; // Binary address
struct addrinfoW * ai_next; // Next structure in linked list
}
ADDRINFOW, *PADDRINFOW;
// Switchable definition for GetAddrInfo()
#ifdef UNICODE
typedef ADDRINFOW ADDRINFOT, *PADDRINFOT;
#else
typedef ADDRINFOA ADDRINFOT, *PADDRINFOT;
#endif
// RFC standard definition for getaddrinfo()
typedef ADDRINFOA ADDRINFO, FAR * LPADDRINFO;
/* Flags used in "hints" argument to getaddrinfo() */
#define AI_PASSIVE 0x1 /* Socket address will be used in bind() call */
#define AI_CANONNAME 0x2 /* Return canonical name in first ai_canonname */
#define AI_NUMERICHOST 0x4 /* Nodename must be a numeric address string */
#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 (_WIN32_WINNT >= 0x0502)
WINSOCK_API_LINKAGE
int
WSAAPI
GetAddrInfoW(
IN PCWSTR pNodeName,
IN PCWSTR pServiceName,
IN const ADDRINFOW * pHints,
OUT PADDRINFOW * ppResult
);
#define GetAddrInfoA getaddrinfo
#ifdef UNICODE
#define GetAddrInfo GetAddrInfoW
#else
#define GetAddrInfo GetAddrInfoA
#endif
#endif
#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
);
typedef
int
(WSAAPI * LPFN_GETADDRINFOW)(
IN PCWSTR pNodeName,
IN PCWSTR pServiceName,
IN const ADDRINFOW * pHints,
OUT PADDRINFOW * ppResult
);
#define LPFN_GETADDRINFOA LPFN_GETADDRINFO
#ifdef UNICODE
#define LPFN_GETADDRINFOT LPFN_GETADDRINFOW
#else
#define LPFN_GETADDRINFOT LPFN_GETADDRINFOA
#endif
#endif
WINSOCK_API_LINKAGE
void
WSAAPI
freeaddrinfo(
IN LPADDRINFO pAddrInfo
);
#if (_WIN32_WINNT >= 0x0502)
WINSOCK_API_LINKAGE
void
WSAAPI
FreeAddrInfoW(
IN PADDRINFOW pAddrInfo
);
#define FreeAddrInfoA freeaddrinfo
#ifdef UNICODE
#define FreeAddrInfo FreeAddrInfoW
#else
#define FreeAddrInfo FreeAddrInfoA
#endif
#endif
#if INCL_WINSOCK_API_TYPEDEFS
typedef
void
(WSAAPI * LPFN_FREEADDRINFO)(
IN struct addrinfo FAR * ai
);
typedef
void
(WSAAPI * LPFN_FREEADDRINFOW)(
IN PADDRINFOW * pAddrInfo
);
#define LPFN_FREEADDRINFOA LPFN_FREEADDRINFO
#ifdef UNICODE
#define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOW
#else
#define LPFN_FREEADDRINFOT LPFN_FREEADDRINFOA
#endif
#endif
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 (_WIN32_WINNT >= 0x0502)
WINSOCK_API_LINKAGE
INT
WSAAPI
GetNameInfoW(
IN const SOCKADDR * pSockaddr,
IN socklen_t SockaddrLength,
OUT PWCHAR pNodeBuffer,
IN DWORD NodeBufferSize,
OUT PWCHAR pServiceBuffer,
IN DWORD ServiceBufferSize,
IN INT Flags
);
#define GetNameInfoA getnameinfo
#ifdef UNICODE
#define GetNameInfo GetNameInfoW
#else
#define GetNameInfo GetNameInfoA
#endif
#endif
#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
);
typedef
INT
(WSAAPI * LPFN_GETNAMEINFOW)(
IN const SOCKADDR * pSockaddr,
IN socklen_t SockaddrLength,
OUT PWCHAR pNodeBuffer,
IN DWORD NodeBufferSize,
OUT PWCHAR pServiceBuffer,
IN DWORD ServiceBufferSize,
IN INT Flags
);
#define LPFN_GETNAMEINFOA LPFN_GETNAMEINFO
#ifdef UNICODE
#define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOW
#else
#define LPFN_GETNAMEINFOT LPFN_GETNAMEINFOA
#endif
#endif
#if INCL_WINSOCK_API_PROTOTYPES
#ifdef UNICODE
#define gai_strerror gai_strerrorW
#else
#define gai_strerror gai_strerrorA
#endif /* UNICODE */
// WARNING: The gai_strerror inline functions below use static buffers,
// and hence are not thread-safe. We'll use buffers long enough to hold
// 1k characters. Any system error messages longer than this will be
// returned as empty strings. However 1k should work for the error codes
// used by getaddrinfo().
#define GAI_STRERROR_BUFFER_SIZE 1024
WS2TCPIP_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
|FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
WS2TCPIP_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
|FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
#endif /* INCL_WINSOCK_API_PROTOTYPES */
#define NI_MAXHOST 1025 /* Max size of a fully-qualified domain name */
#define NI_MAXSERV 32 /* Max size of a service name */
//
// Maximum length of address literals (potentially including a port number)
// generated by any address-to-string conversion routine. This length can
// be used when declaring buffers used with getnameinfo, WSAAddressToString,
// inet_ntoa, etc. We just provide one define, rather than one per api,
// to avoid confusion.
//
// The totals are derived from the following data:
// 15: IPv4 address
// 45: IPv6 address including embedded IPv4 address
// 11: Scope Id
// 2: Brackets around IPv6 address when port is present
// 6: Port (including colon)
// 1: Terminating null byte
//
#define INET_ADDRSTRLEN 22
#define INET6_ADDRSTRLEN 65
/* Flags for getnameinfo() */
#define NI_NOFQDN 0x01 /* Only return nodename portion for local hosts */
#define NI_NUMERICHOST 0x02 /* Return numeric form of the host's address */
#define NI_NAMEREQD 0x04 /* Error if the host's name not in DNS */
#define NI_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */
#define NI_DGRAM 0x10 /* Service is a datagram service */
#ifdef __cplusplus
}
#endif
//
// Unless the build environment is explicitly targeting only
// platforms that include built-in getaddrinfo() support, include
// the backwards-compatibility version of the relevant APIs.
//
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)
#include <wspiapi.h>
#endif
#endif /* _WS2TCPIP_H_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?