Blame lib/lwres/man/lwres_getaddrinfo.docbook

Packit 5ce601
Packit 5ce601
]>
Packit 5ce601
Packit 5ce601
 - Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit 5ce601
 -
Packit 5ce601
 - This Source Code Form is subject to the terms of the Mozilla Public
Packit 5ce601
 - License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service 704ed8
 - file, you can obtain one at https://mozilla.org/MPL/2.0/.
Packit 5ce601
 -
Packit 5ce601
 - See the COPYRIGHT file distributed with this work for additional
Packit 5ce601
 - information regarding copyright ownership.
Packit 5ce601
-->
Packit 5ce601
Packit 5ce601
Packit Service 704ed8
<refentry xmlns="http://docbook.org/ns/docbook" version="5.0">
Packit 5ce601
  <info>
Packit 5ce601
    <date>2007-06-18</date>
Packit 5ce601
  </info>
Packit 5ce601
  <refentryinfo>
Packit 5ce601
    <corpname>ISC</corpname>
Packit 5ce601
    <corpauthor>Internet Systems Consortium, Inc.</corpauthor>
Packit 5ce601
  </refentryinfo>
Packit 5ce601
Packit 5ce601
  <refmeta>
Packit 5ce601
    <refentrytitle>lwres_getaddrinfo</refentrytitle>
Packit 5ce601
    <manvolnum>3</manvolnum>
Packit Service e5d613
    <refmiscinfo class="manual">BIND9</refmiscinfo>
Packit 5ce601
  </refmeta>
Packit 5ce601
Packit 5ce601
  <docinfo>
Packit 5ce601
    <copyright>
Packit 5ce601
      <year>2000</year>
Packit 5ce601
      <year>2001</year>
Packit 5ce601
      <year>2003</year>
Packit 5ce601
      <year>2004</year>
Packit 5ce601
      <year>2005</year>
Packit 5ce601
      <year>2007</year>
Packit 5ce601
      <year>2014</year>
Packit 5ce601
      <year>2015</year>
Packit 5ce601
      <year>2016</year>
Packit 5ce601
      <year>2018</year>
Packit 5ce601
      <year>2019</year>
Packit 5ce601
      <year>2020</year>
Packit 5ce601
      <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
Packit 5ce601
    </copyright>
Packit 5ce601
  </docinfo>
Packit 5ce601
Packit 5ce601
  <refnamediv>
Packit 5ce601
    <refname>lwres_getaddrinfo</refname>
Packit 5ce601
    <refname>lwres_freeaddrinfo</refname>
Packit 5ce601
    <refpurpose>socket address structure to host and service name</refpurpose>
Packit 5ce601
  </refnamediv>
Packit 5ce601
  <refsynopsisdiv>
Packit 5ce601
    <funcsynopsis>
Packit 5ce601
<funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
Packit 5ce601
<funcprototype>
Packit 5ce601
        <funcdef>
Packit 5ce601
int
Packit 5ce601
<function>lwres_getaddrinfo</function></funcdef>
Packit 5ce601
        <paramdef>const char *<parameter>hostname</parameter></paramdef>
Packit 5ce601
        <paramdef>const char *<parameter>servname</parameter></paramdef>
Packit 5ce601
        <paramdef>const struct addrinfo *<parameter>hints</parameter></paramdef>
Packit 5ce601
        <paramdef>struct addrinfo **<parameter>res</parameter></paramdef>
Packit 5ce601
        </funcprototype>
Packit 5ce601
<funcprototype>
Packit 5ce601
        <funcdef>
Packit 5ce601
void
Packit 5ce601
<function>lwres_freeaddrinfo</function></funcdef>
Packit 5ce601
        <paramdef>struct addrinfo *<parameter>ai</parameter></paramdef>
Packit 5ce601
      </funcprototype>
Packit 5ce601
</funcsynopsis>
Packit 5ce601
Packit 5ce601
    <para>
Packit 5ce601
      If the operating system does not provide a
Packit 5ce601
      <type>struct addrinfo</type>,
Packit 5ce601
      the following structure is used:
Packit 5ce601
    </para>
Packit 5ce601
    <para><programlisting>
