iaddr.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <refentry id="refiaddr">
  2. <refmeta>
  3. <refentrytitle>ne_iaddr_make</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_iaddr_make">ne_iaddr_make</refname>
  8. <refname id="ne_iaddr_cmp">ne_iaddr_cmp</refname>
  9. <refname id="ne_iaddr_print">ne_iaddr_print</refname>
  10. <refname id="ne_iaddr_typeof">ne_iaddr_typeof</refname>
  11. <refname id="ne_iaddr_parse">ne_iaddr_parse</refname>
  12. <refname id="ne_iaddr_raw">ne_iaddr_raw</refname>
  13. <refname id="ne_iaddr_reverse">ne_iaddr_reverse</refname>
  14. <refname id="ne_iaddr_free">ne_iaddr_free</refname>
  15. <refpurpose>functions to manipulate network addresses</refpurpose>
  16. </refnamediv>
  17. <refsynopsisdiv>
  18. <funcsynopsis>
  19. <funcsynopsisinfo>#include &lt;ne_socket.h&gt;
  20. typedef enum {
  21. ne_iaddr_ipv4 = 0,
  22. ne_iaddr_ipv6
  23. } <type>ne_iaddr_type</type>;</funcsynopsisinfo>
  24. <funcprototype>
  25. <funcdef>ne_inet_addr *<function>ne_iaddr_make</function></funcdef>
  26. <paramdef>ne_iaddr_type <parameter>type</parameter></paramdef>
  27. <paramdef>const unsigned char *<parameter>raw</parameter></paramdef>
  28. </funcprototype>
  29. <funcprototype>
  30. <funcdef>int <function>ne_iaddr_cmp</function></funcdef>
  31. <paramdef>const ne_inet_addr *<parameter>ia1</parameter></paramdef>
  32. <paramdef>const ne_inet_addr *<parameter>ia2</parameter></paramdef>
  33. </funcprototype>
  34. <funcprototype>
  35. <funcdef>char *<function>ne_iaddr_print</function></funcdef>
  36. <paramdef>const ne_inet_addr *<parameter>ia</parameter></paramdef>
  37. <paramdef>char *<parameter>buffer</parameter></paramdef>
  38. <paramdef>size_t <parameter>bufsiz</parameter></paramdef>
  39. </funcprototype>
  40. <funcprototype>
  41. <funcdef>ne_iaddr_type <function>ne_iaddr_typeof</function></funcdef>
  42. <paramdef>const ne_inet_addr *<parameter>ia</parameter></paramdef>
  43. </funcprototype>
  44. <funcprototype>
  45. <funcdef>ne_inet_addr *<function>ne_iaddr_parse</function></funcdef>
  46. <paramdef>const char *<parameter>address</parameter></paramdef>
  47. <paramdef>ne_iaddr_type <parameter>type</parameter></paramdef>
  48. </funcprototype>
  49. <funcprototype>
  50. <funcdef>unsigned char *<function>ne_iaddr_raw</function></funcdef>
  51. <paramdef>const ne_inet_addr *<parameter>ia</parameter></paramdef>
  52. <paramdef>unsigned char *<parameter>buffer</parameter></paramdef>
  53. </funcprototype>
  54. <funcprototype>
  55. <funcdef>int <function>ne_iaddr_reverse</function></funcdef>
  56. <paramdef>const ne_inet_addr *<parameter>ia</parameter></paramdef>
  57. <paramdef>char *<parameter>buffer</parameter></paramdef>
  58. <paramdef>size_t <parameter>buflen</parameter></paramdef>
  59. </funcprototype>
  60. <funcprototype>
  61. <funcdef>void <function>ne_iaddr_free</function></funcdef>
  62. <paramdef>const ne_inet_addr *<parameter>ia</parameter></paramdef>
  63. </funcprototype>
  64. </funcsynopsis>
  65. </refsynopsisdiv>
  66. <refsect1>
  67. <title>Description</title>
  68. <para><function>ne_iaddr_make</function> creates an
  69. <type>ne_inet_addr</type> object from a raw binary network
  70. address; for instance the four bytes <literal>0x7f 0x00 0x00
  71. 0x01</literal> represent the IPv4 address
  72. <literal>127.0.0.1</literal>. The object returned is suitable for
  73. passing to <function>ne_sock_connect</function>. A binary IPv4
  74. address contains four bytes; a binary IPv6 address contains
  75. sixteen bytes; addresses passed must be in network byte
  76. order.</para>
  77. <para><function>ne_iaddr_cmp</function> compares two network
  78. address objects; returning zero only if they are identical. The
  79. objects need not have the same address type; if the addresses are
  80. not of the same type, the return value is guaranteed to be
  81. non-zero.</para>
  82. <para><function>ne_iaddr_print</function> prints a human-readable
  83. string representation of a network address into a buffer, for
  84. instance the string <literal>"127.0.0.1"</literal>.</para>
  85. <para><function>ne_iaddr_typeof</function> returns the type of the
  86. given network address object.</para>
  87. <para><function>ne_iaddr_parse</function> parses a string
  88. representation of a network address (such as
  89. <literal>"127.0.0.1"</literal> and creates a network address
  90. object to represent the parsed address.</para>
  91. <para><function>ne_iaddr_raw</function> writes the raw byte
  92. representation of a network address to the provided buffer. The
  93. bytes are written in network byte order; the buffer must be of
  94. suitable length for the type of address (4 bytes for an IPv4
  95. address, 16 bytes for an IPv6 address).</para>
  96. <para><function>ne_iaddr_reverse</function> performs a reverse
  97. name lookup on the address object, writing the (first) hostname
  98. associated with the IP address to the provided buffer. If the
  99. hostname is longer than the buffer it will be silently truncated;
  100. on success the string written to the buffer is always
  101. &nul;-terminated.</para>
  102. <para><function>ne_iaddr_free</function> releases the memory
  103. associated with a network address object.</para>
  104. </refsect1>
  105. <refsect1>
  106. <title>Return value</title>
  107. <para><function>ne_iaddr_make</function> returns &null; if the
  108. address type passed is not supported (for instance on a platform
  109. which does not support IPv6).</para>
  110. <para><function>ne_iaddr_print</function> returns the
  111. <parameter>buffer</parameter> pointer, and never &null;.</para>
  112. <para><function>ne_iaddr_parse</function> returns a network
  113. address object on success, or &null; on failure to parse the
  114. <parameter>address</parameter> parameter.</para>
  115. <para><function>ne_iaddr_reverse</function> returns zero on
  116. success or non-zero if no hostname is associated with the
  117. address.</para>
  118. <para><function>ne_iaddr_raw</function> returns the
  119. <parameter>buffer</parameter> parameter, and never &null;.</para>
  120. </refsect1>
  121. <refsect1>
  122. <title>Examples</title>
  123. <para>The following example connects a socket to port 80 at the
  124. address <literal>127.0.0.1</literal>.</para>
  125. <programlisting>unsigned char addr[] = "\0x7f\0x00\0x00\0x01";
  126. ne_inet_addr *ia;
  127. ia = ne_iaddr_make(ne_iaddr_ipv4, addr);
  128. if (ia != NULL) {
  129. ne_socket *sock = ne_sock_connect(ia, 80);
  130. ne_iaddr_free(ia);
  131. /* ... */
  132. } else {
  133. /* ... */
  134. }</programlisting>
  135. </refsect1>
  136. <refsect1>
  137. <title>See also</title>
  138. <para><xref linkend="ne_addr_resolve"/></para>
  139. </refsect1>
  140. </refentry>