File: gethostbyname.3

package info (click to toggle)
manpages-ja 0.5.0.0.20100315-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 21,156 kB
  • ctags: 1
  • sloc: sh: 13,935; perl: 157; makefile: 114
file content (458 lines) | stat: -rw-r--r-- 11,716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
.\" 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 1993-05-22, David Metcalfe
.\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu)
.\" Modified 1997-02-16, Andries Brouwer (aeb@cwi.nl)
.\" Modified 1998-12-21, Andries Brouwer (aeb@cwi.nl)
.\" Modified 2000-08-12, Andries Brouwer (aeb@cwi.nl)
.\" Modified 2001-05-19, Andries Brouwer (aeb@cwi.nl)
.\" Modified 2002-08-05, Michael Kerrisk
.\" Modified 2004-10-31, Andries Brouwer
.\"
.\" Japanese Version Copyright (c) 1998-2000 NAKANO Takeo all rights reserved.
.\" Translated 1998-04-30, NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Modified 1998-12-06, NAKANO Takeo
.\" Updated & Modified 1999-10-12, NAKANO Takeo
.\" Updated & Modified 2001-07-01, Yuichi SATO <ysato@h4.dion.ne.jp>
.\" Updated & Modified 2002-01-03, Yuichi SATO
.\" Updated & Modified 2003-11-27, Yuichi SATO <ysato444@yahoo.co.jp>
.\" Updated & Modified 2005-01-10, Yuichi SATO
.\" Updated 2006-01-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2007-06-11, Akihiro MOTOKI, LDP v2.54
.\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
.\"
.TH GETHOSTBYNAME 3 2009-03-15 "" "Linux Programmer's Manual"
.SH ̾
gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
h_errno,
herror, hstrerror,
gethostbyaddr_r,
gethostbyname2, gethostbyname2_r, gethostbyname_r,
gethostent_r \- ͥåȥΥۥȤΥȥ
.SH 
.nf
.B #include <netdb.h>
.B extern int h_errno;
.sp
.BI "struct hostent *gethostbyname(const char *" name );
.sp
.BR "#include <sys/socket.h>" "       /* AF_INET Ȥ */"
.BI "struct hostent *gethostbyaddr(const void *" addr ,
.BI "                              socklen_t " len ", int " type );
.sp
.BI "void sethostent(int " stayopen );
.sp
.B void endhostent(void);
.sp
.BI "void herror(const char *" s );
.sp
.BI "const char *hstrerror(int " err );
.sp
/* System V/POSIX ĥ */
.br
.B struct hostent *gethostent(void);
.sp
/* GNU ĥ */
.br
.BI "struct hostent *gethostbyname2(const char *" name ", int " af );
.sp
.B "int gethostent_r("
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
.BI "        struct hostent **" result ", int *" h_errnop );
.sp
.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 );
.sp
.BI "int gethostbyname_r(const char *" name ,
.BI "        struct hostent *" ret ", char *" buf ", size_t " buflen ,
.BI "        struct hostent **" result ", int *" h_errnop );
.sp
.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
.sp
.in -4n
glibc εǽޥ׷
.RB ( feature_test_macros (7)
):
.in
.sp
.ad l
.BR gethostbyname2 (),
.BR gethostent_r (),
.BR gethostbyaddr_r (),
.BR gethostbyname_r (),
.BR gethostbyname2_r ():
_BSD_SOURCE || _SVID_SOURCE
.ad b
.SH 
.BR gethostbyname* ()

.BR gethostbyaddr* ()
ϲΤΤǤ롣
ץꥱǤϡ
.BR getaddrinfo (3)

.BR getnameinfo (3)
Ѥ뤳ȡ

.BR gethostbyname ()
ؿͿ줿ۥ̾
.I name
б빽¤
.I hostent
֤
.I name
ˤϥۥ̾ɥåȶڤ IPv4 ɥ쥹
.RB ( inet_addr (3)
)ڤ IPv6 ɥ쥹 (餯ɥåȶڤǤ)
Τ줫ꤹ
(IPv6 ɥ쥹εˡˤĤƤ RFC\ 1884 򻲹ͤˤƤۤ)
.I name
 IPv4  IPv6 Υɥ쥹ä硢
̾ (lookup) ϹԤʤξˤϡ
.BR gethostbyname ()

.I name
򤽤Τޤ
.I hostent
¤Τ
.I h_name
եɤ˥ԡ

.I name