Packit 5ce601
struct  addrinfo {
Packit 5ce601
        int             ai_flags;       /* AI_PASSIVE, AI_CANONNAME */
Packit 5ce601
        int             ai_family;      /* PF_xxx */
Packit 5ce601
        int             ai_socktype;    /* SOCK_xxx */
Packit 5ce601
        int             ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
Packit 5ce601
        size_t          ai_addrlen;     /* length of ai_addr */
Packit 5ce601
        char            *ai_canonname;  /* canonical name for hostname */
Packit 5ce601
        struct sockaddr *ai_addr;       /* binary address */
Packit 5ce601
        struct addrinfo *ai_next;       /* next structure in linked list */
Packit 5ce601
};
Packit 5ce601
</programlisting>
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
  </refsynopsisdiv>
Packit 5ce601
Packit 5ce601
  <refsection><info><title>DESCRIPTION</title></info>
Packit 5ce601
Packit 5ce601
Packit 5ce601
    <para><function>lwres_getaddrinfo()</function>
Packit 5ce601
      is used to get a list of IP addresses and port numbers for host
Packit 5ce601
      <parameter>hostname</parameter> and service
Packit 5ce601
      <parameter>servname</parameter>.
Packit 5ce601
Packit 5ce601
      The function is the lightweight resolver's implementation of
Packit 5ce601
      <function>getaddrinfo()</function> as defined in RFC2133.
Packit 5ce601
      <parameter>hostname</parameter> and
Packit 5ce601
      <parameter>servname</parameter> are pointers to null-terminated
Packit 5ce601
      strings or <type>NULL</type>.
Packit 5ce601
Packit 5ce601
      <parameter>hostname</parameter> is either a host name or a
Packit 5ce601
      numeric host address string: a dotted decimal IPv4 address or an
Packit 5ce601
      IPv6 address.  <parameter>servname</parameter> is either a
Packit 5ce601
      decimal port number or a service name as listed in
Packit 5ce601
      <filename>/etc/services</filename>.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
    <para><parameter>hints</parameter>
Packit 5ce601
      is an optional pointer to a
Packit 5ce601
      <type>struct addrinfo</type>.
Packit 5ce601
      This structure can be used to provide hints concerning the type of
Packit 5ce601
      socket
Packit 5ce601
      that the caller supports or wishes to use.
Packit 5ce601
      The caller can supply the following structure elements in
Packit 5ce601
      <parameter>*hints</parameter>:
Packit 5ce601
Packit 5ce601
      <variablelist>
Packit 5ce601
        <varlistentry>
Packit 5ce601
          <term><constant>ai_family</constant></term>
Packit 5ce601
          <listitem>
Packit 5ce601
            <para>
Packit 5ce601
              The protocol family that should be used.
Packit 5ce601
              When
Packit 5ce601
              <constant>ai_family</constant>
Packit 5ce601
              is set to
Packit 5ce601
              <type>PF_UNSPEC</type>,
Packit 5ce601
              it means the caller will accept any protocol family supported by
Packit 5ce601
              the
Packit 5ce601
              operating system.
Packit 5ce601
            </para>
Packit 5ce601
          </listitem>
Packit 5ce601
        </varlistentry>
Packit 5ce601
        <varlistentry>
Packit 5ce601
          <term><constant>ai_socktype</constant></term>
Packit 5ce601
          <listitem>
Packit 5ce601
            <para>
Packit 5ce601
              denotes the type of socket —
Packit 5ce601
              <type>SOCK_STREAM</type>,
Packit 5ce601
              <type>SOCK_DGRAM</type>
Packit 5ce601
              or
Packit 5ce601
              <type>SOCK_RAW</type>
Packit 5ce601
              — that is wanted.
Packit 5ce601
              When
Packit 5ce601
              <constant>ai_socktype</constant>
Packit 5ce601
              is zero the caller will accept any socket type.
Packit 5ce601
            </para>
Packit 5ce601
          </listitem>
Packit 5ce601
        </varlistentry>
Packit 5ce601
        <varlistentry>
Packit 5ce601
          <term><constant>ai_protocol</constant></term>
Packit 5ce601
          <listitem>
Packit 5ce601
            <para>
Packit 5ce601
              indicates which transport protocol is wanted: IPPROTO_UDP or
Packit 5ce601
              IPPROTO_TCP.
