Blame man3/gethostbyname.3

Packit 7cfc04
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" References consulted:
Packit 7cfc04
.\"     Linux libc source code
Packit 7cfc04
.\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
Packit 7cfc04
.\"     386BSD man pages
Packit 7cfc04
.\" Modified 1993-05-22, David Metcalfe
Packit 7cfc04
.\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.\" Modified 1997-02-16, Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified 1998-12-21, Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified 2000-08-12, Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified 2001-05-19, Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified 2002-08-05, Michael Kerrisk
Packit 7cfc04
.\" Modified 2004-10-31, Andries Brouwer
Packit 7cfc04
.\"
Packit 7cfc04
.TH GETHOSTBYNAME 3 2017-09-15 "" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
Packit 7cfc04
h_errno,
Packit 7cfc04
herror, hstrerror,
Packit 7cfc04
gethostbyaddr_r,
Packit 7cfc04
gethostbyname2, gethostbyname2_r, gethostbyname_r,
Packit 7cfc04
gethostent_r \- get network host entry
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <netdb.h>
Packit 7cfc04
.B extern int h_errno;
Packit 7cfc04
.PP
Packit 7cfc04
.BI "struct hostent *gethostbyname(const char *" name );
Packit 7cfc04
Packit 7cfc04
.BR "#include <sys/socket.h>" "       /* for AF_INET */"
Packit 7cfc04
.BI "struct hostent *gethostbyaddr(const void *" addr ,
Packit 7cfc04
.BI "                              socklen_t " len ", int " type );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void sethostent(int " stayopen );
Packit 7cfc04
.PP
Packit 7cfc04
.B void endhostent(void);
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void herror(const char *" s );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "const char *hstrerror(int " err );
Packit 7cfc04
.PP
Packit 7cfc04
/* System V/POSIX extension */
Packit 7cfc04
.B struct hostent *gethostent(void);
Packit 7cfc04
.PP
Packit 7cfc04
/* GNU extensions */
Packit 7cfc04
.BI "struct hostent *gethostbyname2(const char *" name ", int " af );
Packit 7cfc04
.PP
Packit 7cfc04
.B "int gethostent_r("
Packit 7cfc04
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
Packit 7cfc04
.BI "        struct hostent **" result ", int *" h_errnop );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
Packit 7cfc04
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
Packit 7cfc04
.BI "        struct hostent **" result ", int *" h_errnop );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int gethostbyname_r(const char *" name ,
Packit 7cfc04
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
Packit 7cfc04
.BI "        struct hostent **" result ", int *" h_errnop );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int gethostbyname2_r(const char *" name ", int " af,
Packit 7cfc04
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
Packit 7cfc04
.BI "        struct hostent **" result ", int *" h_errnop );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.PD 0
Packit 7cfc04
.ad l
Packit 7cfc04
.BR gethostbyname2 (),
Packit 7cfc04
.BR gethostent_r (),
Packit 7cfc04
.BR gethostbyaddr_r (),
Packit 7cfc04
.BR gethostbyname_r (),
Packit 7cfc04
.BR gethostbyname2_r ():
Packit 7cfc04
.RS 4
Packit 7cfc04
.TP 4
Packit 7cfc04
Since glibc 2.19:
Packit 7cfc04
_DEFAULT_SOURCE
Packit 7cfc04
.TP 4
Packit 7cfc04
Glibc versions up to and including 2.19:
Packit 7cfc04
_BSD_SOURCE || _SVID_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.PD
Packit 7cfc04
.PP
Packit 7cfc04
.PD 0
Packit 7cfc04
.BR herror (),
Packit 7cfc04
.BR hstrerror ():
Packit 7cfc04
.RS 4
Packit 7cfc04
.TP 4
Packit 7cfc04
Since glibc 2.19:
Packit 7cfc04
_DEFAULT_SOURCE
Packit 7cfc04
.TP 4
Packit 7cfc04
Glibc 2.8 to 2.19:
Packit 7cfc04
_BSD_SOURCE || _SVID_SOURCE
Packit 7cfc04
.TP
Packit 7cfc04
Before glibc 2.8:
Packit 7cfc04
none
Packit 7cfc04
.RE
Packit 7cfc04
.PD
Packit 7cfc04
.PP
Packit 7cfc04
.PD 0
Packit 7cfc04
.BR h_errno :
Packit 7cfc04
.RS 4
Packit 7cfc04
.TP 4
Packit 7cfc04
Since glibc 2.19
Packit 7cfc04
_DEFAULT_SOURCE || _POSIX_C_SOURCE < 200809L
Packit 7cfc04
.TP 4
Packit 7cfc04
Glibc 2.12 to 2.19:
Packit 7cfc04
_BSD_SOURCE || _SVID_SOURCE || _POSIX_C_SOURCE < 200809L
Packit 7cfc04
.TP
Packit 7cfc04
Before glibc 2.12:
Packit 7cfc04
none
Packit 7cfc04
.RE
Packit 7cfc04
.ad b
Packit 7cfc04
.PD
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR gethostbyname* (),
Packit 7cfc04
.BR gethostbyaddr* (),
Packit 7cfc04
.BR herror (),
Packit 7cfc04
and
Packit 7cfc04
.BR hstrerror ()
Packit 7cfc04
functions are obsolete.
Packit 7cfc04
Applications should use
Packit 7cfc04
.BR getaddrinfo (3),
Packit 7cfc04
.BR getnameinfo (3),
Packit 7cfc04
and
Packit 7cfc04
.BR gai_strerror (3)
Packit 7cfc04
instead.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
function returns a structure of type
Packit 7cfc04
.I hostent
Packit 7cfc04
for the given host
Packit 7cfc04
.IR name .
Packit 7cfc04
Here
Packit 7cfc04
.I name
Packit 7cfc04
is either a hostname or an IPv4 address in standard dot notation (as for
Packit 7cfc04
.BR inet_addr (3)).
Packit 7cfc04
If
Packit 7cfc04
.I name
Packit 7cfc04
is an IPv4 address, no lookup is performed and
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
simply copies
Packit 7cfc04
.I name
Packit 7cfc04
into the
Packit 7cfc04
.I h_name
Packit 7cfc04
field and its
Packit 7cfc04
.I struct in_addr
Packit 7cfc04
equivalent into the
Packit 7cfc04
.I h_addr_list[0]
Packit 7cfc04
field of the returned
Packit 7cfc04
.I hostent
Packit 7cfc04
structure.
Packit 7cfc04
If
Packit 7cfc04
.I name
Packit 7cfc04
doesn't end in a dot and the environment variable
Packit 7cfc04
.B HOSTALIASES
Packit 7cfc04
is set, the alias file pointed to by
Packit 7cfc04
.B HOSTALIASES
Packit 7cfc04
will first be searched for
Packit 7cfc04
.I name
Packit 7cfc04
(see
Packit 7cfc04
.BR hostname (7)
Packit 7cfc04
for the file format).
Packit 7cfc04
The current domain and its parents are searched unless \fIname\fP
Packit 7cfc04
ends in a dot.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
function returns a structure of type \fIhostent\fP
Packit 7cfc04
for the given host address \fIaddr\fP of length \fIlen\fP and address type
Packit 7cfc04
\fItype\fP.
Packit 7cfc04
Valid address types are
Packit 7cfc04
.B AF_INET
Packit 7cfc04
and
Packit 7cfc04
.BR AF_INET6 .
Packit 7cfc04
The host address argument is a pointer to a struct of a type depending
Packit 7cfc04
on the address type, for example a \fIstruct in_addr *\fP (probably
Packit 7cfc04
obtained via a call to
Packit 7cfc04
.BR inet_addr (3))
Packit 7cfc04
for address type
Packit 7cfc04
.BR AF_INET .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR sethostent ()
Packit 7cfc04
function specifies, if \fIstayopen\fP is true (1),
Packit 7cfc04
that a connected TCP socket should be used for the name server queries and
Packit 7cfc04
that the connection should remain open during successive queries.
Packit 7cfc04
Otherwise, name server queries will use UDP datagrams.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR endhostent ()
Packit 7cfc04
function ends the use of a TCP connection for name
Packit 7cfc04
server queries.
Packit 7cfc04
.PP
Packit 7cfc04
The (obsolete)
Packit 7cfc04
.BR herror ()
Packit 7cfc04
function prints the error message associated
Packit 7cfc04
with the current value of \fIh_errno\fP on \fIstderr\fP.
Packit 7cfc04
.PP
Packit 7cfc04
The (obsolete)
Packit 7cfc04
.BR hstrerror ()
Packit 7cfc04
function takes an error number
Packit 7cfc04
(typically \fIh_errno\fP) and returns the corresponding message string.
Packit 7cfc04
.PP
Packit 7cfc04
The domain name queries carried out by
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
and
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
rely on the Name Service Switch
Packit 7cfc04
.RB ( nsswitch.conf (5))
Packit 7cfc04
configured sources or a local name server
Packit 7cfc04
.RB ( named (8)).
Packit 7cfc04
The default action is to query the Name Service Switch
Packit 7cfc04
.RB ( nsswitch.conf(5))
Packit 7cfc04
configured sources, failing that, a local name server
Packit 7cfc04
.RB ( named (8)).
Packit 7cfc04
.\"
Packit 7cfc04
.SS Historical
Packit 7cfc04
The
Packit 7cfc04
.BR nsswitch.conf (5)
Packit 7cfc04
file is the modern way of controlling the order of host lookups.
Packit 7cfc04
.PP
Packit 7cfc04
In glibc 2.4 and earlier, the
Packit 7cfc04
.I order
Packit 7cfc04
keyword was used to control the order of host lookups as defined in
Packit 7cfc04
.IR /etc/host.conf
Packit 7cfc04
.RB ( host.conf (5)).
Packit 7cfc04
.PP
Packit 7cfc04
.PP
Packit 7cfc04
The \fIhostent\fP structure is defined in \fI<netdb.h>\fP as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct hostent {
Packit 7cfc04
    char  *h_name;            /* official name of host */
Packit 7cfc04
    char **h_aliases;         /* alias list */
Packit 7cfc04
    int    h_addrtype;        /* host address type */
Packit 7cfc04
    int    h_length;          /* length of address */
Packit 7cfc04
    char **h_addr_list;       /* list of addresses */
Packit 7cfc04
}
Packit 7cfc04
#define h_addr h_addr_list[0] /* for backward compatibility */
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The members of the \fIhostent\fP structure are:
Packit 7cfc04
.TP
Packit 7cfc04
.I h_name
Packit 7cfc04
The official name of the host.
Packit 7cfc04
.TP
Packit 7cfc04
.I h_aliases
Packit 7cfc04
An array of alternative names for the host, terminated by a null pointer.
Packit 7cfc04
.TP
Packit 7cfc04
.I h_addrtype
Packit 7cfc04
The type of address; always
Packit 7cfc04
.B AF_INET
Packit 7cfc04
or
Packit 7cfc04
.B AF_INET6
Packit 7cfc04
at present.
Packit 7cfc04
.TP
Packit 7cfc04
.I h_length
Packit 7cfc04
The length of the address in bytes.
Packit 7cfc04
.TP
Packit 7cfc04
.I h_addr_list
Packit 7cfc04
An array of pointers to network addresses for the host (in network byte
Packit 7cfc04
order), terminated by a null pointer.
Packit 7cfc04
.TP
Packit 7cfc04
.I h_addr
Packit 7cfc04
The first address in \fIh_addr_list\fP for backward compatibility.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
and
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
functions return the
Packit 7cfc04
.I hostent
Packit 7cfc04
structure or a null pointer if an error occurs.
Packit 7cfc04
On error, the
Packit 7cfc04
.I h_errno
Packit 7cfc04
variable holds an error number.
Packit 7cfc04
When non-NULL, the return value may point at static data, see the notes below.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
The variable \fIh_errno\fP can have the following values:
Packit 7cfc04
.TP
Packit 7cfc04
.B HOST_NOT_FOUND
Packit 7cfc04
The specified host is unknown.
Packit 7cfc04
.TP
Packit 7cfc04
.BR NO_DATA
Packit 7cfc04
The requested name is valid but does not have an IP address.
Packit 7cfc04
Another type of request to the name server for this domain
Packit 7cfc04
may return an answer.
Packit 7cfc04
The constant
Packit 7cfc04
.BR NO_ADDRESS
Packit 7cfc04
is a synonym for
Packit 7cfc04
.BR NO_DATA .
Packit 7cfc04
.TP
Packit 7cfc04
.B NO_RECOVERY
Packit 7cfc04
A nonrecoverable name server error occurred.
Packit 7cfc04
.TP
Packit 7cfc04
.B TRY_AGAIN
Packit 7cfc04
A temporary error occurred on an authoritative name server.
Packit 7cfc04
Try again later.
Packit 7cfc04
.SH FILES
Packit 7cfc04
.TP
Packit 7cfc04
.I /etc/host.conf
Packit 7cfc04
resolver configuration file
Packit 7cfc04
.TP
Packit 7cfc04
.I /etc/hosts
Packit 7cfc04
host database file
Packit 7cfc04
.TP
Packit 7cfc04
.I /etc/nsswitch.conf
Packit 7cfc04
name service switch configuration
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw18 lb lbw29
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:hostbyname env
Packit 7cfc04
.br
Packit 7cfc04
locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:hostbyaddr env
Packit 7cfc04
.br
Packit 7cfc04
locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR sethostent (),
Packit 7cfc04
.br
Packit 7cfc04
.BR endhostent (),
Packit 7cfc04
.br
Packit 7cfc04
.BR gethostent_r ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:hostent env
Packit 7cfc04
.br
Packit 7cfc04
locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR herror (),
Packit 7cfc04
.br
Packit 7cfc04
.BR hstrerror ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
T{
Packit 7cfc04
.BR gethostent ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:hostent
Packit 7cfc04
.br
Packit 7cfc04
race:hostentbuf env locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR gethostbyname2 ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:hostbyname2
Packit 7cfc04
.br
Packit 7cfc04
env locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR gethostbyaddr_r (),
Packit 7cfc04
.BR gethostbyname_r (),
Packit 7cfc04
.BR gethostbyname2_r ()
Packit 7cfc04
T}	Thread safety	MT-Safe env locale
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
In the above table,
Packit 7cfc04
.I hostent
Packit 7cfc04
in
Packit 7cfc04
.I race:hostent
Packit 7cfc04
signifies that if any of the functions
Packit 7cfc04
.BR sethostent (),
Packit 7cfc04
.BR gethostent (),
Packit 7cfc04
.BR gethostent_r (),
Packit 7cfc04
or
Packit 7cfc04
.BR endhostent ()
Packit 7cfc04
are used in parallel in different threads of a program,
Packit 7cfc04
then data races could occur.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001 specifies
Packit 7cfc04
.BR gethostbyname (),
Packit 7cfc04
.BR gethostbyaddr (),
Packit 7cfc04
.BR sethostent (),
Packit 7cfc04
.BR endhostent (),
Packit 7cfc04
.BR gethostent (),
Packit 7cfc04
and
Packit 7cfc04
.IR h_errno ;
Packit 7cfc04
.BR gethostbyname (),
Packit 7cfc04
.BR gethostbyaddr (),
Packit 7cfc04
and
Packit 7cfc04
.IR h_errno
Packit 7cfc04
are marked obsolescent in that standard.
Packit 7cfc04
POSIX.1-2008 removes the specifications of
Packit 7cfc04
.BR gethostbyname (),
Packit 7cfc04
.BR gethostbyaddr (),
Packit 7cfc04
and
Packit 7cfc04
.IR h_errno ,
Packit 7cfc04
recommending the use of
Packit 7cfc04
.BR getaddrinfo (3)
Packit 7cfc04
and
Packit 7cfc04
.BR getnameinfo (3)
Packit 7cfc04
instead.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The functions
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
and
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
may return pointers to static data, which may be overwritten by
Packit 7cfc04
later calls.
Packit 7cfc04
Copying the
Packit 7cfc04
.I struct hostent
Packit 7cfc04
does not suffice, since it contains pointers; a deep copy is required.
Packit 7cfc04
.PP
Packit 7cfc04
In the original BSD implementation the
Packit 7cfc04
.I len
Packit 7cfc04
argument
Packit 7cfc04
of
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
was an
Packit 7cfc04
.IR int .
Packit 7cfc04
The SUSv2 standard is buggy and declares the
Packit 7cfc04
.I len
Packit 7cfc04
argument of
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
to be of type
Packit 7cfc04
.IR size_t .
Packit 7cfc04
(That is wrong, because it has to be
Packit 7cfc04
.IR int ,
Packit 7cfc04
and
Packit 7cfc04
.I size_t
Packit 7cfc04
is not.
Packit 7cfc04
POSIX.1-2001 makes it
Packit 7cfc04
.IR socklen_t ,
Packit 7cfc04
which is OK.)
Packit 7cfc04
See also
Packit 7cfc04
.BR accept (2).
Packit 7cfc04
.PP
Packit 7cfc04
The BSD prototype for
Packit 7cfc04
.BR gethostbyaddr ()
Packit 7cfc04
uses
Packit 7cfc04
.I "const char\ *"
Packit 7cfc04
for the first argument.
Packit 7cfc04
.SS System V/POSIX extension
Packit 7cfc04
POSIX requires the
Packit 7cfc04
.BR gethostent ()
Packit 7cfc04
call, which should return the next entry in the host data base.
Packit 7cfc04
When using DNS/BIND this does not make much sense, but it may
Packit 7cfc04
be reasonable if the host data base is a file that can be read
Packit 7cfc04
line by line.
Packit 7cfc04
On many systems, a routine of this name reads
Packit 7cfc04
from the file
Packit 7cfc04
.IR /etc/hosts .
Packit 7cfc04
.\" e.g., Linux, FreeBSD, UnixWare, HP-UX
Packit 7cfc04
It may be available only when the library was built without DNS support.
Packit 7cfc04
.\" e.g., FreeBSD, AIX
Packit 7cfc04
The glibc version will ignore ipv6 entries.
Packit 7cfc04
This function is not reentrant,
Packit 7cfc04
and glibc adds a reentrant version
Packit 7cfc04
.BR gethostent_r ().
Packit 7cfc04
.SS GNU extensions
Packit 7cfc04
Glibc2 also has a
Packit 7cfc04
.BR gethostbyname2 ()
Packit 7cfc04
that works like
Packit 7cfc04
.BR gethostbyname (),
Packit 7cfc04
but permits to specify the address family to which the address must belong.
Packit 7cfc04
.PP
Packit 7cfc04
Glibc2 also has reentrant versions
Packit 7cfc04
.BR gethostent_r (),
Packit 7cfc04
.BR gethostbyaddr_r (),
Packit 7cfc04
.BR gethostbyname_r ()
Packit 7cfc04
and
Packit 7cfc04
.BR gethostbyname2_r ().
Packit 7cfc04
The caller supplies a
Packit 7cfc04
.I hostent
Packit 7cfc04
structure
Packit 7cfc04
.I ret
Packit 7cfc04
which will be filled in on success, and a temporary work buffer
Packit 7cfc04
.I buf
Packit 7cfc04
of size
Packit 7cfc04
.IR buflen .
Packit 7cfc04
After the call,
Packit 7cfc04
.I result
Packit 7cfc04
will point to the result on success.
Packit 7cfc04
In case of an error
Packit 7cfc04
or if no entry is found
Packit 7cfc04
.I result
Packit 7cfc04
will be NULL.
Packit 7cfc04
The functions return 0 on success and a nonzero error number on failure.
Packit 7cfc04
In addition to the errors returned by the nonreentrant
Packit 7cfc04
versions of these functions, if
Packit 7cfc04
.I buf
Packit 7cfc04
is too small, the functions will return
Packit 7cfc04
.BR ERANGE ,
Packit 7cfc04
and the call should be retried with a larger buffer.
Packit 7cfc04
The global variable
Packit 7cfc04
.I h_errno
Packit 7cfc04
is not modified, but the address of a variable in which to store error numbers
Packit 7cfc04
is passed in
Packit 7cfc04
.IR h_errnop .
Packit 7cfc04
.SH BUGS
Packit 7cfc04
.BR gethostbyname ()
Packit 7cfc04
does not recognize components of a dotted IPv4 address string
Packit 7cfc04
that are expressed in hexadecimal.
Packit 7cfc04
.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR getaddrinfo (3),
Packit 7cfc04
.\" .BR getipnodebyaddr (3),
Packit 7cfc04
.\" .BR getipnodebyname (3),
Packit 7cfc04
.BR getnameinfo (3),
Packit 7cfc04
.BR inet (3),
Packit 7cfc04
.BR inet_ntop (3),
Packit 7cfc04
.BR inet_pton (3),
Packit 7cfc04
.BR resolver (3),
Packit 7cfc04
.BR hosts (5),
Packit 7cfc04
.BR nsswitch.conf (5),
Packit 7cfc04
.BR hostname (7),
Packit 7cfc04
.BR named (8)
Packit 7cfc04
.\" .BR resolv+ (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.