[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

getnameinfo Subroutine

Purpose

Address-to-host name translation [given the binary address and port].

Note
This is the reverse functionality of the getaddrinfo Subroutine host-to-address translation.
Attention: This is not a POSIX (1003.1g) specified function.

Library

Library (libc.a)

Syntax

#include <sys/socket.h>
#include <netdb.h>
int
getnameinfo (sa, salen, host, hostlen, serv, servlen, flags)
const struct sockaddr *sa;
char *host;
size_t hostlen;
char *serv;
size_t servlen;
int flags;

Description

The sa parameter points to either a sockaddr_in structure (for IPv4) or a sockaddr_in6 structure (for IPv6) that holds the IP address and port number. Thesalen parameter gives the length of the sockaddr_in or sockaddr_in6 structure.

Note
A reverse lookup is performed on the IP address and port number provided in sa.

The host parameter is a buffer where the hostname associated with the IP address is copied. The hostlen parameter provides the length of this buffer. The service name associated with the port number is copied into the buffer pointed to by the serv parameter. The servlen parameter provides the length of this buffer.

The flags parameter defines flags that may be used to modify the default actions of this function. By default, the fully-qualified domain name (FQDN) for the host is looked up in DNS and returned.

NI_NOFQDN If set, return only the hostname portion of the FQDN. If cleared, return the FQDN.
NI_NUMERICHOST If set, return the numeric form of the host address. If cleared, return the name.
NI_NAMEREQD If set, return an error if the host's name cannot be determined. If cleared, return the numeric form of the host's address (as if NI_NUMERICHOST had been set).
NI_NUMERICSERV If set, return the numeric form of the desired service. If cleared, return the service name.
NI_DGRAM If set, consider the desired service to be a datagram service, (for example, call getservbyport with an argument of udp). If clear, consider the desired service to be a stream service (for example, call getserbyport with an argument of tcp).

Return Values

A zero return value indicates successful completion; a non-zero value indicates failure. If successful, the strings for hostname and service name are copied into the host and serv buffers, respectively. If either the host or service name cannot be located, the numeric form is copied into the host and serv buffers, respectively.

Related Information

getaddrinfo Subroutine, and freeaddrinfo Subroutine.

The gai_strerror Subroutine in AIX 5L Version 5.2 Technical Reference: Base Operating System and Extensions Volume 1.

Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]