 |
Index for Section 3 |
|
 |
Alphabetical listing for G |
|
 |
Bottom of page |
|
getnameinfo(3)
NAME
getnameinfo - Get a node name and service name for an address and port
number
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <netdb.h>
int getnameinfo(
const struct sockaddr *sa,
socklen_t salen,
char *host,
size_t *hostlen,
char *serv,
size_t servlen,
int flags);
PARAMETERS
sa Points either to a sockaddr_in structure (for IPv4) or to a
sockaddr_in6 structure (for IPv6) that holds the IP address and
port number.
salen Specifies the length of either the sockaddr_in structure or the
sockaddr_in6 structure.
host Points to a buffer in which to receive the null-terminated
network node name or alias corresponding to the address contained
in sa.
hostlen Specifies the length of the host buffer. A value of zero
instructs the routine not to return a host name.
serv Points to a buffer in which to receive the null-terminated
network service name associated with the port number contained in
sa.
servlen Specifies the length of the serv buffer. A value of zero
instructs the routine not to return a service name.
flags Specifies to change the routine's the default actions. By
default, the routine searches for the fully-qualified domain name
of the node in the hosts database and returns it. See the
"Description" section for additional flags.
DESCRIPTION
The getnameinfo() routine looks up an IP address and port number in a
sockaddr structure specified by sa and returns node name and service name
text strings in the buffers pointed to by the host and serv parameters,
respectively.
The application must provide buffers large enough to hold the fully-
qualified domain name and the service name, including the terminating null
characters. To assist in initializing the buffers, the following constants
are defined in <netdb.h>:
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
Flag Bits
The following flag bits are defined:
NI_NOFQDN
If set, the getnameinfo routine returns the node name portion of the
fully-qualified domain name for local hosts.
NI_NUMERICHOST
If set, or if the host's name cannot be located in the hosts database,
the routine returns the numeric form of the host's address is instead
of its name. For example, by calling inet_ntop() instead of
gethostbyaddr().
NI_NAMEREQD
If set, the routine returns an error if the host's name cannot be
located in the hosts database.
NI_NUMERICSERV
If set, the routine returns the numeric form (port number) of the
service address instead of its name.
NI_DGRAM
If set, specifies that the service is a datagram service. The
getnameinfo routine calls getservbyport() with the proto parameter set
to udp instead of tcp (the default). This is required for the few
ports (512-514) that have different services for UDP and TCP.
The two NI_NUMERIC* flags are required to support the -n flag that many
commands provide. All flags are defined in <netdb.h> header file.
RETURN VALUES
Upon successful completion, the getnameinfo() function returns 0 (zero).
Upon failure, it returns a non-zero value.
FILES
/etc/hosts
The Internet network hostname database. Each record in the file
occupies a single line and has three fields consisting of the
host address, official hostname, and aliases.
/etc/resolv.conf
The resolver configuration file.
/etc/svc.conf
The database service selection configuration file.
RELATED INFORMATION
Functions: endhostent(3), freeaddrinfo(3), gai_strerror(3), getaddrinfo(3),
gethostbyaddr(3), sethostent(3).
Files: hostname(5), resolv.conf(4), svc.conf(4).
Networks: bind_intro(7), nis_intro(7).
 |
Index for Section 3 |
|
 |
Alphabetical listing for G |
|
 |
Top of page |
|