1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified 2004-10-31 by aeb
30 .\" Japanese Version Copyright (c) 1998 Shinji Orito all rights reserved.
31 .\" Translated Mon May 25 21:27:03 JST 1998
32 .\" by Shinji Orito <shinji@os.gulf.or.jp>
33 .\" Updated & Modified Thu Feb 17 03:58:45 JST 2005
34 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
36 .\"WORD: resolver ¥ì¥¾¥ë¥Ð (¥ê¥¾¥ë¥Ð)
37 .\"WORD: override ¥ª¡¼¥Ð¡¼¥é¥¤¥É
38 .\"WORD: call ¸Æ¤Ó½Ð¤·¡¢¸Æ¤Ó½Ð¤¹
39 .\"WORD: fully qualified domain name ´°Á´½¤¾þ¥É¥á¥¤¥ó̾(FQDN)
42 .\"WORD: query Ì䤤¹ç¤ï¤»¡¢Ì䤤¹ç¤ï¤»¤ë
43 .\"WORD: buffer ¥Ð¥Ã¥Õ¥¡¡¼
44 .\"WORD: lower-level routines ²¼°Ì¥ë¡¼¥Á¥ó
45 .\"WORD: limit of the array ÇÛÎó¤ÎÈÏ°Ï
46 .\"WORD: state information ¾õÂ֤ξðÊó
47 .\"WORD: bitwise ``or'' ¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýÏÂ
49 .\"WORD: authoritative ¸¢°ÒÉÕ¤±¤µ¤ì¤¿
50 .\"WORD: recursion desired bit ºÆµ¢Í×µá¥Ó¥Ã¥È
51 .\"WORD: single component names °ìÉôʬ¤«¤é¤Ê¤ë̾Á°
53 .TH RESOLVER 3 2008-11-07 "GNU" "Linux Programmer's Manual"
56 .\"O res_init, res_query, res_search, res_querydomain, res_mkquery, res_send,
57 .\"O dn_comp, dn_expand \- resolver routines
58 res_init, res_query, res_search, res_querydomain, res_mkquery, res_send, dn_comp, dn_expand \- ¥ì¥¾¥ë¥Ð¡¦¥ë¡¼¥Á¥ó
62 .B #include <netinet/in.h>
63 .B #include <arpa/nameser.h>
64 .B #include <resolv.h>
65 .B extern struct state _res;
67 .B int res_init(void);
69 .BI "int res_query(const char *" dname ", int " class ", int " type ,
71 .BI "unsigned char *" answer ", int " anslen );
74 .BI "int res_search(const char *" dname ", int " class ", int " type ,
76 .BI "unsigned char *" answer ", int " anslen );
79 .BI "int res_querydomain(const char *" name ", const char *" domain ,
81 .BI "int " class ", int " type ", unsigned char *" answer ,
85 .BI "int res_mkquery(int " op ", const char *" dname ", int " class ,
87 .BI "int " type ", char *" data ", int " datalen ", struct rrec *" newrr ,
88 .BI "char *" buf ", int " buflen );
91 .BI "int res_send(const char *" msg ", int " msglen ", char *" answer ,
96 .BI "int dn_comp(unsigned char *" exp_dn ", unsigned char *" comp_dn ,
98 .BI "int " length ", unsigned char **" dnptrs ", unsigned char *" exp_dn ,
99 .BI "unsigned char **" lastdnptr );
102 .BI "int dn_expand(unsigned char *" msg ", unsigned char *" eomorig ,
104 .BI "unsigned char *" comp_dn ", char *" exp_dn ,
109 .\"O Link with \fI\-lresolv\fP.
110 \fI\-lresolv\fP ¤Ç¥ê¥ó¥¯¤¹¤ë¡£
113 .\"O These functions make queries to and interpret the responses from Internet
114 .\"O domain name servers.
115 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¥¤¥ó¥¿¡¼¥Í¥Ã¥È¤Î¥É¥á¥¤¥ó¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤ËÌ䤤¹ç¤ï¤»¡¢
120 .\"O function reads the configuration files (see
121 .\"O resolv.conf(5)) to get the default domain name, search order and name
122 .\"O server address(es).
123 .\"O If no server is given, the local host is tried.
125 ´Ø¿ô¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥É¥á¥¤¥ó̾¡¢¸¡º÷½ç¡¢¥Í¡¼¥à¥µ¡¼¥Ð¡¼
126 ¥¢¥É¥ì¥¹¤òÆÀ¤ë¤¿¤á¤ËÀßÄê¥Õ¥¡¥¤¥ë (resolv.conf(5) »²¾È) ¤òÆɤࡣ
127 ¤â¤·¥µ¡¼¥Ð¡¼¤¬¼¨¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¥í¡¼¥«¥ë¥Û¥¹¥È¤ò»î¤¹¡£
128 .\"O If no domain is given, that associated with the local host is used.
129 .\"O It can be overridden with the environment variable
130 .\"O .BR LOCALDOMAIN .
132 .\"O is normally executed by the first call to one of the
133 .\"O other functions.
134 ¥É¥á¥¤¥ó¤¬¼¨¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¥í¡¼¥«¥ë¥Û¥¹¥È¤ËÉÕ¤±¤é¤ì¤¿¥É¥á¥¤¥ó¤òÍѤ¤¤ë¡£
137 ¤Ç¥ª¡¼¥Ð¡¼¥é¥¤¥É¤Ç¤¤ë¡£
139 ¤Ï¡¢¸å½Ò¤¹¤ë´Ø¿ô¤Î¤É¤ì¤«¤¬ºÇ½é¤Ë¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¡¢¤½¤Î´Ø¿ô
143 .\"O .BR res_query ()
144 .\"O function queries the name server for the
145 .\"O fully qualified domain name \fIname\fP of specified \fItype\fP and
147 .\"O The reply is left in the buffer \fIanswer\fP of length
148 .\"O \fIanslen\fP supplied by the caller.
150 ´Ø¿ô¤Ï¡¢»ØÄꤵ¤ì¤¿ \fItype\fP ¤È \fIclass\fP ¤Î
151 ´°Á´½¤¾þ¥É¥á¥¤¥ó̾ (FQDN) \fIname\fP ¤ò¡¢¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤ØÌ䤤¹ç¤ï¤»¤ë¡£
152 ±þÅú¤Ï¡¢¸Æ¤Ó½Ð¤·¤¿Â¦¤Ë¤è¤Ã¤ÆÍÑ°Õ¤µ¤ì¤ëŤµ \fIanslen\fP ¤Î \fIanswer\fP
153 ¥Ð¥Ã¥Õ¥¡¡¼¤Ë»Ä¤µ¤ì¤ë¡£
156 .\"O .BR res_search ()
157 .\"O function makes a query and waits for the response
159 .\"O .BR res_query (),
160 .\"O but in addition implements the default and search
161 .\"O rules controlled by
165 .\"O (see description of
166 .\"O \fI_res\fP options below).
168 ´Ø¿ô¤Ï¡¢Ì䤤¹ç¤ï¤»¤ò¹Ô¤¤
171 ÂԤĤ¬¡¢¤µ¤é¤Ë¥Ç¥Õ¥©¥ë¥È¤ò¼ÂÁõ¤·¤Æ¤ª¤ê
175 ¤Ë¤è¤Ã¤Æµ¬Äꤵ¤ì¤ë¸¡º÷¥ë¡¼¥ë¤òŬÍѤ¹¤ë¡£
176 (²¼µ \fI_res\fP ¥ª¥×¥·¥ç¥ó¤ÎÀâÌÀ¤ò»²¾È)
178 .\"O The \fBres_querydomain\fP() function makes a query using
179 .\"O .BR res_query ()
180 .\"O on the concatenation of \fIname\fP and \fIdomain\fP.
181 .BR res_querydomain ()
182 ´Ø¿ô¤Ï \fIname\fP ¤È \fIdomain\fP ¤Î·ë¹ç¤Ë
184 ¤òÍѤ¤¤ÆÌ䤤¹ç¤ï¤»¤ò¹Ô¤¦¡£
186 .\"O The following functions are lower-level routines used by
187 .\"O .BR res_query ().
190 ¤Ç»È¤ï¤ì¤ë²¼°Ì¥ë¡¼¥Á¥ó¤Ç¤¢¤ë¡£
193 .\"O .BR res_mkquery ()
194 .\"O function constructs a query message in \fIbuf\fP
195 .\"O of length \fIbuflen\fP for the domain name \fIdname\fP.
197 .\"O \fIop\fP is usually
199 .\"O but can be any of the types defined in
200 .\"O \fI<arpa/nameser.h>\fP. \fInewrr\fP is currently unused.
202 ´Ø¿ô¤Ï¡¢¥É¥á¥¤¥ó̾ \fIdname\fP ¤Î°Ù¤Ë¡¢Ä¹¤µ \fIbuflen\fP
203 ¤Î \fIbuf\fP ¤ËÌ䤤¹ç¤ï¤»¤ë¥á¥Ã¥»¡¼¥¸¤òºîÀ®¤¹¤ë¡£
204 Ì䤤¹ç¤ï¤»¤Î·¿ \fIop\fP ¤ÏÄ̾ï
206 ¤À¤¬¡¢ \fI<arpa/nameser.h>\fP ¤ÇÄêµÁ¤µ¤ì¤¿·¿¤Î¤É¤ì¤Ç¤âÎɤ¤¡£
207 \fInewrr\fP ¤Ï¸½ºß»ÈÍѤµ¤ì¤Æ¤¤¤Ê¤¤¡£
211 .\"O function sends a preformatted query given in
212 .\"O \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP
213 .\"O which is of length \fIanslen\fP.
215 .\"O .BR res_init (),
217 .\"O has not already been called.
219 ´Ø¿ô¤Ï¡¢Ä¹¤µ \fImsglen\fP ¤Î \fImsg\fP ¤Ë·è¤á¤é¤ì¤¿½ñ¼°
220 ¤ÇÌ䤤¹ç¤ï¤»¡¢\fIanswer\fP ¤ËŤµ \fIanslen\fP ¤Î²óÅú¤òÊÖ¤¹¡£
221 ¤Þ¤À¸Æ¤Ó½Ð¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð
227 .\"O function compresses the domain name \fIexp_dn\fP
228 .\"O and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP.
229 .\"O The compression uses an array of pointers \fIdnptrs\fP to previously
230 .\"O compressed names in the current message.
231 .\"O The first pointer points
232 .\"O to the beginning of the message and the list ends with NULL.
233 .\"O The limit of the array is specified by \fIlastdnptr\fP.
234 .\"O If \fIdnptr\fP is NULL, domain names are not compressed.
235 .\"O If \fIlastdnptr\fP is NULL, the list
236 .\"O of labels is not updated.
238 ´Ø¿ô¤Ï¥É¥á¥¤¥ó̾ \fIexp_dn\fP ¤ò°µ½Ì¤·¤Æ¡¢Ä¹¤µ \fIlength\fP
239 ¤Î¥Ð¥Ã¥Õ¥¡¡¼ \fIcomp_dn\fP ¤ËÊݸ¤¹¤ë¡£
240 °µ½Ì¤Ë¤Ï¥Ý¥¤¥ó¥¿¡¼ÇÛÎó \fIdnptrs\fP ¤òÍѤ¤¤ë¡£
241 ¤³¤ì¤é¤Î¥Ý¥¤¥ó¥¿¡¼¤Ï¡¢¸½ºß¤Î¥á¥Ã¥»¡¼¥¸¤ÎÃæ¤Ë¤¢¤ë°ÊÁ°¤Ë°µ½Ì¤µ¤ì¤¿Ì¾Á°¤ò»Ø¤¹¡£
242 ºÇ½é¤Î¥Ý¥¤¥ó¥¿¡¼¤Ï¥á¥Ã¥»¡¼¥¸¤ÎËÁƬ¤ò»Ø¤·¡¢¤½¤Î¥ê¥¹¥È¤Ï NULL ¤Ç½ª¤ï¤ë¡£
243 ÇÛÎó¤ÎÈÏ°Ï¤Ï \fIlastdnptr\fP ¤Ç·è¤á¤é¤ì¤ë¡£
244 \fIdnptr\fP ¤¬ NULL ¤Ê¤é¤Ð¥É¥á¥¤¥ó̾¤Ï°µ½Ì¤µ¤ì¤Ê¤¤¡£
245 \fIlastdnptr\fP ¤¬ NULL ¤Ê¤é¤Ð¡¢¤½¤Î¥é¥Ù¥ë¤Î¥ê¥¹¥È¤Ï¥¢¥Ã¥×¥Ç¡¼¥È¤µ¤ì¤Ê¤¤¡£
248 .\"O .BR dn_expand ()
249 .\"O function expands the compressed domain name
250 .\"O \fIcomp_dn\fP to a full domain name, which is placed in the buffer
251 .\"O \fIexp_dn\fP of size \fIlength\fP.
252 .\"O The compressed name is contained
253 .\"O in a query or reply message, and \fImsg\fP points to the beginning of
256 ´Ø¿ô¤Ï¡¢°µ½Ì¤µ¤ì¤¿¥É¥á¥¤¥ó̾ \fIcomp_dn\fP ¤«¤é¥µ¥¤¥º
257 ¤¬ \fIlength\fP ¤Î \fIexp_dn\fP ¥Ð¥Ã¥Õ¥¡¡¼¤ËÀµ¼°¤Ê¥É¥á¥¤¥ó̾¤òŸ³«¤¹¤ë¡£
258 ¤½¤Î°µ½Ì¤µ¤ì¤¿Ì¾Á°¤Ï¡¢Ì䤤¹ç¤ï¤»¡¢¤Þ¤¿¤Ï±þÅú¥á¥Ã¥»¡¼¥¸¤Ë´Þ¤Þ¤ì¤Æ¤¤¤Æ¡¢
259 \fImsg\fP ¤¬¥á¥Ã¥»¡¼¥¸¤ÎËÁƬ¤ò»Ø¤¹¡£
261 .\"O The resolver routines use global configuration and state information
262 .\"O contained in the structure \fI_res\fP, which is defined in
263 .\"O \fI<resolv.h>\fP.
264 .\"O The only field that is normally manipulated by the
265 .\"O user is \fI_res.options\fP.
266 .\"O This field can contain the bitwise "OR"
267 .\"O of the following options:
268 ¥ì¥¾¥ë¥Ð¡¦¥ë¡¼¥Á¥ó¤Ï¡¢\fI<resolv.h>\fP ¤ËÄêµÁ¤µ¤ì¤¿ \fI_res\fP ¹½Â¤ÂΤË
269 ´Þ¤Þ¤ì¤Æ¤¤¤ëÁ´ÂÎŪ¤ÊÀßÄê¤È¾õÂ֤ξðÊó¤ò»ÈÍѤ¹¤ë¡£
270 Ä̾ï¥æ¡¼¥¶¡¼¤ËÁàºî¤Ç¤¤ë¹àÌÜ¤Ï \fI_res.options\fP ¤À¤±¤Ç¤¢¤ë¡£
271 ¤³¤Î¹àÌܤϰʲ¼¤Î¥ª¥×¥·¥ç¥ó¤Î¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýϤˤǤ¤ë¡£
276 .\"O has been called.
278 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤Æ¤¤¤ì¤Ð¿¿¡£
281 .\"O Print debugging messages.
282 ¥Ç¥Ð¥Ã¥°¡¦¥á¥Ã¥»¡¼¥¸¤ò½ÐÎϤ¹¤ë¡£
285 .\"O Accept authoritative answers only.
288 .\"O it fins an authoritative answer or returns an error. [Not currently
290 ¸¢°ÒÉÕ¤±¤µ¤ì¤¿ (authoritative) ²óÅú¤Î¤ß¼õ¤±Æþ¤ì¤ë¡£
292 ¤Ï¡¢ºÇ½ªÅª¤Ë¸¢°ÒÉÕ¤±¤µ¤ì¤¿²óÅú¤òÆÀ¤é¤ì¤ë¤«¡¢¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë
294 [¸½ºß¼ÂÁõ¤µ¤ì¤Æ¤¤¤Ê¤¤]
297 .\"O Use TCP connections for queries rather than UDP datagrams.
298 Ì䤤¹ç¤ï¤»¤Ë UDP ¥Ç¡¼¥¿¥°¥é¥à¤Ç¤Ï¤Ê¤¯ TCP Àܳ¤òÍѤ¤¤ë¡£
301 .\"O Query primary domain name server only.
302 ¥×¥é¥¤¥Þ¥ê¡¦¥É¥á¥¤¥ó¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Î¤ßÌ䤤¹ç¤ï¤»¤ë¡£
305 .\"O Ignore truncation errors.
306 .\"O Don't retry with TCP. [Not currently
308 ÀÚ¤êµÍ¤á¥¨¥é¡¼ (truncation error) ¤ò̵»ë¤¹¤ë¡£TCP ¤Ç¥ê¥È¥é¥¤¤·¤Ê¤¤¡£
309 [¸½ºß¼ÂÁõ¤µ¤ì¤Æ¤¤¤Ê¤¤]
312 .\"O Set the recursion desired bit in queries.
313 .\"O Recursion is carried out
314 .\"O by the domain name server, not by
315 .\"O .BR res_send ().
316 .\"O [Enabled by default].
318 .\"Osato: recursion desired ¤Ï¡ÖºÆµ¢Í×µá¡×¡ÖºÆµ¢Í×˾¡×¡ÖºÆµ¢Í×ÀÁ¡×¤Ê¤É¤È
319 .\"Osato: Ìõ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤·¤¿¡£
321 ºÆµ¢Í×µá (recursion desired) ¥Ó¥Ã¥È¤òÌ䤤¹ç¤ï¤»¤ËÀßÄꤹ¤ë¡£
324 ¤Ç¤Ï¤Ê¤¯¥É¥á¥¤¥ó¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ë¤è¤Ã¤Æ¹Ô¤ï¤ì¤ë¡£
329 .\"O .BR res_search ()
330 .\"O will append the default domain name to
331 .\"O single component names, i.e., those that do not contain a dot.
332 .\"O [Enabled by default].
334 .\"Osato: single component ¤Ï¡Ö1 ¤Ä¤ÎÍ×ÁǤ«¤é¤Ê¤ë¡×¤ÎÊý¤¬¤è¤¤¤Ç¤·¤ç¤¦¤«?
338 ¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¥É¥á¥¤¥ó̾¤ò°ìÉôʬ
339 ¤Î¤ß¤«¤é¤Ê¤ë̾Á°¡¢¤¹¤Ê¤ï¤Á¥É¥Ã¥È¤ò´Þ¤Þ¤Ê¤¤Ì¾Á°¤ËÉÕ¤±²Ã¤¨¤ë¡£
345 .\"O to keep the TCP connection open between queries.
346 Ì䤤¹ç¤ï¤»Ãæ¤Ë TCP Àܳ¤òÊݤĤ¿¤á
352 .\"O .BR res_search ()
353 .\"O will search for hostnames in the current
354 .\"O domain and in parent domains.
355 .\"O This option is used by
356 .\"O .BR gethostbyname (3).
357 .\"O [Enabled by default].
360 ¤Ï¸½ºß¤Î¥É¥á¥¤¥ó¤ª¤è¤Ó¿Æ¥É¥á¥¤¥ó¤Î
361 ¥Û¥¹¥È̾¤òõ¤¹¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï
362 .BR gethostbyname (3)
365 .\"O .SH "RETURN VALUE"
369 .\"O function returns 0 on success, or \-1 if an error
372 ´Ø¿ô¤ÏÀ®¸ù¤¹¤ì¤Ð 0 ¤ò¡¢¥¨¥é¡¼¤¬È¯À¸¤¹¤ì¤Ð \-1 ¤òÊÖ¤¹¡£
374 .\"O The \fBres_query\fP(), \fBres_search\fP(),
375 .\"O .BR res_querydomain (),
376 .\"O .BR res_mkquery ()
379 .\"O functions return the length
380 .\"O of the response, or \-1 if an error occurs.
383 .BR res_querydomain (),
386 ´Ø¿ô¤Ï±þÅú¤ÎŤµ¤òÊÖ¤¹¡£
387 ¤Þ¤¿¡¢¥¨¥é¡¼¤¬È¯À¸¤¹¤ì¤Ð \-1 ¤òÊÖ¤¹¡£
392 .\"O .BR dn_expand ()
393 .\"O functions return the length
394 .\"O of the compressed name, or \-1 if an error occurs.
398 ´Ø¿ô¤Ï°µ½Ì¤µ¤ì¤¿¥É¥á¥¤¥ó̾¤ÎŤµ¤òÊÖ¤¹¡£
399 ¤Þ¤¿¡¢¥¨¥é¡¼¤¬È¯À¸¤¹¤ì¤Ð \-1 ¤òÊÖ¤¹¡£
403 .\"O /etc/resolv.conf resolver configuration file
404 /etc/resolv.conf ¥ì¥¾¥ë¥ÐÀßÄê¥Õ¥¡¥¤¥ë
405 .\"O /etc/host.conf resolver configuration file
406 /etc/host.conf ¥ì¥¾¥ë¥ÐÀßÄê¥Õ¥¡¥¤¥ë
408 .\"O .SH "CONFORMING TO"
413 .BR gethostbyname (3),