resolve.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <refentry id="refresolve">
  2. <refmeta>
  3. <refentrytitle>ne_addr_resolve</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_addr_resolve">ne_addr_resolve</refname>
  8. <refname id="ne_addr_result">ne_addr_result</refname>
  9. <refname id="ne_addr_first">ne_addr_first</refname>
  10. <refname id="ne_addr_next">ne_addr_next</refname>
  11. <refname id="ne_addr_error">ne_addr_error</refname>
  12. <refname id="ne_addr_canonical">ne_addr_canonical</refname>
  13. <refname id="ne_addr_destroy">ne_addr_destroy</refname>
  14. <refpurpose>functions to resolve hostnames to addresses</refpurpose>
  15. </refnamediv>
  16. <refsynopsisdiv>
  17. <funcsynopsis>
  18. <funcsynopsisinfo>#include &lt;ne_socket.h&gt;</funcsynopsisinfo>
  19. <funcprototype>
  20. <funcdef>ne_sock_addr *<function>ne_addr_resolve</function></funcdef>
  21. <paramdef>const char *<parameter>hostname</parameter></paramdef>
  22. <paramdef>int <parameter>flags</parameter></paramdef>
  23. </funcprototype>
  24. <funcprototype>
  25. <funcdef>int <function>ne_addr_result</function></funcdef>
  26. <paramdef>const ne_sock_addr *<parameter>addr</parameter></paramdef>
  27. </funcprototype>
  28. <funcprototype>
  29. <funcdef>const ne_inet_addr *<function>ne_addr_first</function></funcdef>
  30. <paramdef>ne_sock_addr *<parameter>addr</parameter></paramdef>
  31. </funcprototype>
  32. <funcprototype>
  33. <funcdef>const ne_inet_addr *<function>ne_addr_next</function></funcdef>
  34. <paramdef>ne_sock_addr *<parameter>addr</parameter></paramdef>
  35. </funcprototype>
  36. <funcprototype>
  37. <funcdef>char *<function>ne_addr_error</function></funcdef>
  38. <paramdef>const ne_sock_addr *<parameter>addr</parameter></paramdef>
  39. <paramdef>char *<parameter>buffer</parameter></paramdef>
  40. <paramdef>size_t <parameter>bufsiz</parameter></paramdef>
  41. </funcprototype>
  42. <funcprototype>
  43. <funcdef>const char *<function>ne_addr_canonical</function></funcdef>
  44. <paramdef>const ne_sock_addr *<parameter>addr</parameter></paramdef>
  45. </funcprototype>
  46. <funcprototype>
  47. <funcdef>void <function>ne_addr_destroy</function></funcdef>
  48. <paramdef>ne_sock_addr *<parameter>addr</parameter></paramdef>
  49. </funcprototype>
  50. </funcsynopsis>
  51. </refsynopsisdiv>
  52. <refsect1>
  53. <title>Description</title>
  54. <para>The <function>ne_addr_resolve</function> function resolves
  55. the given <parameter>hostname</parameter>, returning an
  56. <type>ne_sock_addr</type> object representing the address (or
  57. addresses) associated with the hostname. The
  58. <parameter>flags</parameter> parameter should be zero, or if
  59. <literal>NE_ADDR_CANON</literal> used, the canonical name for
  60. the hostname will be determined.</para>
  61. <para>The <parameter>hostname</parameter> passed to
  62. <function>ne_addr_resolve</function> can be a DNS hostname
  63. (e.g. <literal>"www.example.com"</literal>) or an IPv4 dotted quad
  64. (e.g. <literal>"192.0.34.72"</literal>); or, on systems which
  65. support IPv6, an IPv6 hex address, which may be enclosed in
  66. brackets, e.g. <literal>"[::1]"</literal>.</para>
  67. <para>To determine whether the hostname was successfully resolved,
  68. the <function>ne_addr_result</function> function is used, which
  69. returns non-zero if an error occurred. If an error did occur, the
  70. <function>ne_addr_error</function> function can be used, which
  71. will copy the error string into a given
  72. <parameter>buffer</parameter> (of size
  73. <parameter>bufsiz</parameter>).</para>
  74. <para>The functions <function>ne_addr_first</function> and
  75. <function>ne_addr_next</function> are used to retrieve the
  76. Internet addresses associated with an address object which has
  77. been successfully resolved. <function>ne_addr_first</function>
  78. returns the first address; <function>ne_addr_next</function>
  79. returns the next address after the most recent call to
  80. <function>ne_addr_next</function> or
  81. <function>ne_addr_first</function>, or &null; if there are no more
  82. addresses. The <type>ne_inet_addr</type> pointer returned by
  83. these functions can be passed to
  84. <function>ne_sock_connect</function> to connect a socket.</para>
  85. <para>If the <literal>NE_ADDR_CANON</literal> flag was used with
  86. <function>ne_addr_resolve</function>, the canonical hostname can
  87. be retrieved using <function>ne_addr_canonical</function>.</para>
  88. <para>After the address object has been used, it should be
  89. destroyed using <function>ne_addr_destroy</function>.</para>
  90. </refsect1>
  91. <refsect1>
  92. <title>Return value</title>
  93. <para><function>ne_addr_resolve</function> returns a pointer to an
  94. address object, and never &null;.
  95. <function>ne_addr_error</function> returns the
  96. <parameter>buffer</parameter> parameter.</para>
  97. </refsect1>
  98. <refsect1>
  99. <title>Examples</title>
  100. <para>The code below prints out the set of addresses associated
  101. with the hostname <literal>www.google.com</literal>.</para>
  102. <programlisting>ne_sock_addr *addr;
  103. char buf[256];
  104. addr = ne_addr_resolve("www.google.com", 0);
  105. if (ne_addr_result(addr)) {
  106. printf("Could not resolve www.google.com: %s\n",
  107. ne_addr_error(addr, buf, sizeof buf));
  108. } else {
  109. const ne_inet_addr *ia;
  110. printf("www.google.com:");
  111. for (ia = ne_addr_first(addr); ia != NULL; ia = ne_addr_next(addr)) {
  112. printf(" %s", ne_iaddr_print(ia, buf, sizeof buf));
  113. }
  114. putchar('\n');
  115. }
  116. ne_addr_destroy(addr);
  117. </programlisting>
  118. </refsect1>
  119. <refsect1>
  120. <title>History</title>
  121. <para><function>ne_addr_canonical</function> was added in &neon; 0.30.0.</para>
  122. </refsect1>
  123. <refsect1>
  124. <title>See also</title>
  125. <para><xref linkend="ne_iaddr_print"/></para>
  126. </refsect1>
  127. </refentry>