Penguin
Blame: gethostbyaddr(3)
EditPageHistoryDiffInfoLikePages
Annotated edit history of gethostbyaddr(3) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 GETHOSTBYNAME
2 !!!GETHOSTBYNAME
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 RETURN VALUE
7 ERRORS
8 FILES
9 CONFORMING TO
10 NOTES
11 SEE ALSO
12 ----
13 !!NAME
14
15
16 gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entry
17 !!SYNOPSIS
18
19
20 __#include
21 __''name''__);
22 struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);
23 #include
24 __''addr''__,
25 int__ ''len''__, int__ ''type''__);
26 void sethostent(int__ ''stayopen''__);
27 void endhostent(void);
28 void herror(const char *__''s''__);
29 const char * hstrerror(int__ ''err''__);
30 __
31 !!DESCRIPTION
32
33
34 The __gethostbyname()__ function returns a structure of
35 type ''hostent'' for the given host ''name''. Here
36 ''name'' is either a host name, or an IPv4 address in
37 standard dot notation, or an IPv6 address in colon (and
38 possibly dot) notation. (See RFC 1884 for the description of
39 IPv6 addresses.) If ''name'' is an IPv4 or IPv6 address,
40 no lookup is performed and __gethostbyname__() simply
41 copies ''name'' into the ''h_name'' field and its
42 ''struct in_addr'' equivalent into the
43 ''h_addr_list[[0]'' field of the returned ''hostent''
44 structure. If ''name'' doesn't end in a dot and the
45 environment variable __HOSTALIASES__ is set, the alias
46 file pointed to by __HOSTALIASES__ will first be searched
47 for ''name'' (see hostname(7) for the file
48 format). The current domain and its parents are searched
49 unless ''name'' ends in a dot.
50
51
52 The __gethostbyaddr()__ function returns a structure of
53 type ''hostent'' for the given host address ''addr''
54 of length ''len'' and address type ''type''. The only
55 valid address type is currently __AF_INET__.
56
57
58 The __sethostent()__ function specifies, if
59 ''stayopen'' is true (1), that a connected TCP socket
60 should be used for the name server queries and that the
61 connection should remain open during successive queries.
62 Otherwise, name server queries will use UDP
63 datagrams.
64
65
66 The __endhostent()__ function ends the use of a TCP
67 connection for name server queries.
68
69
70 The (obsolete) __herror()__ function prints the error
71 message associated with the current value of ''h_errno''
72 on stderr.
73
74
75 The (obsolete) __hstrerror()__ function takes an error
76 number (typically ''h_errno'') and returns the
77 corresponding message string.
78
79
80 The domain name queries carried out by
81 __gethostbyname()__ and __gethostbyaddr()__ use a
82 combination of any or all of the name server
83 named(8), a broken out line from ''/etc/hosts'',
84 and the Network Information Service (NIS or YP), depending
85 upon the contents of the ''order'' line in
2 perry 86 ''/etc/host.conf''. (See resolv+(8)). The default
1 perry 87 action is to query named(8), followed by
88 ''/etc/hosts''.
89
90
91 The ''hostent'' structure is defined in
92 '''' as follows:
93
94
95 struct hostent {
96 char *h_name; /* official name of host */
97 char **h_aliases; /* alias list */
98 int h_addrtype; /* host address type */
99 int h_length; /* length of address */
100 char **h_addr_list; /* list of addresses */
101 }
102 #define h_addr h_addr_list[[0] /* for backward compatibility */
103
104
105 The members of the ''hostent'' structure
106 are:
107
108
109 ''h_name''
110
111
112 The official name of the host.
113
114
115 ''h_aliases''
116
117
118 A zero-terminated array of alternative names for the
119 host.
120
121
122 ''h_addrtype''
123
124
125 The type of address; always __AF_INET__ at
126 present.
127
128
129 ''h_length''
130
131
132 The length of the address in bytes.
133
134
135 ''h_addr_list''
136
137
138 A zero-terminated array of network addresses for the host in
139 network byte order.
140
141
142 ''h_addr''
143
144
145 The first address in ''h_addr_list'' for backward
146 compatibility.
147 !!RETURN VALUE
148
149
150 The __gethostbyname()__ and __gethostbyaddr()__
151 functions return the ''hostent'' structure or a NULL
152 pointer if an error occurs. On error, the ''h_errno''
153 variable holds an error number.
154 !!ERRORS
155
156
157 The variable ''h_errno'' can have the following
158 values:
159
160
161 __HOST_NOT_FOUND__
162
163
164 The specified host is unknown.
165
166
167 __NO_ADDRESS__ or __NO_DATA__
168
169
170 The requested name is valid but does not have an IP
171 address.
172
173
174 __NO_RECOVERY__
175
176
177 A non-recoverable name server error occurred.
178
179
180 __TRY_AGAIN__
181
182
183 A temporary error occurred on an authoritative name server.
184 Try again later.
185 !!FILES
186
187
188 ''/etc/host.conf''
189
190
191 resolver configuration file
192
193
194 ''/etc/hosts''
195
196
197 host database file
198 !!CONFORMING TO
199
200
201 BSD 4.3.
202 !!NOTES
203
204
205 The functions __gethostbyname__() and
206 __gethostbyaddr__() may return pointers to static data,
207 which may be overwritten by later calls. Copying the
208 ''struct hostent'' does not suffice, since it contains
209 pointers - a deep copy is required.
210
211
212 The SUS-v2 standard is buggy and declares the ''len''
213 parameter to be of type ''size_t''. (That is wrong,
214 because it has to be ''int'', and ''size_t'' is not.
215 The Austin draft makes it ''socklen_t'', which is
216 OK.)
217
218
219 Glibc2 also has a
220
221
222 __struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);
223 __that works like __gethostbyname()__, but permits to specify the address family to which the address must belong.
224
225
226 The Austin draft marks __gethostbyaddr()__ and
227 __gethostbyname()__ legacy, and introduces
228
229
230 __struct hostent *getipnodebyaddr (const void *restrict__ ''addr''__,
231 socklen_t__ ''len''__, int__ ''type''__, int *restrict__ ''error_num''__);
232 struct hostent *getipnodebyname (const char *__''name''__,
233 int__ ''type''__, int__ ''flags''__, int *__''error_num''__);
234 __
235 !!SEE ALSO
236
237
238 resolver(3), hosts(5), hostname(7),
2 perry 239 resolv+(8), named(8)
1 perry 240 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.