Packit 5ce601
              If
Packit 5ce601
              <constant>ai_protocol</constant>
Packit 5ce601
              is zero the caller will accept any protocol.
Packit 5ce601
            </para>
Packit 5ce601
          </listitem>
Packit 5ce601
        </varlistentry>
Packit 5ce601
        <varlistentry>
Packit 5ce601
          <term><constant>ai_flags</constant></term>
Packit 5ce601
          <listitem>
Packit 5ce601
            <para>
Packit 5ce601
              Flag bits.
Packit 5ce601
              If the
Packit 5ce601
              <type>AI_CANONNAME</type>
Packit 5ce601
              bit is set, a successful call to
Packit 5ce601
              <function>lwres_getaddrinfo()</function>
Packit 5ce601
              will return a null-terminated string containing the canonical
Packit 5ce601
              name
Packit 5ce601
              of the specified hostname in
Packit 5ce601
              <constant>ai_canonname</constant>
Packit 5ce601
              of the first
Packit 5ce601
              <type>addrinfo</type>
Packit 5ce601
              structure returned.
Packit 5ce601
              Setting the
Packit 5ce601
              <type>AI_PASSIVE</type>
Packit 5ce601
              bit indicates that the returned socket address structure is
Packit 5ce601
              intended
Packit 5ce601
              for used in a call to
Packit 5ce601
              <citerefentry>
Packit 5ce601
                <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
              </citerefentry>.
Packit 5ce601
Packit 5ce601
              In this case, if the hostname argument is a
Packit 5ce601
              <type>NULL</type>
Packit 5ce601
              pointer, then the IP address portion of the socket
Packit 5ce601
              address structure will be set to
Packit 5ce601
              <type>INADDR_ANY</type>
Packit 5ce601
              for an IPv4 address or
Packit 5ce601
              <type>IN6ADDR_ANY_INIT</type>
Packit 5ce601
              for an IPv6 address.
Packit 5ce601
            </para>
Packit 5ce601
            <para>
Packit 5ce601
              When
Packit 5ce601
              <constant>ai_flags</constant>
Packit 5ce601
              does not set the
Packit 5ce601
              <type>AI_PASSIVE</type>
Packit 5ce601
              bit, the returned socket address structure will be ready
Packit 5ce601
              for use in a call to
Packit 5ce601
              <citerefentry>
Packit 5ce601
                <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
              </citerefentry>
Packit 5ce601
              for a connection-oriented protocol or
Packit 5ce601
              <citerefentry>
Packit 5ce601
                <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
              </citerefentry>,
Packit 5ce601
Packit 5ce601
              <citerefentry>
Packit 5ce601
                <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
              </citerefentry>,
Packit 5ce601
Packit 5ce601
              or
Packit 5ce601
              <citerefentry>
Packit 5ce601
                <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
              </citerefentry>
Packit 5ce601
              if a connectionless protocol was chosen.
Packit 5ce601
              The IP address portion of the socket address structure will be
Packit 5ce601
              set to the loopback address if
Packit 5ce601
              <parameter>hostname</parameter>
Packit 5ce601
              is a
Packit 5ce601
              <type>NULL</type>
Packit 5ce601
              pointer and
Packit 5ce601
              <type>AI_PASSIVE</type>
Packit 5ce601
              is not set in
Packit 5ce601
              <constant>ai_flags</constant>.
Packit 5ce601
            </para>
Packit 5ce601
            <para>
Packit 5ce601
              If
Packit 5ce601
              <constant>ai_flags</constant>
Packit 5ce601
              is set to
Packit 5ce601
              <type>AI_NUMERICHOST</type>
Packit 5ce601
              it indicates that
Packit 5ce601
              <parameter>hostname</parameter>
Packit 5ce601
              should be treated as a numeric string defining an IPv4 or IPv6
Packit 5ce601
              address
Packit 5ce601
              and no name resolution should be attempted.
Packit 5ce601
            </para>
Packit 5ce601
          </listitem>
Packit 5ce601
        </varlistentry>
Packit 5ce601
      </variablelist>
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
    <para>
Packit 5ce601
      All other elements of the <type>struct addrinfo</type> passed
Packit 5ce601
      via <parameter>hints</parameter> must be zero.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
    <para>
