-.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.2.2.3 2001/08/17 15:42:38 ru Exp $
.\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993
.\" 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.
.\" SUCH DAMAGE.
.\"
.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
+.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.18 2007/01/09 00:28:02 imp Exp $
.\"
-.Dd May 25, 1995
+.Dd August 6, 2004
.Dt GETIPNODEBYNAME 3
.Os
.\"
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
-.Fd #include <sys/socket.h>
-.Fd #include <netdb.h>
+.In sys/types.h
+.In sys/socket.h
+.In netdb.h
.Ft "struct hostent *"
.Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num"
.Ft "struct hostent *"
.Fn freehostent "struct hostent *ptr"
.\"
.Sh DESCRIPTION
+The
.Fn getipnodebyname
and
.Fn getipnodebyaddr
The functions cover all the functionalities provided by the older ones,
and provide better interface to programmers.
The functions require additional arguments,
-.Ar af ,
+.Fa af ,
and
-.Ar flags ,
+.Fa flags ,
for specifying address family and operation mode.
The additional arguments allow programmer to get address for a nodename,
for specific address family
or
.Dv AF_INET6 ) .
The functions also require an additional pointer argument,
-.Ar error_num
+.Fa error_num
to return the appropriate error code,
to support thread safe error code returns.
.Pp
For
.Fn getipnodebyname ,
the
-.Ar name
+.Fa name
argument can be either a node name or a numeric address
string
(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
The
-.Ar af
+.Fa af
argument specifies the address family, either
.Dv AF_INET
or
.Dv AF_INET6 .
The
-.Ar flags
+.Fa flags
argument specifies the types of addresses that are searched for,
and the types of addresses that are returned.
We note that a special flags value of
.Pp
Applications desiring finer control over the types of addresses
searched for and returned, can specify other combinations of the
-.Ar flags
+.Fa flags
argument.
.Pp
A
-.Ar flags
+.Fa flags
of
.Li 0
implies a strict interpretation of the
-.Ar af
+.Fa af
argument:
.Bl -bullet
.It
If
-.Ar flags
+.Fa flags
is 0 and
-.Ar af
+.Fa af
is
.Dv AF_INET ,
then the caller wants only IPv4 addresses.
pointer.
.It
If
-.Ar flags
+.Fa flags
is 0 and if
-.Ar af
+.Fa af
is
.Li AF_INET6 ,
then the caller wants only IPv6 addresses.
.El
.Pp
Other constants can be logically-ORed into the
-.Ar flags
+.Fa flags
argument, to modify the behavior of the function.
.Bl -bullet
.It
If the
.Dv AI_V4MAPPED
flag is specified along with an
-.Ar af
+.Fa af
of
.Dv AF_INET6 ,
then the caller will accept IPv4-mapped IPv6 addresses.
The
.Dv AI_V4MAPPED
flag is ignored unless
-.Ar af
+.Fa af
equals
.Dv AF_INET6 .
.It
A query is first made for
.Li AAAA
records and if successful, the
-IPv6 addresses are returned. Another query is then made for
+IPv6 addresses are returned.
+Another query is then made for
.Li A
records and any found are returned as IPv4-mapped IPv6 addresses.
.Li h_length
-will be 16. Only if both queries fail does the function
+will be 16.
+Only if both queries fail does the function
return a
.Dv NULL
-pointer. This flag is ignored unless af equals
-AF_INET6. If both
+pointer.
+This flag is ignored unless af equals
+AF_INET6.
+If both
.Dv AI_ALL
and
.Dv AI_V4MAPPED
.Pp
For example, if the node has no IPv6 source addresses configured,
and
-.Ar af
+.Fa af
equals AF_INET6, and the node name being looked up has both
.Li AAAA
and
We noted that the
.Fn getipnodebyname
function must allow the
-.Ar name
+.Fa name
argument to be either a node name or a literal address string
(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
This saves applications from having to call
.Xr inet_pton 3
to handle literal address strings.
When the
-.Ar name
+.Fa name
argument is a literal address string,
the
-.Ar flags
+.Fa flags
argument is always ignored.
.Pp
There are four scenarios based on the type of literal address string
and the value of the
-.Ar af
+.Fa af
argument.
The two simple cases are when
-.Ar name
+.Fa name
is a dotted-decimal IPv4 address and
-.Ar af
+.Fa af
equals
.Dv AF_INET ,
or when
-.Ar name
+.Fa name
is an IPv6 hex address and
-.Ar af
+.Fa af
equals
.Dv AF_INET6 .
The members of the
returned hostent structure are:
.Li h_name
points to a copy of the
-.Ar name
+.Fa name
argument,
.Li h_aliases
is a
pointer,
.Li h_addrtype
is a copy of the
-.Ar af
+.Fa af
argument,
.Li h_length
is either 4
pointer.
.Pp
When
-.Ar name
+.Fa name
is a dotted-decimal IPv4 address and
-.Ar af
+.Fa af
equals
.Dv AF_INET6 ,
and
pointer.
.Pp
It is an error when
-.Ar name
+.Fa name
is an IPv6 hex address and
-.Ar af
+.Fa af
equals
.Dv AF_INET .
The function's return value is a
.Dv NULL
pointer and the value pointed to by
-.Ar error_num
+.Fa error_num
equals
.Dv HOST_NOT_FOUND .
.Pp
+The
.Fn getipnodebyaddr
+function
takes almost the same argument as
.Xr gethostbyaddr 3 ,
but adds a pointer to return an error number.
Additionally it takes care of IPv4-mapped IPv6 addresses,
and IPv4-compatible IPv6 addresses.
.Pp
+The
.Fn getipnodebyname
and
.Fn getipnodebyaddr
+functions
dynamically allocate the structure to be returned to the caller.
+The
.Fn freehostent
+function
reclaims memory region allocated and returned by
.Fn getipnodebyname
or
.Fn getipnodebyaddr .
.\"
.Sh FILES
-.Bl -tag -width /etc/resolv.conf -compact
+.Bl -tag -width /etc/nsswitch.conf -compact
.It Pa /etc/hosts
-.It Pa /etc/host.conf
+.\".It Pa /etc/nsswitch.conf
.It Pa /etc/resolv.conf
.El
.\"
.Sh DIAGNOSTICS
+The
.Fn getipnodebyname
and
.Fn getipnodebyaddr
+functions
returns
.Dv NULL
on errors.
The integer values pointed to by
-.Ar error_num
+.Fa error_num
may then be checked to see whether this is a temporary failure
or an invalid or unknown host.
The meanings of each error code are described in
.Xr gethostbyname 3 .
.\"
.Sh SEE ALSO
+.Xr getaddrinfo 3 ,
.Xr gethostbyaddr 3 ,
.Xr gethostbyname 3 ,
+.Xr getnameinfo 3 ,
.Xr hosts 5 ,
+.Xr nsswitch.conf 5 ,
.Xr services 5 ,
.Xr hostname 7 ,
.Xr named 8
.%D March 1999
.Re
.\"
-.Sh HISTORY
-The implementation first appeared in KAME advanced networking kit.
-.\"
.Sh STANDARDS
+The
.Fn getipnodebyname
and
.Fn getipnodebyaddr
+functions
are documented in
.Dq Basic Socket Interface Extensions for IPv6
(RFC2553).
.\"
+.Sh HISTORY
+The implementation first appeared in KAME advanced networking kit.
+.\"
.Sh BUGS
+The
.Fn getipnodebyname
and
.Fn getipnodebyaddr
+functions
do not handle scoped IPv6 address properly.
If you use these functions,
your program will not be able to handle scoped IPv6 addresses.