]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/gethostbyname.3
fanotify_init.2, fanotify.7: Document FAN_REPORT_TID
[thirdparty/man-pages.git] / man3 / gethostbyname.3
index 7ec96331c01b22a62cc2c5d7fc93c824014b9c4d..5b680e521f0c09f3a9982f98be53e794df3a6ec8 100644 (file)
@@ -1,5 +1,6 @@
 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
@@ -19,6 +20,7 @@
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
 .\"
 .\" References consulted:
 .\"     Linux libc source code
 .\" Modified 2002-08-05, Michael Kerrisk
 .\" Modified 2004-10-31, Andries Brouwer
 .\"
-.TH GETHOSTBYNAME 3 2004-10-31 "" "Linux Programmer's Manual"
+.TH GETHOSTBYNAME 3 2017-09-15 "" "Linux Programmer's Manual"
 .SH NAME
 gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
-herror, hstrerror \- get network host entry
+h_errno,
+herror, hstrerror,
+gethostbyaddr_r,
+gethostbyname2, gethostbyname2_r, gethostbyname_r,
+gethostent_r \- get network host entry
 .SH SYNOPSIS
 .nf
 .B #include <netdb.h>
 .B extern int h_errno;
-.sp
+.PP
 .BI "struct hostent *gethostbyname(const char *" name );
-.sp
+
 .BR "#include <sys/socket.h>" "       /* for AF_INET */"
-.BI "struct hostent *gethostbyaddr(const void *" addr \
-", socklen_t " len ", int " type );
-.sp
+.BI "struct hostent *gethostbyaddr(const void *" addr ,
+.BI "                              socklen_t " len ", int " type );
+.PP
 .BI "void sethostent(int " stayopen );
-.sp
+.PP
 .B void endhostent(void);
-.sp
+.PP
 .BI "void herror(const char *" s );
-.sp
+.PP
 .BI "const char *hstrerror(int " err );
-.sp
+.PP
 /* System V/POSIX extension */
-.br
 .B struct hostent *gethostent(void);
-.sp
+.PP
 /* GNU extensions */
-.br
 .BI "struct hostent *gethostbyname2(const char *" name ", int " af );
-.sp
-.BI "int gethostent_r("
+.PP
+.B "int gethostent_r("
 .BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
 .BI "        struct hostent **" result ", int *" h_errnop );
-.sp
+.PP
+.BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
+.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
+.BI "        struct hostent **" result ", int *" h_errnop );
+.PP
 .BI "int gethostbyname_r(const char *" name ,
 .BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
 .BI "        struct hostent **" result ", int *" h_errnop );
-.sp
+.PP
 .BI "int gethostbyname2_r(const char *" name ", int " af,
 .BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
 .BI "        struct hostent **" result ", int *" h_errnop );
 .fi
+.PP
+.in -4n
+Feature Test Macro Requirements for glibc (see
+.BR feature_test_macros (7)):
+.in
+.PP
+.PD 0
+.ad l
+.BR gethostbyname2 (),
+.BR gethostent_r (),
+.BR gethostbyaddr_r (),
+.BR gethostbyname_r (),
+.BR gethostbyname2_r ():
+.RS 4
+.TP 4
+Since glibc 2.19:
+_DEFAULT_SOURCE
+.TP 4
+Glibc versions up to and including 2.19:
+_BSD_SOURCE || _SVID_SOURCE
+.RE
+.PD
+.PP
+.PD 0
+.BR herror (),
+.BR hstrerror ():
+.RS 4
+.TP 4
+Since glibc 2.19:
+_DEFAULT_SOURCE
+.TP 4
+Glibc 2.8 to 2.19:
+_BSD_SOURCE || _SVID_SOURCE
+.TP
+Before glibc 2.8:
+none
+.RE
+.PD
+.PP
+.PD 0
+.BR h_errno :
+.RS 4
+.TP 4
+Since glibc 2.19
+_DEFAULT_SOURCE || _POSIX_C_SOURCE < 200809L
+.TP 4
+Glibc 2.12 to 2.19:
+_BSD_SOURCE || _SVID_SOURCE || _POSIX_C_SOURCE < 200809L
+.TP
+Before glibc 2.12:
+none
+.RE
+.ad b
+.PD
 .SH DESCRIPTION
 The
