- 论坛徽章:
- 0
|
The getaddrinfo() function performs the node name to address
translation. The nodename and servname arguments are
pointers to null-terminated strings or NULL. One or both of
these arguments must be a non-null pointer. In the normal
client scenario, both the nodename and servname are speci-
fied. In the normal server scenario, only the servname is
specified.
A non-null nodename string can be a node name or a numeric
host address string. The nodename can also be an IPv6 zone-
id in the form:
<address>%<zone-id>
The address is the literal IPv6 link-local address or host
name of the destination. The zone-id is the interface ID of
the IPv6 link used to send the packet. The zone-id can
either be a numeric value, indicating a literal zone value,
or an interface name such as hme0.
A non-null servname string can be either a service name or a
decimal port number.
The caller can optionally pass an addrinfo structure,
pointed to by the hints argument, to provide hints concern-
ing the type of socket that the caller supports.
The addrinfo structure is defined as:
struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME,
AI_NUMERICHOST, AI_NUMERICSERV
AI_V4MAPPED, AI_ALL, AI_ADDRCONFIG */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
socklen_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 */
};
In this hints structure, all members other than ai_flags,
ai_family, ai_socktype, and ai_protocol must be 0 or a null
pointer. A value of PF_UNSPEC for ai_family indicates that
the caller will accept any protocol family. A value of 0 for
ai_socktype indicates that the caller will accept any socket
type. A value of 0 for ai_protocol indicates that the
caller will accept any protocol. For example, if the caller
handles only TCP and not UDP, then the ai_socktype member of
the hints structure should be set to SOCK_STREAM when getad-
drinfo() is called. If the caller handles only IPv4 and not
IPv6, then the ai_family member of the hints structure
should be set to PF_INET when getaddrinfo() is called. If
the third argument to getaddrinfo() is a null pointer, it is
as if the caller had filled in an addrinfo structure ini-
tialized to 0 with ai_family set to PF_UNSPEC.
Upon success, a pointer to a linked list of one or more
addrinfo structures is returned through the final argument.
The caller can process each addrinfo structure in this list
by following the ai_next pointer, until a null pointer is
encountered. In each returned addrinfo structure the three
members ai_family, ai_socktype, and ai_protocol are the
corresponding arguments for a call to the socket(3SOCKET)
function. In each addrinfo structure the ai_addr member
points to a filled-in socket address structure whose length
is specified by the ai_addrlen member.
man信息太多了,贴不完,建议还是man一下 |
|