getaddrinfo

getaddrinfo translates the name of a service location, e.g., hostname 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

Copy
int WSAAPI getaddrinfo(
    [in, optional]    const char *nodename,
    [in, optional]    const char *servname,
    [in, optional]    const struct addrinfo *hints,
    [out]             struct addrinfo **res
);

Parameters

[in, optional] 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.

[in, optional] 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.

[in, optional] hints

A pointer to an addrinfo structure that provides hints about the socket type 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 the unsupported values.

[out] res

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

Return Value

If the function succeeds, it returns 0 (zero). If the function fails, it returns a non-zero positive value.

Possible error codes:

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 fails.

WSAHOST_NOT_FOUND

The node or service is unknown. 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 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 Header Library

wRTOS 1.0 SDK

ws2tcpip.h

RttcpipApi.lib