+.BR gethostbyname* (),
+.BR gethostbyaddr* (),
+.BR herror (),
+and
+.BR hstrerror ()
+functions are obsolete.
+Applications should use
+.BR getaddrinfo (3),
+.BR getnameinfo (3),
+and
+.BR gai_strerror (3)
+instead.
+.PP
+The
 .BR gethostbyname ()
 function returns a structure of type
 .I hostent
@@ -85,12 +161,11 @@ for the given host
 .IR name .
 Here
 .I name
-is either a host name, or an IPv4 address in standard dot notation,
-or an IPv6 address in colon (and possibly dot) notation.
-(See RFC\ 1884 for the description of IPv6 addresses.)
+is either a hostname or an IPv4 address in standard dot notation (as for
+.BR inet_addr (3)).
 If
 .I name
-is an IPv4 or IPv6 address, no lookup is performed and
+is an IPv4 address, no lookup is performed and
 .BR gethostbyname ()
 simply copies
 .I name
@@ -127,10 +202,11 @@ Valid address types are
 and
 .BR AF_INET6 .
 The host address argument is a pointer to a struct of a type depending
-on the address type, for example a \fBstruct in_addr *\fP (probably
-obtained via a call to 
+on the address type, for example a \fIstruct in_addr *\fP (probably
+obtained via a call to
 .BR inet_addr (3))
-for address type AF_INET.
+for address type
+.BR AF_INET .
 .PP
 The
 .BR sethostent ()
@@ -147,7 +223,7 @@ server queries.
 The (obsolete)
 .BR herror ()
 function prints the error message associated
-with the current value of \fIh_errno\fP on stderr.
+with the current value of \fIh_errno\fP on \fIstderr\fP.
 .PP
 The (obsolete)
 .BR hstrerror ()
@@ -158,24 +234,31 @@ The domain name queries carried out by
 .BR gethostbyname ()
 and
 .BR gethostbyaddr ()
-use a combination of any or all of the name server
-.BR named (8),
-a broken out line from \fI/etc/hosts\fP, and the Network
-Information Service (NIS or YP), depending upon the contents of the
-\fIorder\fP line in
-.IR /etc/host.conf .
-.\" (See
-.\" .BR resolv+ (8)).
-The default action is to query
-.BR named (8),
-followed by
-.IR /etc/hosts .
+rely on the Name Service Switch
+.RB ( nsswitch.conf (5))
+configured sources or a local name server
+.RB ( named (8)).
+The default action is to query the Name Service Switch
+.RB ( nsswitch.conf(5))
+configured sources, failing that, a local name server
+.RB ( named (8)).
+.\"
+.SS Historical
+The
+.BR nsswitch.conf (5)
+file is the modern way of controlling the order of host lookups.
+.PP
+In glibc 2.4 and earlier, the
+.I order
+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
-.in +0.5i
-.nf
-.ne 7
+.PP
+.in +4n
+.EX
 struct hostent {
     char  *h_name;            /* official name of host */
     char **h_aliases;         /* alias list */
@@ -184,8 +267,8 @@ struct hostent {
     char **h_addr_list;       /* list of addresses */
 }
 #define h_addr h_addr_list[0] /* for backward compatibility */
-.fi
-.in -0.5i
+.EE
+.in
 .PP
 The members of the \fIhostent\fP structure are:
 .TP
@@ -193,7 +276,7 @@ The members of the \fIhostent\fP structure are:
 The official name of the host.
 .TP
 .I h_aliases
-An array of alternative names for the host, terminated by a NULL pointer.
+An array of alternative names for the host, terminated by a null pointer.
 .TP
 .I h_addrtype
 The type of address; always
@@ -207,18 +290,18 @@ The length of the address in bytes.
 .TP
 .I h_addr_list
 An array of pointers to network addresses for the host (in network byte
-order), terminated by a NULL pointer.
+order), terminated by a null pointer.
 .TP
 .I h_addr
 The first address in \fIh_addr_list\fP for backward compatibility.
-.SH "RETURN VALUE"
+.SH RETURN VALUE
 The
 .BR gethostbyname ()
 and
 .BR gethostbyaddr ()
 functions return the
 .I hostent
-structure or a NULL pointer if an error occurs.
+structure or a null pointer if an error occurs.
 On error, the
 .I h_errno
 variable holds an error number.
@@ -229,11 +312,17 @@ The variable \fIh_errno\fP can have the following values:
 .B HOST_NOT_FOUND
 The specified host is unknown.
 .TP
-.BR NO_ADDRESS " or " NO_DATA
+.BR NO_DATA
 The requested name is valid but does not have an IP address.
+Another type of request to the name server for this domain
+may return an answer.
+The constant
+.BR NO_ADDRESS
+is a synonym for
+.BR NO_DATA .
 .TP
 .B NO_RECOVERY
-A non-recoverable name server error occurred.
+A nonrecoverable name server error occurred.
 .TP
 .B TRY_AGAIN
 A temporary error occurred on an authoritative name server.
@@ -248,8 +337,101 @@ host database file
 .TP
 .I /etc/nsswitch.conf
 name service switch configuration
-.SH "CONFORMING TO"
-4.3BSD, POSIX.1-2001.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lbw18 lb lbw29
+l l l.
+Interface      Attribute       Value
+T{
+.BR gethostbyname ()
+T}     Thread safety   T{
+MT-Unsafe race:hostbyname env
+.br
+locale
+T}
+T{
+.BR gethostbyaddr ()
+T}     Thread safety   T{
+MT-Unsafe race:hostbyaddr env
+.br
+locale
+T}
+T{
+.BR sethostent (),
+.br
+.BR endhostent (),
+.br
+.BR gethostent_r ()
+T}     Thread safety   T{
+MT-Unsafe race:hostent env
+.br
+locale
+T}
+T{
+.BR herror (),
+.br
+.BR hstrerror ()
+T}     Thread safety   MT-Safe
+T{
+.BR gethostent ()
+T}     Thread safety   T{
+MT-Unsafe race:hostent
+.br
+race:hostentbuf env locale
+T}
+T{
+.BR gethostbyname2 ()
+T}     Thread safety   T{
+MT-Unsafe race:hostbyname2
+.br
+env locale
+T}
+T{
+.BR gethostbyaddr_r (),
+.BR gethostbyname_r (),
+.BR gethostbyname2_r ()
+T}     Thread safety   MT-Safe env locale
+.TE
+.sp 1
+In the above table,
+.I hostent
+in
+.I race:hostent
+signifies that if any of the functions
+.BR sethostent (),
+.BR gethostent (),
+.BR gethostent_r (),
+or
+.BR endhostent ()
+are used in parallel in different threads of a program,
+then data races could occur.
+.SH CONFORMING TO
+POSIX.1-2001 specifies
+.BR gethostbyname (),
+.BR gethostbyaddr (),
+.BR sethostent (),
+.BR endhostent (),
+.BR gethostent (),
+and
+.IR h_errno ;
+.BR gethostbyname (),
+.BR gethostbyaddr (),
+and
+.IR h_errno
+are marked obsolescent in that standard.
+POSIX.1-2008 removes the specifications of
+.BR gethostbyname (),
+.BR gethostbyaddr (),
+and
+.IR h_errno ,
+recommending the use of
+.BR getaddrinfo (3)
+and
+.BR getnameinfo (3)
+instead.
 .SH NOTES
 The functions
 .BR gethostbyname ()
@@ -260,17 +442,17 @@ later calls.
 Copying the
 .I struct hostent
 does not suffice, since it contains pointers; a deep copy is required.
-.LP
-In the original BSD implementation the 
+.PP
+In the original BSD implementation the
 .I len
 argument
-of 
+of
 .BR gethostbyname ()
 was an
 .IR int .
 The SUSv2 standard is buggy and declares the
 .I len
-parameter of
+argument of
 .BR gethostbyaddr ()
 to be of type
 .IR size_t .
@@ -284,73 +466,80 @@ POSIX.1-2001 makes it
 which is OK.)
 See also
 .BR accept (2).