Packit 5ce601
      A <parameter>hints</parameter> of <type>NULL</type> is
Packit 5ce601
      treated as if
Packit 5ce601
      the caller provided a <type>struct addrinfo</type> initialized to zero
Packit 5ce601
      with <constant>ai_family</constant>set to
Packit 5ce601
      <constant>PF_UNSPEC</constant>.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
    <para>
Packit 5ce601
      After a successful call to
Packit 5ce601
      <function>lwres_getaddrinfo()</function>,
Packit 5ce601
      <parameter>*res</parameter>
Packit 5ce601
      is a pointer to a linked list of one or more
Packit 5ce601
      <type>addrinfo</type>
Packit 5ce601
      structures.
Packit 5ce601
      Each
Packit 5ce601
      <type>struct addrinfo</type>
Packit 5ce601
      in this list cn be processed by following
Packit 5ce601
      the
Packit 5ce601
      <constant>ai_next</constant>
Packit 5ce601
      pointer, until a
Packit 5ce601
      <type>NULL</type>
Packit 5ce601
      pointer is encountered.
Packit 5ce601
      The three members
Packit 5ce601
      <constant>ai_family</constant>,
Packit 5ce601
      <constant>ai_socktype</constant>,
Packit 5ce601
      and
Packit 5ce601
      <constant>ai_protocol</constant>
Packit 5ce601
      in each
Packit 5ce601
      returned
Packit 5ce601
      <type>addrinfo</type>
Packit 5ce601
      structure contain the corresponding arguments for a call to
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>.
Packit 5ce601
      For each
Packit 5ce601
      <type>addrinfo</type>
Packit 5ce601
      structure in the list, the
Packit 5ce601
      <constant>ai_addr</constant>
Packit 5ce601
      member points to a filled-in socket address structure of length
Packit 5ce601
      <constant>ai_addrlen</constant>.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
    <para>
Packit 5ce601
      All of the information returned by
Packit 5ce601
      <function>lwres_getaddrinfo()</function>
Packit 5ce601
      is dynamically allocated: the addrinfo structures, and the socket
Packit 5ce601
      address structures and canonical host name strings pointed to by the
Packit 5ce601
      <constant>addrinfo</constant>structures.
Packit 5ce601
      Memory allocated for the dynamically allocated structures created by
Packit 5ce601
      a successful call to
Packit 5ce601
      <function>lwres_getaddrinfo()</function>
Packit 5ce601
      is released by
Packit 5ce601
      <function>lwres_freeaddrinfo()</function>.
Packit 5ce601
      <parameter>ai</parameter>
Packit 5ce601
      is a pointer to a
Packit 5ce601
      <type>struct addrinfo</type>
Packit 5ce601
      created by a call to
Packit 5ce601
      <function>lwres_getaddrinfo()</function>.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
  </refsection>
Packit 5ce601
Packit 5ce601
  <refsection><info><title>RETURN VALUES</title></info>
Packit 5ce601
Packit 5ce601
Packit 5ce601
    <para><function>lwres_getaddrinfo()</function>
Packit 5ce601
      returns zero on success or one of the error codes listed in
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>gai_strerror</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>
Packit 5ce601
      if an error occurs.  If both <parameter>hostname</parameter> and
Packit 5ce601
      <parameter>servname</parameter> are <type>NULL</type>
Packit 5ce601
      <function>lwres_getaddrinfo()</function> returns
Packit 5ce601
      <errorcode>EAI_NONAME</errorcode>.
Packit 5ce601
    </para>
Packit 5ce601
  </refsection>
Packit 5ce601
  <refsection><info><title>SEE ALSO</title></info>
Packit 5ce601
Packit 5ce601
    <para><citerefentry>
Packit 5ce601
        <refentrytitle>lwres</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>lwres_getaddrinfo</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>lwres_freeaddrinfo</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>lwres_gai_strerror</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>RFC2133</refentrytitle>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>getservbyname</refentrytitle><manvolnum>3</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>,
Packit 5ce601
Packit 5ce601
      <citerefentry>
Packit 5ce601
        <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>
Packit 5ce601
      </citerefentry>.
Packit 5ce601
    </para>
Packit 5ce601
Packit 5ce601
  </refsection>
Packit 5ce601
</refentry>