resolve.xml 5.0 KB

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