Penguin
Blame: gethostbyname(3)
EditPageHistoryDiffInfoLikePages
Annotated edit history of gethostbyname(3) version 4, including all changes. View license author blame.
Rev Author # Line
1 perry 1 !!NAME
2 gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entry
3 !!SYNOPSIS
4 SamJansen 4 __#include <netdb.h>__
5 __extern int__ ''h_errno''__;__
6
7 __struct hostent *gethostbyname(const char *__''name''__);__
8 __struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);__
9
10 __#include <sys/socket.h> /* For AF_INET */__
11 __struct hostent *gethostbyaddr(const char *__''addr''__, int__ ''len''__, int__ ''type''__);__
12 __void sethostent(int__ ''stayopen''__);__
13 __void endhostent(void);__
3 PerryLorier 14 __void herror(const char *__''s''__);__
15 __const char * hstrerror(int__ ''err''__);__
1 perry 16 !!DESCRIPTION
17
3 PerryLorier 18 The __gethostbyname()__ function returns a structure of type ''hostent'' for the given host ''name''. Here ''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.) If ''name'' is an IPv4 or IPv6 address, no lookup is performed and __gethostbyname__() simply copies ''name'' into the ''h_name'' field and its ''struct in_addr'' equivalent into the
19 ''h_addr_list[[0]'' field of the returned ''hostent'' structure. If ''name'' doesn't end in a dot and the environment variable __HOSTALIASES__ is set, the alias file pointed to by __HOSTALIASES__ will first be searched for ''name'' (see hostname(7) for the file format). The current domain and its parents are searched unless ''name'' ends in a dot.
1 perry 20
3 PerryLorier 21 The __gethostbyaddr()__ function returns a structure of type ''hostent'' for the given host address ''addr'' of length ''len'' and address type ''type''. The only valid address type is currently __AF_INET__.
1 perry 22
3 PerryLorier 23 The __sethostent()__ function specifies, if ''stayopen'' is true (1), that a connected TCP socket
24 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.
1 perry 25
3 PerryLorier 26 The __endhostent()__ function ends the use of a TCP connection for name server queries.
1 perry 27
3 PerryLorier 28 The (obsolete) __herror()__ function prints the error message associated with the current value of ''h_errno'' on stderr.
1 perry 29
3 PerryLorier 30 The (obsolete) __hstrerror()__ function takes an error number (typically ''h_errno'') and returns the corresponding message string.
1 perry 31
3 PerryLorier 32 The domain name queries carried out by __gethostbyname()__ and __gethostbyaddr()__ use a combination of any or all of the name server named(8), a broken out line from ''/etc/hosts'', and the Network Information Service (NIS or YP), depending upon the contents of the ''order'' line in
33 ''/etc/host.conf''. (See resolv+(8)). The default action is to query named(8), followed by
1 perry 34 ''/etc/hosts''.
35
3 PerryLorier 36 The ''hostent'' structure is defined in '''' as follows:
1 perry 37
38
3 PerryLorier 39 struct hostent {
40 char *h_name; /* official name of host */
41 char **h_aliases; /* alias list */
42 int h_addrtype; /* host address type */
43 int h_length; /* length of address */
44 char **h_addr_list; /* list of addresses */
45 }
46 #define h_addr h_addr_list[[0] /* for backward compatibility */
1 perry 47
3 PerryLorier 48 The members of the ''hostent'' structure are:
1 perry 49
3 PerryLorier 50 ;''h_name'': The official name of the host.
51 ;''h_aliases'': A zero-terminated array of alternative names for the host.
52 ;''h_addrtype'': The type of address; always __AF_INET__ at present.
53 ;''h_length'': The length of the address in bytes.
54 ;''h_addr_list'': A zero-terminated array of network addresses for the host in network byte order.
55 ;''h_addr'': The first address in ''h_addr_list'' for backward compatibility.
1 perry 56
57 !!RETURN VALUE
58
3 PerryLorier 59 The __gethostbyname()__ and __gethostbyaddr()__ functions return the ''hostent'' structure or a NULL
60 pointer if an error occurs. On error, the ''h_errno'' variable holds an error number.
1 perry 61
62 !!ERRORS
3 PerryLorier 63 The variable ''h_errno'' can have the following values:
1 perry 64
3 PerryLorier 65 ;__HOST_NOT_FOUND__: The specified host is unknown.
66 ;__NO_ADDRESS__ or __NO_DATA__: The requested name is valid but does not have an IP address.
67 ;__NO_RECOVERY__: A non-recoverable name server error occurred.
68 ;__TRY_AGAIN__: A temporary error occurred on an authoritative name server. Try again later.
1 perry 69 !!FILES
3 PerryLorier 70 ;''/etc/host.conf'': resolver configuration file
71 ;''/etc/hosts'': host database file
1 perry 72
73 !!CONFORMING TO
3 PerryLorier 74 BSD 4.3.
1 perry 75
76 !!NOTES
3 PerryLorier 77 The functions __gethostbyname__() and __gethostbyaddr__() may return pointers to static data,
78 which may be overwritten by later calls. Copying the ''struct hostent'' does not suffice, since it contains pointers - a deep copy is required.
1 perry 79
3 PerryLorier 80 The SUS-v2 standard is buggy and declares the ''len'' parameter to be of type ''size_t''. (That is wrong, because it has to be ''int'', and ''size_t'' is not. The Austin draft makes it ''socklen_t'', which is OK.)
1 perry 81
82 Glibc2 also has a
83
3 PerryLorier 84 __struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);__ that works like __gethostbyname()__, but permits to specify the address family to which the address must belong.
1 perry 85
3 PerryLorier 86 The Austin draft marks __gethostbyaddr()__ and __gethostbyname()__ legacy, and introduces
1 perry 87
4 SamJansen 88 __struct hostent *getipnodebyaddr (const void *restrict__ ''addr''__, socklen_t__ ''len''__, int__ ''type''__, int *restrict__ ''error_num''__);__
89 __struct hostent *getipnodebyname (const char *__''name''__, int__ ''type''__, int__ ''flags''__, int *__''error_num''__);__
1 perry 90
91 !!SEE ALSO
92
3 PerryLorier 93 resolver(3), hosts(5), hostname(7), resolv+(8), named(8)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 8 times)