2 - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
5 - Permission to use, copy, modify, and/or 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.
20 <meta http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1">
21 <title>lwres_getaddrinfo
</title>
22 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.71.1">
24 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF"><div class=
"refentry" lang=
"en">
25 <a name=
"id2476275"></a><div class=
"titlepage"></div>
26 <div class=
"refnamediv">
28 <p>lwres_getaddrinfo, lwres_freeaddrinfo
— socket address structure to host and service name
</p>
30 <div class=
"refsynopsisdiv">
32 <div class=
"funcsynopsis">
33 <pre class=
"funcsynopsisinfo">#include
<lwres/netdb.h
></pre>
34 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
36 <td><code class=
"funcdef">
38 <b class=
"fsfunc">lwres_getaddrinfo
</b>(
</code></td>
39 <td>const char *
</td>
41 <var class=
"pdparam">hostname
</var>,
</td>
45 <td>const char *
</td>
47 <var class=
"pdparam">servname
</var>,
</td>
51 <td>const struct addrinfo *
</td>
53 <var class=
"pdparam">hints
</var>,
</td>
57 <td>struct addrinfo **
</td>
59 <var class=
"pdparam">res
</var><code>)
</code>;
</td>
62 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0"><tr>
63 <td><code class=
"funcdef">
65 <b class=
"fsfunc">lwres_freeaddrinfo
</b>(
</code></td>
66 <td>struct addrinfo *
</td>
68 <var class=
"pdparam">ai
</var><code>)
</code>;
</td>
72 If the operating system does not provide a
73 <span class=
"type">struct addrinfo
</span>,
74 the following structure is used:
76 <pre class=
"programlisting">
78 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
79 int ai_family; /* PF_xxx */
80 int ai_socktype; /* SOCK_xxx */
81 int ai_protocol; /*
0 or IPPROTO_xxx for IPv4 and IPv6 */
82 size_t ai_addrlen; /* length of ai_addr */
83 char *ai_canonname; /* canonical name for hostname */
84 struct sockaddr *ai_addr; /* binary address */
85 struct addrinfo *ai_next; /* next structure in linked list */
91 <div class=
"refsect1" lang=
"en">
92 <a name=
"id2543421"></a><h2>DESCRIPTION
</h2>
93 <p><code class=
"function">lwres_getaddrinfo()
</code>
94 is used to get a list of IP addresses and port numbers for host
95 <em class=
"parameter"><code>hostname
</code></em> and service
96 <em class=
"parameter"><code>servname
</code></em>.
98 The function is the lightweight resolver's implementation of
99 <code class=
"function">getaddrinfo()
</code> as defined in RFC2133.
100 <em class=
"parameter"><code>hostname
</code></em> and
101 <em class=
"parameter"><code>servname
</code></em> are pointers to null-terminated
102 strings or
<span class=
"type">NULL
</span>.
104 <em class=
"parameter"><code>hostname
</code></em> is either a host name or a
105 numeric host address string: a dotted decimal IPv4 address or an
106 IPv6 address.
<em class=
"parameter"><code>servname
</code></em> is either a
107 decimal port number or a service name as listed in
108 <code class=
"filename">/etc/services
</code>.
110 <p><em class=
"parameter"><code>hints
</code></em>
111 is an optional pointer to a
112 <span class=
"type">struct addrinfo
</span>.
113 This structure can be used to provide hints concerning the type of
115 that the caller supports or wishes to use.
116 The caller can supply the following structure elements in
117 <em class=
"parameter"><code>*hints
</code></em>:
120 <div class=
"variablelist"><dl>
121 <dt><span class=
"term"><code class=
"constant">ai_family
</code></span></dt>
123 The protocol family that should be used.
125 <code class=
"constant">ai_family
</code>
127 <span class=
"type">PF_UNSPEC
</span>,
128 it means the caller will accept any protocol family supported by
132 <dt><span class=
"term"><code class=
"constant">ai_socktype
</code></span></dt>
134 denotes the type of socket
—
135 <span class=
"type">SOCK_STREAM
</span>,
136 <span class=
"type">SOCK_DGRAM
</span>
138 <span class=
"type">SOCK_RAW
</span>
139 — that is wanted.
141 <code class=
"constant">ai_socktype
</code>
142 is zero the caller will accept any socket type.
144 <dt><span class=
"term"><code class=
"constant">ai_protocol
</code></span></dt>
146 indicates which transport protocol is wanted: IPPROTO_UDP or
149 <code class=
"constant">ai_protocol
</code>
150 is zero the caller will accept any protocol.
152 <dt><span class=
"term"><code class=
"constant">ai_flags
</code></span></dt>
157 <span class=
"type">AI_CANONNAME
</span>
158 bit is set, a successful call to
159 <code class=
"function">lwres_getaddrinfo()
</code>
160 will return a null-terminated string containing the canonical
162 of the specified hostname in
163 <code class=
"constant">ai_canonname
</code>
165 <span class=
"type">addrinfo
</span>
168 <span class=
"type">AI_PASSIVE
</span>
169 bit indicates that the returned socket address structure is
171 for used in a call to
172 <span class=
"citerefentry"><span class=
"refentrytitle">bind
</span>(
2)
</span>.
174 In this case, if the hostname argument is a
175 <span class=
"type">NULL
</span>
176 pointer, then the IP address portion of the socket
177 address structure will be set to
178 <span class=
"type">INADDR_ANY
</span>
179 for an IPv4 address or
180 <span class=
"type">IN6ADDR_ANY_INIT
</span>
185 <code class=
"constant">ai_flags
</code>
187 <span class=
"type">AI_PASSIVE
</span>
188 bit, the returned socket address structure will be ready
190 <span class=
"citerefentry"><span class=
"refentrytitle">connect
</span>(
2)
</span>
191 for a connection-oriented protocol or
192 <span class=
"citerefentry"><span class=
"refentrytitle">connect
</span>(
2)
</span>,
194 <span class=
"citerefentry"><span class=
"refentrytitle">sendto
</span>(
2)
</span>,
197 <span class=
"citerefentry"><span class=
"refentrytitle">sendmsg
</span>(
2)
</span>
198 if a connectionless protocol was chosen.
199 The IP address portion of the socket address structure will be
200 set to the loopback address if
201 <em class=
"parameter"><code>hostname
</code></em>
203 <span class=
"type">NULL
</span>
205 <span class=
"type">AI_PASSIVE
</span>
207 <code class=
"constant">ai_flags
</code>.
211 <code class=
"constant">ai_flags
</code>
213 <span class=
"type">AI_NUMERICHOST
</span>
215 <em class=
"parameter"><code>hostname
</code></em>
216 should be treated as a numeric string defining an IPv4 or IPv6
218 and no name resolution should be attempted.
225 All other elements of the
<span class=
"type">struct addrinfo
</span> passed
226 via
<em class=
"parameter"><code>hints
</code></em> must be zero.
229 A
<em class=
"parameter"><code>hints
</code></em> of
<span class=
"type">NULL
</span> is
231 the caller provided a
<span class=
"type">struct addrinfo
</span> initialized to zero
232 with
<code class=
"constant">ai_family
</code>set to
233 <code class=
"constant">PF_UNSPEC
</code>.
236 After a successful call to
237 <code class=
"function">lwres_getaddrinfo()
</code>,
238 <em class=
"parameter"><code>*res
</code></em>
239 is a pointer to a linked list of one or more
240 <span class=
"type">addrinfo
</span>
243 <span class=
"type">struct addrinfo
</span>
244 in this list cn be processed by following
246 <code class=
"constant">ai_next
</code>
248 <span class=
"type">NULL
</span>
249 pointer is encountered.
251 <code class=
"constant">ai_family
</code>,
252 <code class=
"constant">ai_socktype
</code>,
254 <code class=
"constant">ai_protocol
</code>
257 <span class=
"type">addrinfo
</span>
258 structure contain the corresponding arguments for a call to
259 <span class=
"citerefentry"><span class=
"refentrytitle">socket
</span>(
2)
</span>.
261 <span class=
"type">addrinfo
</span>
262 structure in the list, the
263 <code class=
"constant">ai_addr
</code>
264 member points to a filled-in socket address structure of length
265 <code class=
"constant">ai_addrlen
</code>.
268 All of the information returned by
269 <code class=
"function">lwres_getaddrinfo()
</code>
270 is dynamically allocated: the addrinfo structures, and the socket
271 address structures and canonical host name strings pointed to by the
272 <code class=
"constant">addrinfo
</code>structures.
273 Memory allocated for the dynamically allocated structures created by
275 <code class=
"function">lwres_getaddrinfo()
</code>
277 <code class=
"function">lwres_freeaddrinfo()
</code>.
278 <em class=
"parameter"><code>ai
</code></em>
280 <span class=
"type">struct addrinfo
</span>
282 <code class=
"function">lwres_getaddrinfo()
</code>.
285 <div class=
"refsect1" lang=
"en">
286 <a name=
"id2543799"></a><h2>RETURN VALUES
</h2>
287 <p><code class=
"function">lwres_getaddrinfo()
</code>
288 returns zero on success or one of the error codes listed in
289 <span class=
"citerefentry"><span class=
"refentrytitle">gai_strerror
</span>(
3)
</span>
290 if an error occurs. If both
<em class=
"parameter"><code>hostname
</code></em> and
291 <em class=
"parameter"><code>servname
</code></em> are
<span class=
"type">NULL
</span>
292 <code class=
"function">lwres_getaddrinfo()
</code> returns
293 <span class=
"errorcode">EAI_NONAME
</span>.
296 <div class=
"refsect1" lang=
"en">
297 <a name=
"id2543836"></a><h2>SEE ALSO
</h2>
298 <p><span class=
"citerefentry"><span class=
"refentrytitle">lwres
</span>(
3)
</span>,
300 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_getaddrinfo
</span>(
3)
</span>,
302 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_freeaddrinfo
</span>(
3)
</span>,
304 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_gai_strerror
</span>(
3)
</span>,
306 <span class=
"citerefentry"><span class=
"refentrytitle">RFC2133
</span></span>,
308 <span class=
"citerefentry"><span class=
"refentrytitle">getservbyname
</span>(
3)
</span>,
310 <span class=
"citerefentry"><span class=
"refentrytitle">bind
</span>(
2)
</span>,
312 <span class=
"citerefentry"><span class=
"refentrytitle">connect
</span>(
2)
</span>,
314 <span class=
"citerefentry"><span class=
"refentrytitle">sendto
</span>(
2)
</span>,
316 <span class=
"citerefentry"><span class=
"refentrytitle">sendmsg
</span>(
2)
</span>,
318 <span class=
"citerefentry"><span class=
"refentrytitle">socket
</span>(
2)
</span>.