类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
struct addrinfo hints;
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = PF_INET;
请问addrinfo是不是linux或是win下的库函数有的,如果是
是什么里面的,望高手指点
网友回答:
addrinfo
The addrinfo structure is used by the getaddrinfo function to hold host address information.
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;
Members
ai_flags
Flags that indicate options used in the getaddrinfo function. See AI_PASSIVE, AI_CANONNAME, and AI_NUMERICHOST.
ai_family
Protocol family, such as PF_INET.
ai_socktype
Socket type, such as SOCK_RAW, SOCK_STREAM, or SOCK_DGRAM.
ai_protocol
Protocol, such as IPPROTO_TCP or IPPROTO_UDP. For protocols other than IPv4 and IPv6, set ai_protocol to zero.
ai_addrlen
Length of the ai_addr member, in bytes.
ai_canonname
Canonical name for the host.
ai_addr
Pointer to a sockaddr structure.
ai_next
Pointer to the next structure in a linked list. This parameter is set to NULL in the last addrinfo structure of a linked list.
Example Code
The following example demonstrates the use of the addrinfo structure.
//--------------------------------
// Declare and initialize variables.
char* ip = "127.0.0.1";
char* port = "27015";
struct addrinfo aiHints;
struct addrinfo *aiList = NULL;
int retVal;
//--------------------------------
// Setup the hints address info structure
// which is passed to the getaddrinfo() function
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;
//--------------------------------
// Call getaddrinfo(). If the call succeeds,
// the aiList variable will hold a linked list
// of addrinfo structures containing response
// information about the host
if ((retVal = getaddrinfo(ip, port, &aiHints, &aiList)) != 0) {
printf("getaddrinfo() failed.\n");
}
Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header: Declared in Ws2tcpip.h; include wspiapi.h for Windows 95/98/Me, Windows 2000 and Windows NT.
See Also