Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / lwres / man / lwres_getaddrinfo.html
blobe26bcf0f85a4499c3f53aebf858519be4f7bf9c0
1 <!--
2 - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2001, 2003 Internet Software Consortium.
5 - Permission to use, copy, modify, and distribute this software for any
6 - purpose with or without fee is hereby granted, provided that the above
7 - copyright notice and this permission notice appear in all copies.
9 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 - PERFORMANCE OF THIS SOFTWARE.
16 -->
18 <!-- $Id: lwres_getaddrinfo.html,v 1.8.2.3 2004/03/15 04:45:02 marka Exp $ -->
20 <HTML
21 ><HEAD
22 ><TITLE
23 >lwres_getaddrinfo</TITLE
24 ><META
25 NAME="GENERATOR"
26 CONTENT="Modular DocBook HTML Stylesheet Version 1.73
27 "></HEAD
28 ><BODY
29 CLASS="REFENTRY"
30 BGCOLOR="#FFFFFF"
31 TEXT="#000000"
32 LINK="#0000FF"
33 VLINK="#840084"
34 ALINK="#0000FF"
35 ><H1
36 ><A
37 NAME="AEN1"
38 >lwres_getaddrinfo</A
39 ></H1
40 ><DIV
41 CLASS="REFNAMEDIV"
42 ><A
43 NAME="AEN8"
44 ></A
45 ><H2
46 >Name</H2
47 >lwres_getaddrinfo, lwres_freeaddrinfo&nbsp;--&nbsp;socket address structure to host and service name</DIV
48 ><DIV
49 CLASS="REFSYNOPSISDIV"
50 ><A
51 NAME="AEN12"
52 ></A
53 ><H2
54 >Synopsis</H2
55 ><DIV
56 CLASS="FUNCSYNOPSIS"
57 ><A
58 NAME="AEN13"
59 ></A
60 ><P
61 ></P
62 ><PRE
63 CLASS="FUNCSYNOPSISINFO"
64 >#include &lt;lwres/netdb.h&gt;</PRE
65 ><P
66 ><CODE
67 ><CODE
68 CLASS="FUNCDEF"
69 >int
70 lwres_getaddrinfo</CODE
71 >(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res);</CODE
72 ></P
73 ><P
74 ><CODE
75 ><CODE
76 CLASS="FUNCDEF"
77 >void
78 lwres_freeaddrinfo</CODE
79 >(struct addrinfo *ai);</CODE
80 ></P
81 ><P
82 ></P
83 ></DIV
84 ><P
85 >If the operating system does not provide a
86 <SPAN
87 CLASS="TYPE"
88 >struct addrinfo</SPAN
90 the following structure is used:
92 <PRE
93 CLASS="PROGRAMLISTING"
94 >struct addrinfo {
95 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
96 int ai_family; /* PF_xxx */
97 int ai_socktype; /* SOCK_xxx */
98 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
99 size_t ai_addrlen; /* length of ai_addr */
100 char *ai_canonname; /* canonical name for hostname */
101 struct sockaddr *ai_addr; /* binary address */
102 struct addrinfo *ai_next; /* next structure in linked list */
103 };</PRE
104 ></P
105 ></DIV
106 ><DIV
107 CLASS="REFSECT1"
109 NAME="AEN29"
110 ></A
111 ><H2
112 >DESCRIPTION</H2
114 ><TT
115 CLASS="FUNCTION"
116 >lwres_getaddrinfo()</TT
118 is used to get a list of IP addresses and port numbers for host
120 CLASS="PARAMETER"
122 >hostname</I
123 ></TT
125 and service
127 CLASS="PARAMETER"
129 >servname</I
130 ></TT
133 The function is the lightweight resolver's implementation of
135 CLASS="FUNCTION"
136 >getaddrinfo()</TT
138 as defined in RFC2133.
140 CLASS="PARAMETER"
142 >hostname</I
143 ></TT
147 CLASS="PARAMETER"
149 >servname</I
150 ></TT
152 are pointers to null-terminated
153 strings or
154 <SPAN
155 CLASS="TYPE"
156 >NULL</SPAN
160 CLASS="PARAMETER"
162 >hostname</I
163 ></TT
165 is either a host name or a numeric host address string: a dotted decimal
166 IPv4 address or an IPv6 address.
168 CLASS="PARAMETER"
170 >servname</I
171 ></TT
173 is either a decimal port number or a service name as listed in
175 CLASS="FILENAME"
176 >/etc/services</TT
177 >.</P
179 ><TT
180 CLASS="PARAMETER"
182 >hints</I
183 ></TT
185 is an optional pointer to a
186 <SPAN
187 CLASS="TYPE"
188 >struct addrinfo</SPAN
190 This structure can be used to provide hints concerning the type of socket
191 that the caller supports or wishes to use.
192 The caller can supply the following structure elements in
194 CLASS="PARAMETER"
196 >*hints</I
197 ></TT
201 ></P
202 ><DIV
203 CLASS="VARIABLELIST"
204 ><DL
205 ><DT
206 ><TT
207 CLASS="CONSTANT"
208 >ai_family</TT
209 ></DT
210 ><DD
212 >The protocol family that should be used.
213 When
215 CLASS="CONSTANT"
216 >ai_family</TT
218 is set to
219 <SPAN
220 CLASS="TYPE"
221 >PF_UNSPEC</SPAN
223 it means the caller will accept any protocol family supported by the
224 operating system.</P
225 ></DD
226 ><DT
227 ><TT
228 CLASS="CONSTANT"
229 >ai_socktype</TT
230 ></DT
231 ><DD
233 >denotes the type of socket &mdash;
234 <SPAN
235 CLASS="TYPE"
236 >SOCK_STREAM</SPAN
238 <SPAN
239 CLASS="TYPE"
240 >SOCK_DGRAM</SPAN
243 <SPAN
244 CLASS="TYPE"
245 >SOCK_RAW</SPAN
247 &mdash; that is wanted.
248 When
250 CLASS="CONSTANT"
251 >ai_socktype</TT
253 is zero the caller will accept any socket type.</P
254 ></DD
255 ><DT
256 ><TT
257 CLASS="CONSTANT"
258 >ai_protocol</TT
259 ></DT
260 ><DD
262 >indicates which transport protocol is wanted: IPPROTO_UDP or
263 IPPROTO_TCP.
266 CLASS="CONSTANT"
267 >ai_protocol</TT
269 is zero the caller will accept any protocol.</P
270 ></DD
271 ><DT
272 ><TT
273 CLASS="CONSTANT"
274 >ai_flags</TT
275 ></DT
276 ><DD
278 >Flag bits.
279 If the
280 <SPAN
281 CLASS="TYPE"
282 >AI_CANONNAME</SPAN
284 bit is set, a successful call to
286 CLASS="FUNCTION"
287 >lwres_getaddrinfo()</TT
289 will return a null-terminated string containing the canonical name
290 of the specified hostname in
292 CLASS="CONSTANT"
293 >ai_canonname</TT
295 of the first
296 <SPAN
297 CLASS="TYPE"
298 >addrinfo</SPAN
300 structure returned.
301 Setting the
302 <SPAN
303 CLASS="TYPE"
304 >AI_PASSIVE</SPAN
306 bit indicates that the returned socket address structure is intended
307 for used in a call to
308 <SPAN
309 CLASS="CITEREFENTRY"
310 ><SPAN
311 CLASS="REFENTRYTITLE"
312 >bind</SPAN
313 >(2)</SPAN
316 In this case, if the hostname argument is a
317 <SPAN
318 CLASS="TYPE"
319 >NULL</SPAN
321 pointer, then the IP address portion of the socket
322 address structure will be set to
323 <SPAN
324 CLASS="TYPE"
325 >INADDR_ANY</SPAN
327 for an IPv4 address or
328 <SPAN
329 CLASS="TYPE"
330 >IN6ADDR_ANY_INIT</SPAN
332 for an IPv6 address.</P
334 >When
336 CLASS="CONSTANT"
337 >ai_flags</TT
339 does not set the
340 <SPAN
341 CLASS="TYPE"
342 >AI_PASSIVE</SPAN
344 bit, the returned socket address structure will be ready
345 for use in a call to
346 <SPAN
347 CLASS="CITEREFENTRY"
348 ><SPAN
349 CLASS="REFENTRYTITLE"
350 >connect</SPAN
351 >(2)</SPAN
353 for a connection-oriented protocol or
354 <SPAN
355 CLASS="CITEREFENTRY"
356 ><SPAN
357 CLASS="REFENTRYTITLE"
358 >connect</SPAN
359 >(2)</SPAN
362 <SPAN
363 CLASS="CITEREFENTRY"
364 ><SPAN
365 CLASS="REFENTRYTITLE"
366 >sendto</SPAN
367 >(2)</SPAN
371 <SPAN
372 CLASS="CITEREFENTRY"
373 ><SPAN
374 CLASS="REFENTRYTITLE"
375 >sendmsg</SPAN
376 >(2)</SPAN
378 if a connectionless protocol was chosen.
379 The IP address portion of the socket address structure will be
380 set to the loopback address if
382 CLASS="PARAMETER"
384 >hostname</I
385 ></TT
387 is a
388 <SPAN
389 CLASS="TYPE"
390 >NULL</SPAN
392 pointer and
393 <SPAN
394 CLASS="TYPE"
395 >AI_PASSIVE</SPAN
397 is not set in
399 CLASS="CONSTANT"
400 >ai_flags</TT
401 >.</P
405 CLASS="CONSTANT"
406 >ai_flags</TT
408 is set to
409 <SPAN
410 CLASS="TYPE"
411 >AI_NUMERICHOST</SPAN
413 it indicates that
415 CLASS="PARAMETER"
417 >hostname</I
418 ></TT
420 should be treated as a numeric string defining an IPv4 or IPv6 address
421 and no name resolution should be attempted.</P
422 ></DD
423 ></DL
424 ></DIV
425 ></P
427 >All other elements of the <SPAN
428 CLASS="TYPE"
429 >struct addrinfo</SPAN
430 > passed
431 via <TT
432 CLASS="PARAMETER"
434 >hints</I
435 ></TT
436 > must be zero.</P
438 >A <TT
439 CLASS="PARAMETER"
441 >hints</I
442 ></TT
443 > of <SPAN
444 CLASS="TYPE"
445 >NULL</SPAN
446 > is treated as if
447 the caller provided a <SPAN
448 CLASS="TYPE"
449 >struct addrinfo</SPAN
450 > initialized to zero
451 with <TT
452 CLASS="CONSTANT"
453 >ai_family</TT
454 >set to
456 CLASS="CONSTANT"
457 >PF_UNSPEC</TT
458 >.</P
460 >After a successful call to
462 CLASS="FUNCTION"
463 >lwres_getaddrinfo()</TT
466 CLASS="PARAMETER"
468 >*res</I
469 ></TT
471 is a pointer to a linked list of one or more
472 <SPAN
473 CLASS="TYPE"
474 >addrinfo</SPAN
476 structures.
477 Each
478 <SPAN
479 CLASS="TYPE"
480 >struct addrinfo</SPAN
482 in this list cn be processed by following
485 CLASS="CONSTANT"
486 >ai_next</TT
488 pointer, until a
489 <SPAN
490 CLASS="TYPE"
491 >NULL</SPAN
493 pointer is encountered.
494 The three members
496 CLASS="CONSTANT"
497 >ai_family</TT
500 CLASS="CONSTANT"
501 >ai_socktype</TT
505 CLASS="CONSTANT"
506 >ai_protocol</TT
508 in each
509 returned
510 <SPAN
511 CLASS="TYPE"
512 >addrinfo</SPAN
514 structure contain the corresponding arguments for a call to
515 <SPAN
516 CLASS="CITEREFENTRY"
517 ><SPAN
518 CLASS="REFENTRYTITLE"
519 >socket</SPAN
520 >(2)</SPAN
522 For each
523 <SPAN
524 CLASS="TYPE"
525 >addrinfo</SPAN
527 structure in the list, the
529 CLASS="CONSTANT"
530 >ai_addr</TT
532 member points to a filled-in socket address structure of length
534 CLASS="CONSTANT"
535 >ai_addrlen</TT
536 >.</P
538 >All of the information returned by
540 CLASS="FUNCTION"
541 >lwres_getaddrinfo()</TT
543 is dynamically allocated: the addrinfo structures, and the socket
544 address structures and canonical host name strings pointed to by the
546 CLASS="CONSTANT"
547 >addrinfo</TT
548 >structures.
549 Memory allocated for the dynamically allocated structures created by
550 a successful call to
552 CLASS="FUNCTION"
553 >lwres_getaddrinfo()</TT
555 is released by
557 CLASS="FUNCTION"
558 >lwres_freeaddrinfo()</TT
561 CLASS="PARAMETER"
563 >ai</I
564 ></TT
566 is a pointer to a
567 <SPAN
568 CLASS="TYPE"
569 >struct addrinfo</SPAN
571 created by a call to
573 CLASS="FUNCTION"
574 >lwres_getaddrinfo()</TT
575 >.</P
576 ></DIV
577 ><DIV
578 CLASS="REFSECT1"
580 NAME="AEN142"
581 ></A
582 ><H2
583 >RETURN VALUES</H2
585 ><TT
586 CLASS="FUNCTION"
587 >lwres_getaddrinfo()</TT
589 returns zero on success or one of the error codes listed in
590 <SPAN
591 CLASS="CITEREFENTRY"
592 ><SPAN
593 CLASS="REFENTRYTITLE"
594 >gai_strerror</SPAN
595 >(3)</SPAN
597 if an error occurs.
598 If both
600 CLASS="PARAMETER"
602 >hostname</I
603 ></TT
607 CLASS="PARAMETER"
609 >servname</I
610 ></TT
613 <SPAN
614 CLASS="TYPE"
615 >NULL</SPAN
618 CLASS="FUNCTION"
619 >lwres_getaddrinfo()</TT
621 returns
622 <SPAN
623 CLASS="ERRORCODE"
624 >EAI_NONAME</SPAN
625 >.&#13;</P
626 ></DIV
627 ><DIV
628 CLASS="REFSECT1"
630 NAME="AEN154"
631 ></A
632 ><H2
633 >SEE ALSO</H2
635 ><SPAN
636 CLASS="CITEREFENTRY"
637 ><SPAN
638 CLASS="REFENTRYTITLE"
639 >lwres</SPAN
640 >(3)</SPAN
643 <SPAN
644 CLASS="CITEREFENTRY"
645 ><SPAN
646 CLASS="REFENTRYTITLE"
647 >lwres_getaddrinfo</SPAN
648 >(3)</SPAN
651 <SPAN
652 CLASS="CITEREFENTRY"
653 ><SPAN
654 CLASS="REFENTRYTITLE"
655 >lwres_freeaddrinfo</SPAN
656 >(3)</SPAN
659 <SPAN
660 CLASS="CITEREFENTRY"
661 ><SPAN
662 CLASS="REFENTRYTITLE"
663 >lwres_gai_strerror</SPAN
664 >(3)</SPAN
667 <SPAN
668 CLASS="CITEREFENTRY"
669 ><SPAN
670 CLASS="REFENTRYTITLE"
671 >RFC2133</SPAN
672 ></SPAN
675 <SPAN
676 CLASS="CITEREFENTRY"
677 ><SPAN
678 CLASS="REFENTRYTITLE"
679 >getservbyname</SPAN
680 >(3)</SPAN
683 <SPAN
684 CLASS="CITEREFENTRY"
685 ><SPAN
686 CLASS="REFENTRYTITLE"
687 >bind</SPAN
688 >(2)</SPAN
691 <SPAN
692 CLASS="CITEREFENTRY"
693 ><SPAN
694 CLASS="REFENTRYTITLE"
695 >connect</SPAN
696 >(2)</SPAN
699 <SPAN
700 CLASS="CITEREFENTRY"
701 ><SPAN
702 CLASS="REFENTRYTITLE"
703 >sendto</SPAN
704 >(2)</SPAN
707 <SPAN
708 CLASS="CITEREFENTRY"
709 ><SPAN
710 CLASS="REFENTRYTITLE"
711 >sendmsg</SPAN
712 >(2)</SPAN
715 <SPAN
716 CLASS="CITEREFENTRY"
717 ><SPAN
718 CLASS="REFENTRYTITLE"
719 >socket</SPAN
720 >(2)</SPAN
721 >.</P
722 ></DIV
723 ></BODY
724 ></HTML