2001-04-29 08:32:26 +04:00
|
|
|
.\" $NetBSD: getnameinfo.3,v 1.13 2001/04/29 04:32:26 itojun Exp $
|
2001-01-05 16:40:28 +03:00
|
|
|
.\" $KAME: getnameinfo.3,v 1.20 2001/01/05 13:37:37 itojun Exp $
|
2000-05-11 07:08:06 +04:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.\" Copyright (c) 1983, 1987, 1991, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
|
|
|
|
.\"
|
|
|
|
.Dd May 25, 1995
|
|
|
|
.Dt GETNAMEINFO 3
|
2000-01-17 11:33:45 +03:00
|
|
|
.Os
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh NAME
|
|
|
|
.Nm getnameinfo
|
|
|
|
.Nd address-to-nodename translation in protocol-independent manner
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-03 17:58:31 +04:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh SYNOPSIS
|
2000-01-07 04:49:42 +03:00
|
|
|
.Fd #include <sys/types.h>
|
1999-07-01 22:23:53 +04:00
|
|
|
.Fd #include <sys/socket.h>
|
|
|
|
.Fd #include <netdb.h>
|
|
|
|
.Ft int
|
2000-06-04 12:52:21 +04:00
|
|
|
.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" \
|
1999-07-01 22:23:53 +04:00
|
|
|
"char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags"
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn getnameinfo
|
|
|
|
function is defined for protocol-independent address-to-nodename translation.
|
|
|
|
Its functionality is a reverse conversion of
|
|
|
|
.Xr getaddrinfo 3 ,
|
|
|
|
and implements similar functionality with
|
2000-08-10 02:52:49 +04:00
|
|
|
.Xr gethostbyaddr 3
|
|
|
|
and
|
2000-01-17 11:33:45 +03:00
|
|
|
.Xr getservbyport 3
|
1999-07-01 22:23:53 +04:00
|
|
|
in more sophisticated manner.
|
|
|
|
.Pp
|
|
|
|
This function looks up an IP address and port number provided by the
|
|
|
|
caller in the DNS and system-specific database, and returns text
|
|
|
|
strings for both in buffers provided by the caller.
|
|
|
|
The function indicates successful completion by a zero return value;
|
|
|
|
a non-zero return value indicates failure.
|
|
|
|
.Pp
|
|
|
|
The first argument,
|
|
|
|
.Fa sa ,
|
|
|
|
points to either a
|
1999-12-13 17:18:31 +03:00
|
|
|
.Li sockaddr_in
|
1999-07-01 22:23:53 +04:00
|
|
|
structure (for IPv4) or a
|
1999-12-13 17:18:31 +03:00
|
|
|
.Li sockaddr_in6
|
1999-07-01 22:23:53 +04:00
|
|
|
structure (for IPv6) that holds the IP address and port number.
|
|
|
|
The
|
|
|
|
.Fa salen
|
|
|
|
argument gives the length of the
|
1999-12-13 17:18:31 +03:00
|
|
|
.Li sockaddr_in
|
1999-07-01 22:23:53 +04:00
|
|
|
or
|
1999-12-13 17:18:31 +03:00
|
|
|
.Li sockaddr_in6
|
1999-07-01 22:23:53 +04:00
|
|
|
structure.
|
|
|
|
.Pp
|
|
|
|
The function returns the nodename associated with the IP address in
|
|
|
|
the buffer pointed to by the
|
|
|
|
.Fa host
|
|
|
|
argument.
|
|
|
|
The caller provides the size of this buffer via the
|
|
|
|
.Fa hostlen
|
|
|
|
argument.
|
|
|
|
The service name associated with the port number is returned in the buffer
|
|
|
|
pointed to by
|
|
|
|
.Fa serv ,
|
|
|
|
and the
|
|
|
|
.Fa servlen
|
|
|
|
argument gives the length of this buffer.
|
|
|
|
The caller specifies not to return either string by providing a zero
|
|
|
|
value for the
|
|
|
|
.Fa hostlen
|
|
|
|
or
|
|
|
|
.Fa servlen
|
|
|
|
arguments.
|
|
|
|
Otherwise, the caller must provide buffers large enough to hold the
|
2000-06-23 00:32:28 +04:00
|
|
|
nodename and the service name, including the terminating null characters.
|
1999-07-01 22:23:53 +04:00
|
|
|
.Pp
|
|
|
|
Unfortunately most systems do not provide constants that specify the
|
|
|
|
maximum size of either a fully-qualified domain name or a service name.
|
|
|
|
Therefore to aid the application in allocating buffers for these two
|
|
|
|
returned strings the following constants are defined in
|
1999-12-13 17:18:31 +03:00
|
|
|
.Aq Pa netdb.h :
|
1999-07-01 22:23:53 +04:00
|
|
|
.Bd -literal -offset
|
|
|
|
#define NI_MAXHOST 1025
|
|
|
|
#define NI_MAXSERV 32
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The first value is actually defined as the constant
|
|
|
|
.Dv MAXDNAME
|
|
|
|
in recent versions of BIND's
|
1999-12-13 17:18:31 +03:00
|
|
|
.Aq Pa arpa/nameser.h
|
1999-07-01 22:23:53 +04:00
|
|
|
header
|
|
|
|
.Po
|
|
|
|
older versions of BIND define this constant to be 256
|
|
|
|
.Pc
|
|
|
|
and the second is a guess based on the services listed in the current
|
|
|
|
Assigned Numbers RFC.
|
|
|
|
.Pp
|
|
|
|
The final argument is a
|
|
|
|
.Fa flag
|
|
|
|
that changes 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.
|
|
|
|
If the flag bit
|
|
|
|
.Dv NI_NOFQDN
|
|
|
|
is set, only the nodename portion of the FQDN is returned for local hosts.
|
|
|
|
.Pp
|
|
|
|
If the
|
|
|
|
.Fa flag
|
|
|
|
bit
|
|
|
|
.Dv NI_NUMERICHOST
|
|
|
|
is set, or if the host's name cannot be located in the DNS,
|
|
|
|
the numeric form of the host's address is returned instead of its name
|
|
|
|
.Po
|
|
|
|
e.g., by calling
|
|
|
|
.Fn inet_ntop
|
2000-01-17 11:33:45 +03:00
|
|
|
instead of
|
2001-01-05 16:40:28 +03:00
|
|
|
.Fn gethostbyaddr
|
1999-07-01 22:23:53 +04:00
|
|
|
.Pc .
|
|
|
|
If the
|
|
|
|
.Fa flag
|
|
|
|
bit
|
|
|
|
.Dv NI_NAMEREQD
|
|
|
|
is set, an error is returned if the host's name cannot be located in the DNS.
|
|
|
|
.Pp
|
|
|
|
If the flag bit
|
|
|
|
.Dv NI_NUMERICSERV
|
|
|
|
is set, the numeric form of the service address is returned
|
|
|
|
.Pq e.g., its port number
|
|
|
|
instead of its name.
|
|
|
|
The two
|
|
|
|
.Dv NI_NUMERICxxx
|
|
|
|
flags are required to support the
|
1999-12-13 17:18:31 +03:00
|
|
|
.Fl n
|
1999-07-01 22:23:53 +04:00
|
|
|
flag that many commands provide.
|
|
|
|
.Pp
|
|
|
|
A fifth flag bit,
|
|
|
|
.Dv NI_DGRAM ,
|
|
|
|
specifies that the service is a datagram service, and causes
|
|
|
|
.Fn getservbyport
|
1999-12-13 17:18:31 +03:00
|
|
|
to be called with a second argument of
|
|
|
|
.Dq udp
|
|
|
|
instead of its default of
|
|
|
|
.Dq tcp .
|
1999-07-01 22:23:53 +04:00
|
|
|
This is required for the few ports (512-514)
|
|
|
|
that have different services for UDP and TCP.
|
|
|
|
.Pp
|
|
|
|
These
|
|
|
|
.Dv NI_xxx
|
|
|
|
flags are defined in
|
1999-12-13 17:18:31 +03:00
|
|
|
.Aq Pa netdb.h .
|
|
|
|
.\"
|
2001-01-05 16:40:28 +03:00
|
|
|
.Ss Extension for scoped IPv6 address
|
1999-12-13 17:18:31 +03:00
|
|
|
The implementation allows experimental numeric IPv6 address notation with
|
|
|
|
scope identifier.
|
|
|
|
IPv6 link-local address will appear as string like
|
2000-05-11 07:08:06 +04:00
|
|
|
.Dq Li fe80::1%ne0 ,
|
1999-12-13 17:18:31 +03:00
|
|
|
if
|
|
|
|
.Dv NI_WITHSCOPEID
|
|
|
|
bit is enabled in
|
|
|
|
.Ar flags
|
|
|
|
argument.
|
|
|
|
Refer to
|
|
|
|
.Xr getaddrinfo 3
|
|
|
|
for the notation.
|
|
|
|
.\"
|
2000-01-17 11:33:45 +03:00
|
|
|
.Sh EXAMPLES
|
|
|
|
The following code tries to get numeric hostname, and service name,
|
|
|
|
for given socket address.
|
|
|
|
Observe that there is no hardcoded reference to particular address family.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
struct sockaddr *sa; /* input */
|
|
|
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
|
|
|
|
|
|
|
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
|
2000-06-23 00:32:28 +04:00
|
|
|
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) {
|
2000-01-17 11:33:45 +03:00
|
|
|
errx(1, "could not get numeric hostname");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
printf("host=%s, serv=%s\\n", hbuf, sbuf);
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The following version checks if the socket address has reverse address mapping.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
struct sockaddr *sa; /* input */
|
|
|
|
char hbuf[NI_MAXHOST];
|
|
|
|
|
|
|
|
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0,
|
2000-06-23 00:32:28 +04:00
|
|
|
NI_NAMEREQD)) {
|
2000-01-17 11:33:45 +03:00
|
|
|
errx(1, "could not resolve hostname");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
printf("host=%s\\n", hbuf);
|
|
|
|
.Ed
|
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /etc/resolv.conf -compact
|
|
|
|
.It Pa /etc/hosts
|
|
|
|
.It Pa /etc/host.conf
|
|
|
|
.It Pa /etc/resolv.conf
|
|
|
|
.El
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh DIAGNOSTICS
|
|
|
|
The function indicates successful completion by a zero return value;
|
|
|
|
a non-zero return value indicates failure.
|
2000-06-23 00:32:28 +04:00
|
|
|
Error codes are as below:
|
|
|
|
.Bl -tag -width Er
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_AGAIN
|
2000-06-23 00:32:28 +04:00
|
|
|
The name could not be resolved at this time.
|
|
|
|
Future attempts may succeed.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_BADFLAGS
|
2000-06-23 00:32:28 +04:00
|
|
|
The flags had an invalid value.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_FAIL
|
2000-06-23 00:32:28 +04:00
|
|
|
A non-recoverable error occurred.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_FAMILY
|
2000-06-23 00:32:28 +04:00
|
|
|
The address family was not recognized or the address length was invalid
|
|
|
|
for the specified family.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_MEMORY
|
2000-06-23 00:32:28 +04:00
|
|
|
There was a memory allocation failure.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_NONAME
|
2000-06-23 00:32:28 +04:00
|
|
|
The name does not resolve for the supplied parameters.
|
|
|
|
.Dv NI_NAMEREQD
|
|
|
|
is set and the host's name cannot be located,
|
|
|
|
or both nodename and servname were null.
|
2001-01-05 16:40:28 +03:00
|
|
|
.It Dv EAI_SYSTEM
|
2000-06-23 00:32:28 +04:00
|
|
|
A system error occurred.
|
|
|
|
The error code can be found in errno.
|
|
|
|
.El
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr getaddrinfo 3 ,
|
|
|
|
.Xr gethostbyaddr 3 ,
|
|
|
|
.Xr getservbyport 3 ,
|
|
|
|
.Xr hosts 5 ,
|
|
|
|
.Xr services 5 ,
|
|
|
|
.Xr hostname 7 ,
|
|
|
|
.Xr named 8
|
|
|
|
.Pp
|
1999-12-13 17:18:31 +03:00
|
|
|
.Rs
|
|
|
|
.%A R. Gilligan
|
|
|
|
.%A S. Thomson
|
|
|
|
.%A J. Bound
|
|
|
|
.%A W. Stevens
|
|
|
|
.%T Basic Socket Interface Extensions for IPv6
|
|
|
|
.%R RFC2553
|
|
|
|
.%D March 1999
|
|
|
|
.Re
|
2000-01-17 11:33:45 +03:00
|
|
|
.Rs
|
|
|
|
.%A Tatsuya Jinmei
|
|
|
|
.%A Atsushi Onoe
|
|
|
|
.%T "An Extension of Format for IPv6 Scoped Addresses"
|
|
|
|
.%R internet draft
|
2000-08-10 02:52:49 +04:00
|
|
|
.%N draft-ietf-ipngwg-scopedaddr-format-02.txt
|
2000-01-17 11:33:45 +03:00
|
|
|
.%O work in progress material
|
|
|
|
.Re
|
2000-06-23 00:32:28 +04:00
|
|
|
.Rs
|
|
|
|
.%A Craig Metz
|
|
|
|
.%T Protocol Independence Using the Sockets API
|
|
|
|
.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference"
|
|
|
|
.%D June 2000
|
|
|
|
.Re
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
2001-04-29 08:32:26 +04:00
|
|
|
.Fn getnameinfo
|
1999-07-01 22:23:53 +04:00
|
|
|
function is defined IEEE POSIX 1003.1g draft specification,
|
1999-12-13 17:18:31 +03:00
|
|
|
and documented in
|
|
|
|
.Dq Basic Socket Interface Extensions for IPv6
|
2000-06-30 20:48:47 +04:00
|
|
|
.Pq RFC2553 .
|
1999-12-13 17:18:31 +03:00
|
|
|
.\"
|
1999-07-01 22:23:53 +04:00
|
|
|
.Sh BUGS
|
2000-08-10 02:52:49 +04:00
|
|
|
The current implementation is not thread-safe.
|
|
|
|
.Pp
|
1999-07-01 22:23:53 +04:00
|
|
|
The text was shamelessly copied from RFC2553.
|