ne_iaddr_make.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. '\" t
  2. .\" Title: ne_iaddr_make
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 21 January 2023
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.32.5
  8. .\" Language: English
  9. .\"
  10. .TH "NE_IADDR_MAKE" "3" "21 January 2023" "neon 0.32.5" "neon API reference"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. ne_iaddr_make, ne_iaddr_cmp, ne_iaddr_print, ne_iaddr_typeof, ne_iaddr_parse, ne_iaddr_raw, ne_iaddr_reverse, ne_iaddr_free \- functions to manipulate network addresses
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <ne_socket\&.h>
  37. typedef enum {
  38. ne_iaddr_ipv4 = 0,
  39. ne_iaddr_ipv6
  40. } ne_iaddr_type;
  41. .fi
  42. .ft
  43. .HP \w'ne_inet_addr\ *ne_iaddr_make('u
  44. .BI "ne_inet_addr *ne_iaddr_make(ne_iaddr_type\ " "type" ", const\ unsigned\ char\ *" "raw" ");"
  45. .HP \w'int\ ne_iaddr_cmp('u
  46. .BI "int ne_iaddr_cmp(const\ ne_inet_addr\ *" "ia1" ", const\ ne_inet_addr\ *" "ia2" ");"
  47. .HP \w'char\ *ne_iaddr_print('u
  48. .BI "char *ne_iaddr_print(const\ ne_inet_addr\ *" "ia" ", char\ *" "buffer" ", size_t\ " "bufsiz" ");"
  49. .HP \w'ne_iaddr_type\ ne_iaddr_typeof('u
  50. .BI "ne_iaddr_type ne_iaddr_typeof(const\ ne_inet_addr\ *" "ia" ");"
  51. .HP \w'ne_inet_addr\ *ne_iaddr_parse('u
  52. .BI "ne_inet_addr *ne_iaddr_parse(const\ char\ *" "address" ", ne_iaddr_type\ " "type" ");"
  53. .HP \w'unsigned\ char\ *ne_iaddr_raw('u
  54. .BI "unsigned char *ne_iaddr_raw(const\ ne_inet_addr\ *" "ia" ", unsigned\ char\ *" "buffer" ");"
  55. .HP \w'int\ ne_iaddr_reverse('u
  56. .BI "int ne_iaddr_reverse(const\ ne_inet_addr\ *" "ia" ", char\ *" "buffer" ", size_t\ " "buflen" ");"
  57. .HP \w'void\ ne_iaddr_free('u
  58. .BI "void ne_iaddr_free(const\ ne_inet_addr\ *" "ia" ");"
  59. .SH "DESCRIPTION"
  60. .PP
  61. \fBne_iaddr_make\fR
  62. creates an
  63. \fBne_inet_addr\fR
  64. object from a raw binary network address; for instance the four bytes
  65. 0x7f 0x00 0x00 0x01
  66. represent the IPv4 address
  67. 127\&.0\&.0\&.1\&. The object returned is suitable for passing to
  68. \fBne_sock_connect\fR\&. A binary IPv4 address contains four bytes; a binary IPv6 address contains sixteen bytes; addresses passed must be in network byte order\&.
  69. .PP
  70. \fBne_iaddr_cmp\fR
  71. compares two network address objects; returning zero only if they are identical\&. The objects need not have the same address type; if the addresses are not of the same type, the return value is guaranteed to be non\-zero\&.
  72. .PP
  73. \fBne_iaddr_print\fR
  74. prints a human\-readable string representation of a network address into a buffer, for instance the string
  75. "127\&.0\&.0\&.1"\&.
  76. .PP
  77. \fBne_iaddr_typeof\fR
  78. returns the type of the given network address object\&.
  79. .PP
  80. \fBne_iaddr_parse\fR
  81. parses a string representation of a network address (such as
  82. "127\&.0\&.0\&.1"
  83. and creates a network address object to represent the parsed address\&.
  84. .PP
  85. \fBne_iaddr_raw\fR
  86. writes the raw byte representation of a network address to the provided buffer\&. The bytes are written in network byte order; the buffer must be of suitable length for the type of address (4 bytes for an IPv4 address, 16 bytes for an IPv6 address)\&.
  87. .PP
  88. \fBne_iaddr_reverse\fR
  89. performs a reverse name lookup on the address object, writing the (first) hostname associated with the IP address to the provided buffer\&. If the hostname is longer than the buffer it will be silently truncated; on success the string written to the buffer is always
  90. NUL\-terminated\&.
  91. .PP
  92. \fBne_iaddr_free\fR
  93. releases the memory associated with a network address object\&.
  94. .SH "RETURN VALUE"
  95. .PP
  96. \fBne_iaddr_make\fR
  97. returns
  98. NULL
  99. if the address type passed is not supported (for instance on a platform which does not support IPv6)\&.
  100. .PP
  101. \fBne_iaddr_print\fR
  102. returns the
  103. \fIbuffer\fR
  104. pointer, and never
  105. NULL\&.
  106. .PP
  107. \fBne_iaddr_parse\fR
  108. returns a network address object on success, or
  109. NULL
  110. on failure to parse the
  111. \fIaddress\fR
  112. parameter\&.
  113. .PP
  114. \fBne_iaddr_reverse\fR
  115. returns zero on success or non\-zero if no hostname is associated with the address\&.
  116. .PP
  117. \fBne_iaddr_raw\fR
  118. returns the
  119. \fIbuffer\fR
  120. parameter, and never
  121. NULL\&.
  122. .SH "EXAMPLES"
  123. .PP
  124. The following example connects a socket to port 80 at the address
  125. 127\&.0\&.0\&.1\&.
  126. .sp
  127. .if n \{\
  128. .RS 4
  129. .\}
  130. .nf
  131. unsigned char addr[] = "\e0x7f\e0x00\e0x00\e0x01";
  132. ne_inet_addr *ia;
  133. ia = ne_iaddr_make(ne_iaddr_ipv4, addr);
  134. if (ia != NULL) {
  135. ne_socket *sock = ne_sock_connect(ia, 80);
  136. ne_iaddr_free(ia);
  137. /* \&.\&.\&. */
  138. } else {
  139. /* \&.\&.\&. */
  140. }
  141. .fi
  142. .if n \{\
  143. .RE
  144. .\}
  145. .SH "SEE ALSO"
  146. .PP
  147. ne_addr_resolve
  148. .SH "AUTHOR"
  149. .PP
  150. \fBJoe Orton\fR
  151. .RS 4
  152. Author.
  153. .RE
  154. .SH "COPYRIGHT"
  155. .br