698N/A<!ENTITY mdash "—">]>
698N/A - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC") 698N/A - Copyright (C) 2000, 2001, 2003 Internet Software Consortium. 698N/A - Permission to use, copy, modify, and/or distribute this software for any 698N/A - purpose with or without fee is hereby granted, provided that the above 698N/A - copyright notice and this permission notice appear in all copies. 698N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 698N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 698N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 698N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 698N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 698N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 698N/A - PERFORMANCE OF THIS SOFTWARE. 698N/A<!-- Converted by db4-upgrade version 1.0 --> 698N/A <
date>2007-06-18</
date>
698N/A <
corpname>ISC</
corpname>
698N/A <
corpauthor>Internet Systems Consortium, Inc.</
corpauthor>
844N/A <
refentrytitle>lwres_getaddrinfo</
refentrytitle>
844N/A <
manvolnum>3</
manvolnum>
698N/A <
refmiscinfo>BIND9</
refmiscinfo>
698N/A <
holder>Internet Systems Consortium, Inc. ("ISC")</
holder>
698N/A <
holder>Internet Software Consortium.</
holder>
698N/A <
refname>lwres_getaddrinfo</
refname>
698N/A <
refname>lwres_freeaddrinfo</
refname>
698N/A <
refpurpose>socket address structure to host and service name</
refpurpose>
<
function>lwres_getaddrinfo</
function></
funcdef>
<
paramdef>const char *<
parameter>hostname</
parameter></
paramdef>
<
paramdef>const char *<
parameter>servname</
parameter></
paramdef>
<
paramdef>const struct addrinfo *<
parameter>hints</
parameter></
paramdef>
<
paramdef>struct addrinfo **<
parameter>res</
parameter></
paramdef>
<
function>lwres_freeaddrinfo</
function></
funcdef>
<
paramdef>struct addrinfo *<
parameter>ai</
parameter></
paramdef>
If the operating system does not provide a
<
type>struct addrinfo</
type>,
the following structure is used:
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 */
<
refsection><
info><
title>DESCRIPTION</
title></
info>
<
para><
function>lwres_getaddrinfo()</
function>
is used to get a list of IP addresses and port numbers for host
<
parameter>hostname</
parameter> and service
<
parameter>servname</
parameter>.
The function is the lightweight resolver's implementation of
<
function>getaddrinfo()</
function> as defined in RFC2133.
<
parameter>hostname</
parameter> and
<
parameter>servname</
parameter> are pointers to null-terminated
strings or <
type>NULL</
type>.
<
parameter>hostname</
parameter> is either a host name or a
numeric host address string: a dotted decimal IPv4 address or an
IPv6 address. <
parameter>servname</
parameter> is either a
decimal port number or a service name as listed in
<
para><
parameter>hints</
parameter>
is an optional pointer to a
<
type>struct addrinfo</
type>.
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
<
parameter>*hints</
parameter>:
<
term><
constant>ai_family</
constant></
term>
The protocol family that should be used.
<
constant>ai_family</
constant>
it means the caller will accept any protocol family supported by
<
term><
constant>ai_socktype</
constant></
term>
denotes the type of socket —
<
type>SOCK_STREAM</
type>,
<
constant>ai_socktype</
constant>
is zero the caller will accept any socket type.
<
term><
constant>ai_protocol</
constant></
term>
indicates which transport protocol is wanted: IPPROTO_UDP or
<
constant>ai_protocol</
constant>
is zero the caller will accept any protocol.
<
term><
constant>ai_flags</
constant></
term>
<
type>AI_CANONNAME</
type>
bit is set, a successful call to
<
function>lwres_getaddrinfo()</
function>
will return a null-terminated string containing the canonical
of the specified hostname in
<
constant>ai_canonname</
constant>
bit indicates that the returned socket address structure is
<
refentrytitle>bind</
refentrytitle><
manvolnum>2</
manvolnum>
In this case, if the hostname argument is a
pointer, then the IP address portion of the socket
address structure will be set to
<
type>IN6ADDR_ANY_INIT</
type>
<
constant>ai_flags</
constant>
bit, the returned socket address structure will be ready
<
refentrytitle>connect</
refentrytitle><
manvolnum>2</
manvolnum>
for a connection-oriented protocol or
<
refentrytitle>connect</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>sendto</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>sendmsg</
refentrytitle><
manvolnum>2</
manvolnum>
if a connectionless protocol was chosen.
The IP address portion of the socket address structure will be
set to the loopback address if
<
parameter>hostname</
parameter>
<
constant>ai_flags</
constant>.
<
constant>ai_flags</
constant>
<
type>AI_NUMERICHOST</
type>
<
parameter>hostname</
parameter>
should be treated as a numeric string defining an IPv4 or IPv6
and no name resolution should be attempted.
All other elements of the <
type>struct addrinfo</
type> passed
via <
parameter>hints</
parameter> must be zero.
A <
parameter>hints</
parameter> of <
type>NULL</
type> is
the caller provided a <
type>struct addrinfo</
type> initialized to zero
with <
constant>ai_family</
constant>set to
<
constant>PF_UNSPEC</
constant>.
After a successful call to
<
function>lwres_getaddrinfo()</
function>,
<
parameter>*res</
parameter>
is a pointer to a linked list of one or more
<
type>struct addrinfo</
type>
in this list cn be processed by following
<
constant>ai_next</
constant>
<
constant>ai_family</
constant>,
<
constant>ai_socktype</
constant>,
<
constant>ai_protocol</
constant>
structure contain the corresponding arguments for a call to
<
refentrytitle>socket</
refentrytitle><
manvolnum>2</
manvolnum>
structure in the list, the
<
constant>ai_addr</
constant>
member points to a filled-in socket address structure of length
<
constant>ai_addrlen</
constant>.
All of the information returned by
<
function>lwres_getaddrinfo()</
function>
is dynamically allocated: the addrinfo structures, and the socket
address structures and canonical host name strings pointed to by the
<
constant>addrinfo</
constant>structures.
Memory allocated for the dynamically allocated structures created by
<
function>lwres_getaddrinfo()</
function>
<
function>lwres_freeaddrinfo()</
function>.
<
parameter>ai</
parameter>
<
type>struct addrinfo</
type>
<
function>lwres_getaddrinfo()</
function>.
<
refsection><
info><
title>RETURN VALUES</
title></
info>
<
para><
function>lwres_getaddrinfo()</
function>
returns zero on success or one of the error codes listed in
<
refentrytitle>gai_strerror</
refentrytitle><
manvolnum>3</
manvolnum>
if an error occurs. If both <
parameter>hostname</
parameter> and
<
parameter>servname</
parameter> are <
type>NULL</
type>
<
function>lwres_getaddrinfo()</
function> returns
<
errorcode>EAI_NONAME</
errorcode>.
<
refsection><
info><
title>SEE ALSO</
title></
info>
<
refentrytitle>lwres</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>lwres_getaddrinfo</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>lwres_freeaddrinfo</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>lwres_gai_strerror</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>RFC2133</
refentrytitle>
<
refentrytitle>getservbyname</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>bind</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>connect</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>sendto</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>sendmsg</
refentrytitle><
manvolnum>2</
manvolnum>
<
refentrytitle>socket</
refentrytitle><
manvolnum>2</
manvolnum>