-.LP
+.PP
 The BSD prototype for
 .BR gethostbyaddr ()
 uses
-.I const char *
+.I "const char\ *"
 for the first argument.
-.LP
-POSIX.1-2001 marks
-.BR gethostbyaddr ()
-and
-.BR gethostbyname ()
-obsolescent.
-See
-.BR getaddrinfo (3),
-.BR getnameinfo (3),
-.BR gai_strerror (3).
-.SS "System V/POSIX Extension"
+.SS System V/POSIX extension
 POSIX requires the
 .BR gethostent ()
-call, that should return the next entry in the host data base.
+call, which should return the next entry in the host data base.
 When using DNS/BIND this does not make much sense, but it may
 be reasonable if the host data base is a file that can be read
 line by line.
-On many systems a routine of this name reads
+On many systems, a routine of this name reads
 from the file
 .IR /etc/hosts .
-.\" e.g., Linux, FreeBSD, Unixware, HP-UX
+.\" e.g., Linux, FreeBSD, UnixWare, HP-UX
 It may be available only when the library was built without DNS support.
 .\" e.g., FreeBSD, AIX
 The glibc version will ignore ipv6 entries.
 This function is not reentrant,
 and glibc adds a reentrant version
 .BR gethostent_r ().
-.SS "GNU Extensions"
+.SS GNU extensions
 Glibc2 also has a
 .BR gethostbyname2 ()
 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 (),
 .BR gethostbyname_r ()
 and
 .BR gethostbyname2_r ().