.I struct in_addr
ɽǡ
.I hostent
¤Τ
.I h_addr_list[0]
եɤơ
.I hostent
¤Τ֤
.I name
ɥåȤǽλƤơĴĶѿ
.B HOSTALIASES
ꤵƤ硢ޤ
.B HOSTALIASES
ǻꤵƤ륨ꥢե뤫
.I name
Υȥ꤬ (եΥեޥåȤˤĤƤ
.BR hostname (7)
򻲾ȤΤ)
.I name
ɥåȤǽλƤʤСߤΥɥᥤȤοƥɥᥤ󤬸롣
.PP
.BR gethostbyaddr ()
ؿͿ줿ۥȥɥ쥹
.I addr
(Ĺ \fIlen\fP  \fItype\fP) б빽¤
.I hostent
֤
Ѥ뤳ȤΤǤ륿פ
.B AF_INET

.B AF_INET6
Ǥ롣
ۥȥɥ쥹ϥɥ쥹פ˰¸
¤ΤؤΥݥ󥿤Ǥ롣
㤨Сɥ쥹
.B AF_INET
ФƤ
.RB ( inet_addr (3)
θƤӽФ)
\fIstruct in_addr *\fP Ǥ롣
.PP
.BR sethostent ()
ؿϡ͡ॵФؤ³֤ꤹ롣
.I stayopen
 (1) ʤС͡ॵФؤ䤤碌ˤϡ
³줿 TCP åȤѤϢ³䤤碌δ֤³ݻ롣
ʤХ͡ॵФؤ䤤碌 UDP ǡѤ롣
.PP
.BR endhostent ()
ؿϥ͡ॵФؤ䤤碌Ѥ TCP ³Ѥλ롣
.PP
(ѻͽ)
.BR herror ()
ؿϸߤ
.I h_errno
б륨顼åɸ२顼 \fIstderr\fP ˽Ϥ롣
.PP
(ѻͽ)
.BR hstrerror ()
ؿϥ顼ֹ (̾ \fIh_errno\fP) ˼ꡢ
б륨顼åʸ֤
.PP
.BR gethostbyname ()

.BR gethostbyaddr ()
ˤäƼ¹Ԥɥᥤ̾䤤碌Ǥϡ͡ॵ
.BR named (8)
.I /etc/hosts
Υǡԡ
Network Information Service (NIS ޤ YP)
Ȥ߹碌ƻѤ롣Ѥ뤫ϡ
.I /etc/host.conf

.I order
ԤƤˤޤ롣
.\" (ܤ
.\" .BR resolv+ (8)
.\" 򻲾)
ǥեȤǤϡޤ
.BR named (8)
䤤碌Ԥ
.I /etc/hosts
򻲾Ȥ롣
.PP
.I hostent
¤Τ
.I <netdb.h>
ǰʲΤ褦Ƥ:
.sp
.in +4n
.nf
.ne 7
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] /* ȤθߴΤ */
.fi
.in
.PP
.I hostent
¤ΤΥФϰʲ̤ꡣ
.TP
.I h_name
ۥȤ̾ (official name)
.TP
.I h_aliases
ۥȤ̾ NULL ݥ󥿤ǽü롣
.TP
.I h_addrtype
ɥ쥹ΥסߤϤ٤
.B AF_INET
ޤ
.B AF_INET6
Ǥ롣
.TP
.I h_length
Хñ̤ɽɥ쥹Ĺ
.TP
.I h_addr_list
ۥȤΥͥåȥɥ쥹ؤΥݥ󥿤
 NULL ݥ󥿤ǽü롣
ͥåȥɥ쥹ϥͥåȥХȥǤ롣
.TP
.I h_addr
.I h_addr_list
κǽΥɥ쥹ȤθߴݤĤΤΤǤ롣
.SH ֤
.BR gethostbyname ()

.BR gethostbyaddr ()
ؿ
.I hostent
¤Τ֤顼ä NULL ݥ󥿤֤顼κݤˤ
.I h_errno
ѿ顼ֹݻ롣
֤ͤ NULL Ǥʤ硢Ūǡݥ󥿤ǻؤƤ뤳Ȥ⤢롣
ʲΡաפ򻲾Ȥ뤳ȡ
.SH 顼
.I h_errno
ѿϰʲͤꤦ롣
.TP
.B HOST_NOT_FOUND
ꤷۥȤĤʤ
.TP
.B NO_ADDRESS " ޤ " NO_DATA
ꤷ̾ͭ IP ɥ쥹äƤʤ
.TP
.B NO_RECOVERY
͡ॵФǽʥ顼ä
.TP
.B TRY_AGAIN
authoritative ʥ͡ॵФǰŪʥ顼ä
֤򤪤Ƥ⤦ٻȡ
.SH ե
.TP
.I /etc/host.conf
̾ե
.TP
.I /etc/hosts
ۥȤΥǡ١ե
.TP
.I /etc/nsswitch.conf
͡ॵӥ
.SH 
POSIX.1-2001 Ǥϡ
.BR gethostbyname (),
.BR gethostbyaddr (),
.BR sethostent (),
.BR endhostent (),
.BR gethostent (),
.I h_errno
ꤵƤꡢ
.BR gethostbyaddr ()

