getnameinfo(3N)


getnameinfo -- get name information related to an IP address and port number

Synopsis

cc [options] file -lsocket -lnsl
#include  <sys/socket.h>
#include  <netdb.h>

int getnameinfo(const struct sockaddr *sa, size_t addrlen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);

Description

getnameinfo looks up a specified IP address (IPv4 or IPv6) and port number and returns text strings for each in the buffers provided.

Use the first argument sa to specify a pointer to a sockaddr_in or sockaddr_in6 structure that holds the IP address and port number you want to look up. Use the addrlen argument to specify the size of the structure pointed to by sa.


NOTE: Use the sockaddr_in structure for IPv4 addresses, or sockaddr_in6 for IPv6 addresses.

Use the host argument to specify a pointer to a buffer that can be used to store the returned hostname. Use the hostlen argument to specify the size of the buffer pointed to by host. If you specify a zero value for hostlen, getnameinfo will not attempt to return a hostname.

Use the serv argument to specify a pointer to a buffer that can be used to store the returned service name. Use the servlen argument to specify the size of the buffer pointed to by serv. If you specify a zero value for servlen, getnameinfo will not attempt to return a service name.


NOTE: The sizes of the buffers pointed to by host and serv must be large enough to hold the fully qualified domain hostname and service name respectively. The sizes should also allow for the terminating null characters at the end of each string. The constants NI_MAXHOST and NI_MAXSERV defined in <netdb.h> may be used as suitable buffer sizes for these names.

The flags argument changes the default actions of getnameinfo. The following values may be ORed into its value:


NI_DGRAM
If set, this specifies that the service is a datagram service, and causes getservbyport(3N) to be called with its second argument set to udp instead of the default value tcp. This is useful for ports such as 512-514 which have different services for UDP and TCP.

NI_NAMEREQD
If set, return an error if the host's name cannot be located in the DNS.

NI_NOFQDN
If set, return only the hostname portion of the fully-qualified domain name (FQDN) for local hosts. By default, the FQDN for the host is looked up in the DNS and returned.

NI_NUMERICHOST
If set, or if the host's name cannot be located in the DNS, return the numeric form of the host's address instead of its name (for example, by calling inet_ntop(3N) instead of gethostbyaddr(3N)).

This flag is required to support the -n option that many commands provide.


NI_NUMERICSERV
If set, return the numeric form of the service address (for example, its port number) instead of its name.

This flag is required to support the -n option that many commands provide.

Return values

getnameinfo returns 0 on successful completion, or non-zero for failure.

References

gethostent(3N), getaddrinfo(3N)

RFC 2133

Notices

In UnixWare 7 the sockaddr structure has been modified to support variable length sockets. The net result of this modification is that the family member has been shortened to 8 bits and a new 8-bit member inserted before it called len. For more information on the new sockaddr structures, see: inet(7tcp).
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004