getaddrinfo

getaddrinfo translates the name of a service location, for instance host name and/or a service name, and returns a set of socket addresses and associated information to be used in creating a socket to which specified service can be addressed.

Syntax

int WSAAPI getaddrinfo(
    __in const char *nodename,
    __in const char *servname,
    __in const struct addrinfo *hints,
    __out struct addrinfo **res
);

Parameters

nodename

A pointer to a zero terminated ASCII string containing a host (node) name or a numeric host address string. The numeric host address string is a dotted-decimal IPv4 address or an IPv6 hex address. If nodename is not null, the requested service location is named by nodename; otherwise, the requested service location is local to the caller.

servname

A pointer to a zero-terminated ASCII string containing either a service name or port number.

hints

A pointer to an addrinfo structure that provides hints about the type of socket the caller supports.

The ai_flags field to which the hints parameter points shall be set to zero or be bitwise-inclusive OR of one or more of the following values:

res

A pointer to a linked list of one or more addrinfo structures containing response information about the host.

Return Values

0 (zero) if the function succeeds, a non-zero, positive value if the function fails

Error codes returned by getaddrinfo can also map to any of following:

Error Code

Description

EAI_AGAIN

The name server returned a temporary failure indication. Try again later.

EAI_BADFLAGS

ai_flags contains invalid flags.

EAI_FAMILY

The requested address family is not supported.

EAI_MEMORY

Memory allocation failure.

EAI_NONAME

The node or service is not known. This error is also returned if both node and service are NULL.

EAI_SERVICE

The requested service is not available for the requested socket type. It may be available through another socket type.

EAI_SOCKTYPE

The requested socket type is not supported.

EAI_FAIL

The name server returned a permanent failure indication.

Remarks

freeaddrinfo must be called when the application finishes using the pointer or a memory leak will occur.

IntervalZero.com | Support | Give Feedback