-These return 0 on success and non-zero on error.
-The result of the call
-is now stored in the struct with address
-.IR ret .
-After the call,
-.RI * result
-will be NULL on error or point to the result on success.
-Auxiliary data is stored in the buffer
+The caller supplies a
+.I hostent
+structure
+.I ret
+which will be filled in on success, and a temporary work buffer
 .I buf
-of length
+of size
 .IR buflen .
-(If the buffer is too small, these functions will return
-.BR ERANGE .)
-No global variable
+After the call,
+.I result
+will point to the result on success.
+In case of an error
+or if no entry is found
+.I result
+will be NULL.
+The functions return 0 on success and a nonzero error number on failure.
+In addition to the errors returned by the nonreentrant
+versions of these functions, if
+.I buf
+is too small, the functions will return
+.BR ERANGE ,
+and the call should be retried with a larger buffer.
+The global variable
 .I h_errno
-is modified, but the address of a variable in which to store error numbers
+is not modified, but the address of a variable in which to store error numbers
 is passed in
 .IR h_errnop .
-.SH "SEE ALSO"
+.SH BUGS
+.BR gethostbyname ()
+does not recognize components of a dotted IPv4 address string
+that are expressed in hexadecimal.
+.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973
+.SH SEE ALSO
 .BR getaddrinfo (3),
-.BR getipnodebyaddr (3),
-.BR getipnodebyname (3),
+.\" .BR getipnodebyaddr (3),
+.\" .BR getipnodebyname (3),
 .BR getnameinfo (3),
+.BR inet (3),
 .BR inet_ntop (3),
 .BR inet_pton (3),
 .BR resolver (3),