.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" 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. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat May 22 18:43:54 1993, David Metcalfe .\" Modified Sun Jul 25 10:42:30 1993, Rik Faith (faith@cs.unc.edu) .\" Modified Sun Feb 16 13:23:10 1997, Andries Brouwer (aeb@cwi.nl) .\" .TH GETHOSTBYNAME 3 "April 19, 1993" "BSD" "Linux Programmer's Manual" .SH NAME gethostbyname, gethostbyaddr, sethostent, endhostent, herror \- get network host entry .SH SYNOPSIS .nf .B #include .B extern int h_errno; .sp .BI "struct hostent *gethostbyname(const char *" name ); .sp .B #include " " /* for AF_INET */ .BI "struct hostent *gethostbyaddr(const char *" addr ", int " len ", int " type ); .sp .BI "void sethostent(int " stayopen ); .sp .B void endhostent(void); .sp .BI "void herror(const char *" s ); .fi .SH DESCRIPTION The \fBgethostbyname()\fP function returns a structure of type \fIhostent\fP for the given host \fIname\fP. Here \fIname\fP 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.) If \fIname\fP doesn't end in a dot and the environment variable \fBHOSTALIASES\fP is set, the alias file pointed to by \fBHOSTALIASES\fP will first be searched for \fIname\fP. (See .BR hostname (7) for the file format.) The current domain and its parents are searched unless \fIname\fP ends in a dot. .PP The \fBgethostbyaddr()\fP function returns a structure of type \fIhostent\fP for the given host address \fIaddr\fP of length \fIlen\fP and address type \fItype\fP. The only valid address type is currently AF_INET. .PP The \fBsethostent()\fP function specifies, if \fIstayopen\fP is true (1), that a connected TCP socket should be used for the name server queries and that the connection should remain open during successive queries. Otherwise, name server queries will use UDP datagrams. .PP The \fBendhostent()\fP function ends the use of a TCP connection for name server queries. .PP The \fBherror()\fP function prints the error message associated with the current value of \fIh_errno\fP on stderr. .PP The domain name queries carried out by \fBgethostbyname()\fP and \fBgethostbyaddr()\fP use a combination of any or all of the name server \fBnamed\fP(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 \fI/etc/host.conf\fP. (See .BR resolv+ (8)). The default action is to query \fBnamed\fP(8), followed by \fI/etc/hosts\fP. .PP The \fIhostent\fP structure is defined in \fI\fP as follows: .sp .RS .nf .ne 7 .ta 8n 16n 32n 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 */ } #define h_addr h_addr_list[0] /* for backward compatibility */ .ta .fi .RE .PP The members of the \fIhostent\fP structure are: .TP .I h_name The official name of the host. .TP .I h_aliases A zero-terminated array of alternative names for the host. .TP .I h_addrtype The type of address; always AF_INET at present. .TP .I h_length The length of the address in bytes. .TP .I h_addr_list A zero-terminated array of network addresses for the host in network byte order. .TP .I h_addr The first address in \fIh_addr_list\fP for backward compatibility. .SH "RETURN VALUE" The \fBgethostbyname()\fP and \fBgethostbyaddr()\fP functions return the \fIhostent\fP structure or a NULL pointer if an error occurs. On error, the \fIh_errno\fP variable holds an error number. .SH "ERRORS" The variable \fIh_errno\fP can have the following values: .TP .B HOST_NOT_FOUND The specified host is unknown. .TP .B NO_ADDRESS The requested name is valid but does not have an IP address. .TP .B NO_RECOVERY A non-recoverable name server error occurred. .TP .B TRY_AGAIN A temporary error occurred on an authoritative name server. Try again later. .SH FILES .TP .I /etc/host.conf resolver configuration file .TP .I /etc/hosts host database file .SH "CONFORMING TO" BSD 4.3 .SH "SEE ALSO" .BR resolver (3), .BR hosts (5), .BR hostname (7), .BR resolv+ (8), .BR named (8)