1008N/A - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC") 1008N/A - Copyright (C) 2000, 2001, 2003 Internet Software Consortium 1008N/A - Permission to use, copy, modify, and distribute this software for any 1008N/A - purpose with or without fee is hereby granted, provided that the above 1008N/A - copyright notice and this permission notice appear in all copies. 1008N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 1008N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 1008N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 1008N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 1008N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 1008N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 1008N/A - PERFORMANCE OF THIS SOFTWARE. 1008N/A<
meta http-
equiv="Content-Type" content="text/html; charset=ISO-8859-1">
1008N/A<
title>lwres_getaddrinfo</
title>
1008N/A<
meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
1008N/A<
body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><
div class="refentry" lang="en">
1008N/A<
a name="id2456618"></
a><
div class="titlepage"></
div>
1008N/A<
p>lwres_getaddrinfo, lwres_freeaddrinfo — socket address structure to host and service name</
p>
1008N/A<
div class="refsynopsisdiv">
1008N/A<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
1008N/A<
b class="fsfunc">lwres_getaddrinfo</
b>(</
code></
td>
1008N/A<
var class="pdparam">hostname</
var>, </
td>
<
var class="pdparam">servname</
var>, </
td>
<
td>const struct addrinfo *�</
td>
<
var class="pdparam">hints</
var>, </
td>
<
td>struct addrinfo **�</
td>
<
var class="pdparam">res</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_freeaddrinfo</
b>(</
code></
td>
<
td>struct addrinfo *�</
td>
<
var class="pdparam">ai</
var><
code>)</
code>;</
td>
If the operating system does not provide a
<
span class="type">struct addrinfo</
span>,
the following structure is used:
<
pre class="programlisting">
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
size_t ai_addrlen; /* length of ai_addr */
char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */
<
div class="refsect1" lang="en">
<
a name="id2514026"></
a><
h2>DESCRIPTION</
h2>
<
p><
code class="function">lwres_getaddrinfo()</
code>
is used to get a list of IP addresses and port numbers for host
<
em class="parameter"><
code>hostname</
code></
em> and service
<
em class="parameter"><
code>servname</
code></
em>.
The function is the lightweight resolver's implementation of
<
code class="function">getaddrinfo()</
code> as defined in RFC2133.
<
em class="parameter"><
code>hostname</
code></
em> and
<
em class="parameter"><
code>servname</
code></
em> are pointers to null-terminated
strings or <
span class="type">NULL</
span>.
<
em class="parameter"><
code>hostname</
code></
em> is either a host name or a
numeric host address string: a dotted decimal IPv4 address or an
IPv6 address. <
em class="parameter"><
code>servname</
code></
em> is either a
decimal port number or a service name as listed in
<
p><
em class="parameter"><
code>hints</
code></
em>
is an optional pointer to a
<
span class="type">struct addrinfo</
span>.
This structure can be used to provide hints concerning the type of
that the caller supports or wishes to use.
The caller can supply the following structure elements in
<
em class="parameter"><
code>*hints</
code></
em>:
<
div class="variablelist"><
dl>
<
dt><
span class="term"><
code class="constant">ai_family</
code></
span></
dt>
The protocol family that should be used.
<
code class="constant">ai_family</
code>
<
span class="type">PF_UNSPEC</
span>,
it means the caller will accept any protocol family supported by
<
dt><
span class="term"><
code class="constant">ai_socktype</
code></
span></
dt>
denotes the type of socket —
<
span class="type">SOCK_STREAM</
span>,
<
span class="type">SOCK_DGRAM</
span>
<
span class="type">SOCK_RAW</
span>
<
code class="constant">ai_socktype</
code>
is zero the caller will accept any socket type.
<
dt><
span class="term"><
code class="constant">ai_protocol</
code></
span></
dt>
indicates which transport protocol is wanted: IPPROTO_UDP or
<
code class="constant">ai_protocol</
code>
is zero the caller will accept any protocol.
<
dt><
span class="term"><
code class="constant">ai_flags</
code></
span></
dt>
<
span class="type">AI_CANONNAME</
span>
bit is set, a successful call to
<
code class="function">lwres_getaddrinfo()</
code>
will return a null-terminated string containing the canonical
of the specified hostname in
<
code class="constant">ai_canonname</
code>
<
span class="type">addrinfo</
span>
<
span class="type">AI_PASSIVE</
span>
bit indicates that the returned socket address structure is
<
span class="citerefentry"><
span class="refentrytitle">bind</
span>(2)</
span>.
In this case, if the hostname argument is a
<
span class="type">NULL</
span>
pointer, then the IP address portion of the socket
address structure will be set to
<
span class="type">INADDR_ANY</
span>
<
span class="type">IN6ADDR_ANY_INIT</
span>
<
code class="constant">ai_flags</
code>
<
span class="type">AI_PASSIVE</
span>
bit, the returned socket address structure will be ready
<
span class="citerefentry"><
span class="refentrytitle">connect</
span>(2)</
span>
for a connection-oriented protocol or
<
span class="citerefentry"><
span class="refentrytitle">connect</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">sendto</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">sendmsg</
span>(2)</
span>
if a connectionless protocol was chosen.
The IP address portion of the socket address structure will be
set to the loopback address if
<
em class="parameter"><
code>hostname</
code></
em>
<
span class="type">NULL</
span>
<
span class="type">AI_PASSIVE</
span>
<
code class="constant">ai_flags</
code>.
<
code class="constant">ai_flags</
code>
<
span class="type">AI_NUMERICHOST</
span>
<
em class="parameter"><
code>hostname</
code></
em>
should be treated as a numeric string defining an IPv4 or IPv6
and no name resolution should be attempted.
All other elements of the <
span class="type">struct addrinfo</
span> passed
via <
em class="parameter"><
code>hints</
code></
em> must be zero.
A <
em class="parameter"><
code>hints</
code></
em> of <
span class="type">NULL</
span> is
the caller provided a <
span class="type">struct addrinfo</
span> initialized to zero
with <
code class="constant">ai_family</
code>set to
<
code class="constant">PF_UNSPEC</
code>.
After a successful call to
<
code class="function">lwres_getaddrinfo()</
code>,
<
em class="parameter"><
code>*res</
code></
em>
is a pointer to a linked list of one or more
<
span class="type">addrinfo</
span>
<
span class="type">struct addrinfo</
span>
in this list cn be processed by following
<
code class="constant">ai_next</
code>
<
span class="type">NULL</
span>
<
code class="constant">ai_family</
code>,
<
code class="constant">ai_socktype</
code>,
<
code class="constant">ai_protocol</
code>
<
span class="type">addrinfo</
span>
structure contain the corresponding arguments for a call to
<
span class="citerefentry"><
span class="refentrytitle">socket</
span>(2)</
span>.
<
span class="type">addrinfo</
span>
structure in the list, the
<
code class="constant">ai_addr</
code>
member points to a filled-in socket address structure of length
<
code class="constant">ai_addrlen</
code>.
All of the information returned by
<
code class="function">lwres_getaddrinfo()</
code>
is dynamically allocated: the addrinfo structures, and the socket
address structures and canonical host name strings pointed to by the
<
code class="constant">addrinfo</
code>structures.
Memory allocated for the dynamically allocated structures created by
<
code class="function">lwres_getaddrinfo()</
code>
<
code class="function">lwres_freeaddrinfo()</
code>.
<
em class="parameter"><
code>ai</
code></
em>
<
span class="type">struct addrinfo</
span>
<
code class="function">lwres_getaddrinfo()</
code>.
<
div class="refsect1" lang="en">
<
a name="id2514609"></
a><
h2>RETURN VALUES</
h2>
<
p><
code class="function">lwres_getaddrinfo()</
code>
returns zero on success or one of the error codes listed in
<
span class="citerefentry"><
span class="refentrytitle">gai_strerror</
span>(3)</
span>
if an error occurs. If both <
em class="parameter"><
code>hostname</
code></
em> and
<
em class="parameter"><
code>servname</
code></
em> are <
span class="type">NULL</
span>
<
code class="function">lwres_getaddrinfo()</
code> returns
<
span class="errorcode">EAI_NONAME</
span>.
<
div class="refsect1" lang="en">
<
a name="id2514646"></
a><
h2>SEE ALSO</
h2>
<
p><
span class="citerefentry"><
span class="refentrytitle">lwres</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">lwres_getaddrinfo</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">lwres_freeaddrinfo</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">lwres_gai_strerror</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">RFC2133</
span></
span>,
<
span class="citerefentry"><
span class="refentrytitle">getservbyname</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">bind</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">connect</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">sendto</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">sendmsg</
span>(2)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">socket</
span>(2)</
span>.