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="refsection" title="DESCRIPTION">
<
a name="idp60848592"></
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)
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)
for a connection-oriented protocol or
<
span class="citerefentry">
<
span class="refentrytitle">connect</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">sendto</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">sendmsg</
span>(2)
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 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="refsection" title="RETURN VALUES">
<
a name="idp60895440"></
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)
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="refsection" title="SEE ALSO">
<
a name="idp60904272"></
a><
h2>SEE ALSO</
h2>
<
p><
span class="citerefentry">
<
span class="refentrytitle">lwres</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">lwres_getaddrinfo</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">lwres_freeaddrinfo</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">lwres_gai_strerror</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">RFC2133</
span>
<
span class="citerefentry">
<
span class="refentrytitle">getservbyname</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">bind</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">connect</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">sendto</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">sendmsg</
span>(2)
<
span class="citerefentry">
<
span class="refentrytitle">socket</
span>(2)