getnameinfo

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

Syntax

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

Parameters

sa

A pointer to a socket address structure to be translated.

salen

Size of the socket address structure pointed 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

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

flags

The flags argument modifies the behaviour 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 Values

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

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

Error Code

Description

EAI_AGAIN

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

EAI_FAIL

A non-recoverable error occurred.

IntervalZero.com | Support | Give Feedback