Hostname-to-service name translation [given the binary address and port].
Note: This is the reverse functionality of getaddrinfo (getaddrinfo Subroutine): hostname-to-address translation.
Attention: This is not a POSIX (1003.1g) specified function.
Library (libc.a)
#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;
The first argument, sa, points to either a sockaddr_in structure (for IPv4) or a sockaddr_in6 structure (for IPv6) that holds the IP address and port number. The argument, salen, 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 argument, host, copies the hostname associated with the IP address into a buffer. The argument, hostlen, provides the length of this buffer. The service name associated with the port number is copied into the buffer pointed to by the argument serv. The argument, servlen, provides the length of this buffer.
The final argument 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 the DNS and returned.
NI_NOFQDN | If set, return only the hostname portion of the FQDN. If clear, return the FQDN. |
NI_NUMERICHOST | If set, return the numeric form of the host address. If clear, return the name. |
NI_NAMEREQD | If set, return an error if the host's name cannot be determined. If clear, 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 clear, return the service name. |
NI_DGRAM | If set, consider the desired service to be a datagram service, (i.e., call getservbyport with an argument of udp). If clear, consider the desired service to be a stream service (i.e., call getserbyport with an argument of tcp). |
If successful, the strings for hostname and service are copied into host and serv, respectively. If unsuccessful, zero values for either hostlen or servlen will suppress the associated lookup; in this case no data is copied into the applicable buffer.
The getaddrinfo (getaddrinfo Subroutine) subroutine, freeaddrinfo (freeaddrinfo Subroutine) subroutine, and gai_strerror (gai_strerror Subroutine) subroutine.
Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.