getnameinfo

getnameinfo translates a socket address to a node name and service location, all of which are defined as in getaddrinfo.

Syntax

Copy
int WSAAPI getnameinfo(
    const struct sockaddr FAR *sa,
    socklen_t salen,
    char FAR *host,
    DWORD hostlen,
    char FAR *serv,
    DWORD servlen,
    int flags
);

Parameters

sa

A pointer to a socket address structure to be translated.

salen

A size of the socket address structure pointed at by sa.

host

A pointer to a zero-terminated ASCII string containing the host name.

hostlen

The length of the buffer pointed to by the node parameter, in bytes. The caller must provide a buffer large enough to hold the host name, including terminating null characters. A value of zero indicates the caller does not want to receive the string provided in host.

serv

A pointer to a zero-terminated ASCII string containing the service name associated with the port number.

servlen

The length of the buffer pointed to by the serv parameter, in bytes. The caller must provide a large buffer enough to hold the service name, including terminating null characters. A zero value indicates the caller does not want to receive the string provided in serv.

flags

The flags argument modifies the behavior of getnameinfo as follows:

Flag Description

NI_NUMERICHOST

If set, then the numeric form of the hostname is returned.

NI_NUMERICSERV

If set, then the service address is returned in numeric form, for example by its port number.

Return Value

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

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

Error Code Description
WSATRY_AGAIN

The name could not be resolved at this time. 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 name does not resolve for the supplied parameters.

WSANO_RECOVERY

A non-recoverable error occurred.

Requirements

Minimum supported version Header Library

eRTOS 1.0 SDK

Ws2tcpip.h RtTcpipApi.lib