1996-08-30 19:40:05 +00:00
|
|
|
.\" Copyright (c) 1983, 1987, 1991, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
1996-08-29 22:13:00 +00:00
|
|
|
.\"
|
1996-08-30 19:40:05 +00:00
|
|
|
.\" 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.
|
1996-08-29 22:13:00 +00:00
|
|
|
.\"
|
1996-08-30 19:40:05 +00:00
|
|
|
.\" 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.
|
1996-08-29 22:13:00 +00:00
|
|
|
.\"
|
1997-06-18 06:26:13 +00:00
|
|
|
.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1996-08-30 19:40:05 +00:00
|
|
|
.\"
|
1996-11-01 06:29:00 +00:00
|
|
|
.Dd May 25, 1995
|
1996-08-30 19:40:05 +00:00
|
|
|
.Dt GETHOSTBYNAME 3
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm gethostbyname ,
|
1996-11-01 06:29:00 +00:00
|
|
|
.Nm gethostbyname2 ,
|
1996-08-30 19:40:05 +00:00
|
|
|
.Nm gethostbyaddr ,
|
|
|
|
.Nm gethostent ,
|
|
|
|
.Nm sethostent ,
|
|
|
|
.Nm endhostent ,
|
1996-11-01 06:29:00 +00:00
|
|
|
.Nm herror ,
|
|
|
|
.Nm hstrerror
|
1996-08-30 19:40:05 +00:00
|
|
|
.Nd get network host entry
|
2000-04-21 09:42:15 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In netdb.h
|
2001-01-12 15:46:56 +00:00
|
|
|
.Vt extern int h_errno ;
|
1996-08-30 19:40:05 +00:00
|
|
|
.Ft struct hostent *
|
1996-10-08 22:30:08 +00:00
|
|
|
.Fn gethostbyname "const char *name"
|
1996-08-30 19:40:05 +00:00
|
|
|
.Ft struct hostent *
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname2 "const char *name" "int af"
|
|
|
|
.Ft struct hostent *
|
2006-05-12 15:37:23 +00:00
|
|
|
.Fn gethostbyaddr "const void *addr" "socklen_t len" "int type"
|
1996-08-30 19:40:05 +00:00
|
|
|
.Ft struct hostent *
|
|
|
|
.Fn gethostent void
|
1997-03-19 00:32:42 +00:00
|
|
|
.Ft void
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn sethostent "int stayopen"
|
1997-03-19 00:32:42 +00:00
|
|
|
.Ft void
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn endhostent void
|
1997-03-19 00:32:42 +00:00
|
|
|
.Ft void
|
1996-10-08 22:30:08 +00:00
|
|
|
.Fn herror "const char *string"
|
1996-11-01 06:29:00 +00:00
|
|
|
.Ft const char *
|
|
|
|
.Fn hstrerror "int err"
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh DESCRIPTION
|
2001-08-08 11:05:47 +00:00
|
|
|
.Bf -symbolic
|
|
|
|
The
|
|
|
|
.Xr getaddrinfo 3
|
|
|
|
and
|
|
|
|
.Xr getnameinfo 3
|
|
|
|
functions are preferred over the
|
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostbyname2 ,
|
|
|
|
and
|
|
|
|
.Fn gethostbyaddr
|
|
|
|
functions.
|
|
|
|
.Ef
|
|
|
|
.Pp
|
1996-08-30 19:40:05 +00:00
|
|
|
The
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostbyname2
|
1996-08-29 22:13:00 +00:00
|
|
|
and
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn gethostbyaddr
|
|
|
|
functions
|
1996-08-29 22:13:00 +00:00
|
|
|
each return a pointer to an object with the
|
|
|
|
following structure describing an internet host
|
|
|
|
referenced by name or by address, respectively.
|
2001-02-09 19:06:25 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa name
|
2002-12-19 09:40:28 +00:00
|
|
|
argument passed to
|
2001-02-09 19:06:25 +00:00
|
|
|
.Fn gethostbyname
|
|
|
|
or
|
|
|
|
.Fn gethostbyname2
|
2001-02-10 10:51:39 +00:00
|
|
|
should point to a
|
|
|
|
.Dv NUL Ns -terminated
|
|
|
|
hostname.
|
2001-02-09 19:06:25 +00:00
|
|
|
The
|
|
|
|
.Fa addr
|
2002-12-19 09:40:28 +00:00
|
|
|
argument passed to
|
2001-02-09 19:06:25 +00:00
|
|
|
.Fn gethostbyaddr
|
|
|
|
should point to an address which is
|
|
|
|
.Fa len
|
|
|
|
bytes long,
|
|
|
|
in binary form
|
2004-07-02 23:52:20 +00:00
|
|
|
(i.e., not an IP address in human readable
|
2001-02-10 10:51:39 +00:00
|
|
|
.Tn ASCII
|
|
|
|
form).
|
2001-02-09 19:06:25 +00:00
|
|
|
The
|
|
|
|
.Fa type
|
2002-12-19 09:40:28 +00:00
|
|
|
argument specifies the address family
|
2001-02-10 10:51:39 +00:00
|
|
|
(e.g.\&
|
|
|
|
.Dv AF_INET , AF_INET6 ,
|
|
|
|
etc.) of this address.
|
2001-02-09 19:06:25 +00:00
|
|
|
.Pp
|
|
|
|
The structure returned contains either the information obtained from the name
|
|
|
|
server,
|
1996-08-30 19:40:05 +00:00
|
|
|
.Xr named 8 ,
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
broken-out fields from a line in
|
|
|
|
.Pa /etc/hosts ,
|
|
|
|
or database entries supplied by the
|
2002-01-14 16:59:03 +00:00
|
|
|
.Xr yp 8
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
system.
|
|
|
|
The order of the lookups is controlled by the
|
|
|
|
.Sq hosts
|
|
|
|
entry in
|
|
|
|
.Xr nsswitch.conf 5 .
|
1996-08-30 19:40:05 +00:00
|
|
|
.Bd -literal
|
1996-08-29 22:13:00 +00:00
|
|
|
struct hostent {
|
|
|
|
char *h_name; /* official name of host */
|
|
|
|
char **h_aliases; /* alias list */
|
|
|
|
int h_addrtype; /* host address type */
|
|
|
|
int h_length; /* length of address */
|
|
|
|
char **h_addr_list; /* list of addresses from name server */
|
|
|
|
};
|
|
|
|
#define h_addr h_addr_list[0] /* address, for backward compatibility */
|
1996-08-30 19:40:05 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1996-08-29 22:13:00 +00:00
|
|
|
The members of this structure are:
|
1996-08-30 19:40:05 +00:00
|
|
|
.Bl -tag -width h_addr_list
|
2001-02-10 10:51:39 +00:00
|
|
|
.It Va h_name
|
1996-08-29 22:13:00 +00:00
|
|
|
Official name of the host.
|
2001-02-10 10:51:39 +00:00
|
|
|
.It Va h_aliases
|
|
|
|
A
|
|
|
|
.Dv NULL Ns -terminated
|
|
|
|
array of alternate names for the host.
|
|
|
|
.It Va h_addrtype
|
1996-11-01 06:29:00 +00:00
|
|
|
The type of address being returned; usually
|
1996-08-30 19:40:05 +00:00
|
|
|
.Dv AF_INET .
|
2001-02-10 10:51:39 +00:00
|
|
|
.It Va h_length
|
1996-08-29 22:13:00 +00:00
|
|
|
The length, in bytes, of the address.
|
2001-02-10 10:51:39 +00:00
|
|
|
.It Va h_addr_list
|
|
|
|
A
|
|
|
|
.Dv NULL Ns -terminated
|
|
|
|
array of network addresses for the host.
|
1996-08-29 22:13:00 +00:00
|
|
|
Host addresses are returned in network byte order.
|
2001-02-10 10:51:39 +00:00
|
|
|
.It Va h_addr
|
1996-08-30 19:40:05 +00:00
|
|
|
The first address in
|
2001-02-10 10:51:39 +00:00
|
|
|
.Va h_addr_list ;
|
1996-08-30 19:40:05 +00:00
|
|
|
this is for backward compatibility.
|
1996-11-01 06:29:00 +00:00
|
|
|
.El
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pp
|
1996-08-29 22:13:00 +00:00
|
|
|
When using the nameserver,
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn gethostbyname
|
1996-11-01 06:29:00 +00:00
|
|
|
and
|
1999-09-19 17:57:35 +00:00
|
|
|
.Fn gethostbyname2
|
1996-08-29 22:13:00 +00:00
|
|
|
will search for the named host in the current domain and its parents
|
|
|
|
unless the name ends in a dot.
|
1996-08-30 19:40:05 +00:00
|
|
|
If the name contains no dot, and if the environment variable
|
|
|
|
.Dq Ev HOSTALIASES
|
1996-08-29 22:13:00 +00:00
|
|
|
contains the name of an alias file, the alias file will first be searched
|
|
|
|
for an alias matching the input name.
|
|
|
|
See
|
1996-08-30 19:40:05 +00:00
|
|
|
.Xr hostname 7
|
1996-08-29 22:13:00 +00:00
|
|
|
for the domain search procedure and the alias file format.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pp
|
|
|
|
The
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname2
|
|
|
|
function is an evolution of
|
|
|
|
.Fn gethostbyname
|
|
|
|
which is intended to allow lookups in address families other than
|
|
|
|
.Dv AF_INET ,
|
|
|
|
for example
|
|
|
|
.Dv AF_INET6 .
|
|
|
|
.Pp
|
|
|
|
The
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn sethostent
|
|
|
|
function
|
|
|
|
may be used to request the use of a connected
|
|
|
|
.Tn TCP
|
|
|
|
socket for queries.
|
1996-08-29 22:13:00 +00:00
|
|
|
If the
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fa stayopen
|
1996-08-29 22:13:00 +00:00
|
|
|
flag is non-zero,
|
1996-08-30 19:40:05 +00:00
|
|
|
this sets the option to send all queries to the name server using
|
|
|
|
.Tn TCP
|
2001-07-15 07:53:42 +00:00
|
|
|
and to retain the connection after each call to
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostbyname2
|
1996-08-29 22:13:00 +00:00
|
|
|
or
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn gethostbyaddr .
|
|
|
|
Otherwise, queries are performed using
|
|
|
|
.Tn UDP
|
|
|
|
datagrams.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn endhostent
|
|
|
|
function
|
|
|
|
closes the
|
|
|
|
.Tn TCP
|
|
|
|
connection.
|
1996-11-01 06:29:00 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn herror
|
|
|
|
function writes a message to the diagnostic output consisting of the
|
2002-12-19 09:40:28 +00:00
|
|
|
string argument
|
|
|
|
.Fa string ,
|
2001-02-10 10:51:39 +00:00
|
|
|
the constant string
|
|
|
|
.Qq Li ":\ " ,
|
|
|
|
and a message corresponding to the value of
|
1996-11-01 06:29:00 +00:00
|
|
|
.Va h_errno .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn hstrerror
|
|
|
|
function returns a string which is the message text corresponding to the
|
|
|
|
value of the
|
|
|
|
.Fa err
|
2002-12-19 09:40:28 +00:00
|
|
|
argument.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh FILES
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
.Bl -tag -width /etc/nsswitch.conf -compact
|
1996-08-30 19:40:05 +00:00
|
|
|
.It Pa /etc/hosts
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
.It Pa /etc/nsswitch.conf
|
1996-11-01 06:29:00 +00:00
|
|
|
.It Pa /etc/resolv.conf
|
1996-08-30 19:40:05 +00:00
|
|
|
.El
|
2001-02-09 19:06:25 +00:00
|
|
|
.Sh EXAMPLES
|
|
|
|
Print out the hostname associated with a specific IP address:
|
2001-02-10 10:51:39 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
const char *ipstr = "127.0.0.1";
|
|
|
|
struct in_addr ip;
|
|
|
|
struct hostent *hp;
|
2001-02-09 19:06:25 +00:00
|
|
|
|
2001-02-10 10:51:39 +00:00
|
|
|
if (!inet_aton(ipstr, &ip))
|
|
|
|
errx(1, "can't parse IP address %s", ipstr);
|
2001-02-09 19:06:25 +00:00
|
|
|
|
2006-05-12 15:37:23 +00:00
|
|
|
if ((hp = gethostbyaddr((const void *)&ip,
|
2001-02-10 10:51:39 +00:00
|
|
|
sizeof ip, AF_INET)) == NULL)
|
|
|
|
errx(1, "no name associated with %s", ipstr);
|
2001-02-09 19:06:25 +00:00
|
|
|
|
2001-02-10 10:51:39 +00:00
|
|
|
printf("name associated with %s is %s\en", ipstr, hp->h_name);
|
|
|
|
.Ed
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh DIAGNOSTICS
|
2001-07-15 07:53:42 +00:00
|
|
|
Error return status from
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostbyname2
|
1996-08-29 22:13:00 +00:00
|
|
|
and
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn gethostbyaddr
|
2001-02-10 10:51:39 +00:00
|
|
|
is indicated by return of a
|
|
|
|
.Dv NULL
|
|
|
|
pointer.
|
1996-08-29 22:13:00 +00:00
|
|
|
The external integer
|
1996-08-30 19:40:05 +00:00
|
|
|
.Va h_errno
|
1996-08-29 22:13:00 +00:00
|
|
|
may then be checked to see whether this is a temporary failure
|
|
|
|
or an invalid or unknown host.
|
|
|
|
The routine
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn herror
|
1996-08-29 22:13:00 +00:00
|
|
|
can be used to print an error message describing the failure.
|
|
|
|
If its argument
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fa string
|
|
|
|
is
|
2001-02-10 10:51:39 +00:00
|
|
|
.Pf non- Dv NULL ,
|
1996-08-30 19:40:05 +00:00
|
|
|
it is printed, followed by a colon and a space.
|
1996-08-29 22:13:00 +00:00
|
|
|
The error message is printed with a trailing newline.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pp
|
|
|
|
The variable
|
|
|
|
.Va h_errno
|
1996-08-29 22:13:00 +00:00
|
|
|
can have the following values:
|
1996-08-30 19:40:05 +00:00
|
|
|
.Bl -tag -width HOST_NOT_FOUND
|
|
|
|
.It Dv HOST_NOT_FOUND
|
1996-08-29 22:13:00 +00:00
|
|
|
No such host is known.
|
1996-08-30 19:40:05 +00:00
|
|
|
.It Dv TRY_AGAIN
|
1996-08-29 22:13:00 +00:00
|
|
|
This is usually a temporary error
|
|
|
|
and means that the local server did not receive
|
|
|
|
a response from an authoritative server.
|
|
|
|
A retry at some later time may succeed.
|
1996-08-30 19:40:05 +00:00
|
|
|
.It Dv NO_RECOVERY
|
1996-08-29 22:13:00 +00:00
|
|
|
Some unexpected server failure was encountered.
|
|
|
|
This is a non-recoverable error.
|
1996-08-30 19:40:05 +00:00
|
|
|
.It Dv NO_DATA
|
2001-07-15 07:53:42 +00:00
|
|
|
The requested name is valid but does not have an IP address;
|
|
|
|
this is not a temporary error.
|
1996-08-29 22:13:00 +00:00
|
|
|
This means that the name is known to the name server but there is no address
|
|
|
|
associated with this name.
|
|
|
|
Another type of request to the name server using this domain name
|
|
|
|
will result in an answer;
|
|
|
|
for example, a mail-forwarder may be registered for this domain.
|
1996-08-30 19:40:05 +00:00
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
2001-04-27 18:18:12 +00:00
|
|
|
.Xr getaddrinfo 3 ,
|
2001-08-08 11:05:47 +00:00
|
|
|
.Xr getnameinfo 3 ,
|
2001-05-15 15:57:05 +00:00
|
|
|
.Xr inet_aton 3 ,
|
1996-08-30 19:40:05 +00:00
|
|
|
.Xr resolver 3 ,
|
|
|
|
.Xr hosts 5 ,
|
|
|
|
.Xr hostname 7 ,
|
|
|
|
.Xr named 8
|
|
|
|
.Sh CAVEAT
|
|
|
|
The
|
|
|
|
.Fn gethostent
|
|
|
|
function
|
1996-08-29 22:13:00 +00:00
|
|
|
is defined, and
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn sethostent
|
1996-08-29 22:13:00 +00:00
|
|
|
and
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn endhostent
|
1996-08-29 22:13:00 +00:00
|
|
|
are redefined,
|
|
|
|
when
|
2003-06-08 10:07:14 +00:00
|
|
|
.Lb libc
|
1996-08-29 22:13:00 +00:00
|
|
|
is built to use only the routines to lookup in
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pa /etc/hosts
|
1996-08-29 22:13:00 +00:00
|
|
|
and not the name server.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn gethostent
|
|
|
|
function
|
1996-08-29 22:13:00 +00:00
|
|
|
reads the next line of
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pa /etc/hosts ,
|
1996-08-29 22:13:00 +00:00
|
|
|
opening the file if necessary.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn sethostent
|
|
|
|
function
|
|
|
|
opens and/or rewinds the file
|
|
|
|
.Pa /etc/hosts .
|
|
|
|
If the
|
|
|
|
.Fa stayopen
|
1996-08-29 22:13:00 +00:00
|
|
|
argument is non-zero,
|
1996-08-30 19:40:05 +00:00
|
|
|
the file will not be closed after each call to
|
1996-11-01 06:29:00 +00:00
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostbyname2
|
1996-08-29 22:13:00 +00:00
|
|
|
or
|
1996-08-30 19:40:05 +00:00
|
|
|
.Fn gethostbyaddr .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn endhostent
|
|
|
|
function
|
|
|
|
closes the file.
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn herror
|
2001-07-15 07:53:42 +00:00
|
|
|
function appeared in
|
1996-08-30 19:40:05 +00:00
|
|
|
.Bx 4.3 .
|
|
|
|
The
|
|
|
|
.Fn endhostent ,
|
|
|
|
.Fn gethostbyaddr ,
|
|
|
|
.Fn gethostbyname ,
|
|
|
|
.Fn gethostent ,
|
|
|
|
and
|
|
|
|
.Fn sethostent
|
|
|
|
functions appeared in
|
|
|
|
.Bx 4.2 .
|
1996-11-01 06:29:00 +00:00
|
|
|
The
|
|
|
|
.Fn gethostbyname2
|
2001-02-10 10:51:39 +00:00
|
|
|
function first appeared in
|
|
|
|
.Tn BIND
|
|
|
|
version 4.9.4.
|
1996-08-30 19:40:05 +00:00
|
|
|
.Sh BUGS
|
2005-04-28 18:03:43 +00:00
|
|
|
These functions use a thread-specific data storage;
|
1996-08-30 19:40:05 +00:00
|
|
|
if the data is needed for future use, it should be
|
|
|
|
copied before any subsequent calls overwrite it.
|
2005-04-28 18:03:43 +00:00
|
|
|
.Pp
|
|
|
|
Though these functions are thread-safe,
|
|
|
|
still it is recommended to use the
|
Make the resolver(3) and many associated interfaces much more reentrant.
The getaddrinfo(3), getipnodebyname(3) and resolver(3) can coincide now
with what should be totally reentrant, and h_errno values will now
be preserved correctly, but this does not affect interfaces such as
gethostbyname(3) which are still mostly non-reentrant.
In all of these relevant functions, the thread-safety has been pushed
down as far as it seems possible right now. This means that operations
that are selected via nsdispatch(3) (i.e. files, yp, dns) are protected
still under global locks that getaddrinfo(3) defines, but where possible
the locking is greatly reduced. The most noticeable improvement is
that multiple DNS lookups can now be run at the same time, and this
shows major improvement in performance of DNS-lookup threaded programs,
and solves the "Mozilla tab serialization" problem.
No single-threaded applications need to be recompiled. Multi-threaded
applications that reference "_res" to change resolver(3) options will
need to be recompiled, and ones which reference "h_errno" will also
if they desire the correct h_errno values. If the applications already
understood that _res and h_errno were not thread-safe and had their own
locking, they will see no performance improvement but will not
actually break in any way.
Please note that when NSS modules are used, or when nsdispatch(3)
defaults to adding any lookups of its own to the individual libc
_nsdispatch() calls, those MUST be reentrant as well.
2004-02-25 21:03:46 +00:00
|
|
|
.Xr getaddrinfo 3
|
2005-04-28 18:03:43 +00:00
|
|
|
family of functions, instead.
|
|
|
|
.Pp
|
1996-08-30 19:40:05 +00:00
|
|
|
Only the Internet
|
1996-08-29 22:13:00 +00:00
|
|
|
address format is currently understood.
|