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(
    const char *nodename,
    const char *servname,
    const struct addrinfo *hints,
    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 the port number of the service, in decimal form (e.g. "80" for HTTP). This may be NULL if nodename is not NULL.

hints

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

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:

NOTE: See the Remarks section for a list of unsupported values.

res

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

Return Value

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

Error codes returned by getaddrinfo are:

Error Code

Description

WSATRY_AGAIN

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

WSAEINVAL

ai_flags contains invalid flags.

WSAEAFNOSUPPORT

The requested address family is not supported.

WSA_NOT_ENOUGH_MEMORY

Memory allocation failure.

WSAHOST_NOT_FOUND

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

WSATYPE_NOT_FOUND

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

WSAESOCKTNOSUPPORT

The requested socket type is not supported.

WSANO_RECOVERY

The name server returned a permanent failure indication.

Remarks

Since the RT-TCP/IP stack does not support DNS protocol, only name-to-address translations, which don’t require dynamic name resolution, are supported.

The ai_family in the hints parameter must be one of the following values:

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

The following values for the ai_flags in the hints parameter are not supported:

If the hints parameter is not provided and set to NULL, the following defaults within the hintsparameter are used:

Requirements

Minimum Supported Version RTX64 2013
Header Ws2tcpip.h
Library RtTcpip.lib