.\" Modified 2002-08-05, Michael Kerrisk
.\" Modified 2004-10-31, Andries Brouwer
.\"
-.TH GETHOSTBYNAME 3 2016-03-15 "" "Linux Programmer's Manual"
+.TH GETHOSTBYNAME 3 2017-09-15 "" "Linux Programmer's Manual"
.SH NAME
gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
h_errno,
.B extern int h_errno;
.PP
.BI "struct hostent *gethostbyname(const char *" name );
-.PP
+
.BR "#include <sys/socket.h>" " /* for AF_INET */"
.BI "struct hostent *gethostbyaddr(const void *" addr ,
.BI " socklen_t " len ", int " type );
.BI "const char *hstrerror(int " err );
.PP
/* System V/POSIX extension */
-.br
.B struct hostent *gethostent(void);
.PP
/* GNU extensions */
-.br
.BI "struct hostent *gethostbyname2(const char *" name ", int " af );
.PP
.B "int gethostent_r("
Glibc versions up to and including 2.19:
_BSD_SOURCE || _SVID_SOURCE
.RE
-
+.PD
+.PP
+.PD 0
.BR herror (),
.BR hstrerror ():
.RS 4
Before glibc 2.8:
none
.RE
-
+.PD
+.PP
+.PD 0
.BR h_errno :
.RS 4
.TP 4
and
.BR gai_strerror (3)
instead.
-
+.PP
The
.BR gethostbyname ()
function returns a structure of type
keyword was used to control the order of host lookups as defined in
.IR /etc/host.conf
.RB ( host.conf (5)).
-
+.PP
.PP
The \fIhostent\fP structure is defined in \fI<netdb.h>\fP as follows:
-.sp
+.PP
.in +4n
-.nf
-.ne 7
+.EX
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
char **h_addr_list; /* list of addresses */
}
#define h_addr h_addr_list[0] /* for backward compatibility */
-.fi
+.EE
.in
.PP
The members of the \fIhostent\fP structure are:
.BR gethostbyname2_r ()
T} Thread safety MT-Safe env locale
.TE
-
+.sp 1
In the above table,
.I hostent
in
Copying the
.I struct hostent
does not suffice, since it contains pointers; a deep copy is required.
-.LP
+.PP
In the original BSD implementation the
.I len
argument
which is OK.)
See also
.BR accept (2).
-.LP
+.PP
The BSD prototype for
.BR gethostbyaddr ()
uses
that works like
.BR gethostbyname (),
but permits to specify the address family to which the address must belong.
-.LP
+.PP
Glibc2 also has reentrant versions
.BR gethostent_r (),
.BR gethostbyaddr_r (),