.BR gethostbyname ()
ѻͽǤȤƤ롣
POSIX.1-2008 Ǥ
.BR gethostbyname (),
.BR gethostbyaddr (),
.I h_errno
λͤƤ롣
ˡ
.BR getaddrinfo (3)

.BR getnameinfo (3)
λѤ侩Ƥ롣
.SH 
.BR gethostbyname ()

.BR gethostbyaddr ()
ؿŪǡؤΥݥ󥿤֤
Υݥ󥿤ϡθθƤӽФǾ񤭤뤫⤷ʤ
.I hostent
¤Τϥݥ󥿤ޤǤΤǡ¤ΤΥԡǤԽʬǤ;
꿼ԡɬפǤ롣
.LP
ꥸʥ BSD μǤϡ
.BR gethostbyname ()

.I len

.I int
Ǥä
SUSv2 ɸϥХ¿
.BR gethostbyaddr ()

.I len
ѥ᡼
.I size_t
ȤƤ롣
(ϸǡ
.I size_t
ǤϤʤ
.I int
ǤʤФʤʤ
POSIX.1-2001 ǤϤ
.I socklen_t
ȤƤ뤬 OK)
.BR accept (2)
⻲ȡ
.LP
.BR gethostbyaddr ()
 BSD ΥץȥפϡǽΰȤ
.I const char *
Ȥ
.SS "System V/POSIX ĥ"
POSIX Ǥϡ
.BR gethostent ()
ɬܤȤƤ롣
δؿϥۥȥǡ١μΥȥ֤
DNS/BIND ȤϤޤ̣ʤ
ۥȥǡ١ 1 Ԥɤ߹ޤեǤϰ̣롣
¿ΥƥǤϡ̾Υ롼ϥե
.I /etc/hosts
ɤ߹ࡣ
.\" 㤨СLinux, FreeBSD, Unixware, HP-UX
DNS ݡȤʤǥ饤֥꤬ӥɤ줿ˤΤѲǽǤ롣
.\" 㤨СFreeBSD, AIX
glibc Ǥ ipv6 ȥ̵뤹롣
δؿϥꥨȥ (reentrant) ǤϤʤ
glibc ˤϥꥨȥǤ
.BR gethostent_r ()
ɲä줿
.SS "GNU ĥ"
glibc2 ˤ
.BR gethostbyname2 ()
⤢ꡢ
.BR gethostbyname ()
Ʊ褦ư뤬
ϥɥ쥹°륢ɥ쥹եߥ꡼ꤹ뤳ȤǤ롣
.LP
glibc2 ˤϥꥨȥȤ
.BR gethostent_r (),
.BR gethostbyaddr_r (),
.BR gethostbyname_r ()

.BR gethostbyname2_r ()
⤢롣
ƤӽФ¦ϡ˷̤Ǽ
.I hostent
¤
.I ret
ȡ礭
.I buflen
ΰŪʺȥХåե
.I buf
󶡤롣
뽪λ塢
.I result
Ϸ̤ؤƤ롣
顼ξ硢ޤϥȥ꤬Ĥʤä硢
.I result
 NULL ˤʤ롣
δؿϡ 0 ֤Ԥξ 0 ʳΥ顼ֹ֤
δؿΥꥨȥȤǤʤС֤顼˲äơ
δؿϡ
.I buf

.B ERANGE
֤ξϤä礭ʥХåեѰդ
ؿƤӽФٹԤ٤Ǥ롣
ѿ
.I h_errno
ѹʤ顼ֹǼѿΥɥ쥹
.I h_errnop
Ϥ롣
.SH Х
.BR gethostbyname ()
ϡ16ʿɽΥɥåȶڤ IPv4 ɥ쥹ʸǤǧʤ
.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973
.SH Ϣ
.BR getaddrinfo (3),
.\" .BR getipnodebyaddr (3),
.\" .BR getipnodebyname (3),
.BR getnameinfo (3),
.BR inet (3),
.BR inet_ntop (3),
.BR inet_pton (3),
.BR resolver (3),
.BR hosts (5),
.BR nsswitch.conf (5),
.BR hostname (7),
.BR named (8)
.\" .BR resolv+ (8)