ne_addr_resolve.3 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. '\" t
  2. .\" Title: ne_addr_resolve
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 23 November 2025
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.36.0
  8. .\" Language: English
  9. .\"
  10. .TH "NE_ADDR_RESOLVE" "3" "23 November 2025" "neon 0.36.0" "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_addr_resolve, ne_addr_result, ne_addr_first, ne_addr_next, ne_addr_error, ne_addr_canonical, ne_addr_destroy \- functions to resolve hostnames to addresses
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <ne_socket\&.h>
  37. .fi
  38. .ft
  39. .HP \w'ne_sock_addr\ *ne_addr_resolve('u
  40. .BI "ne_sock_addr *ne_addr_resolve(const\ char\ *" "hostname" ", int\ " "flags" ");"
  41. .HP \w'int\ ne_addr_result('u
  42. .BI "int ne_addr_result(const\ ne_sock_addr\ *" "addr" ");"
  43. .HP \w'const\ ne_inet_addr\ *ne_addr_first('u
  44. .BI "const ne_inet_addr *ne_addr_first(ne_sock_addr\ *" "addr" ");"
  45. .HP \w'const\ ne_inet_addr\ *ne_addr_next('u
  46. .BI "const ne_inet_addr *ne_addr_next(ne_sock_addr\ *" "addr" ");"
  47. .HP \w'char\ *ne_addr_error('u
  48. .BI "char *ne_addr_error(const\ ne_sock_addr\ *" "addr" ", char\ *" "buffer" ", size_t\ " "bufsiz" ");"
  49. .HP \w'const\ char\ *ne_addr_canonical('u
  50. .BI "const char *ne_addr_canonical(const\ ne_sock_addr\ *" "addr" ");"
  51. .HP \w'void\ ne_addr_destroy('u
  52. .BI "void ne_addr_destroy(ne_sock_addr\ *" "addr" ");"
  53. .SH "DESCRIPTION"
  54. .PP
  55. The
  56. \fBne_addr_resolve\fR
  57. function resolves the given
  58. \fIhostname\fR, returning an
  59. \fBne_sock_addr\fR
  60. object representing the address (or addresses) associated with the hostname\&. The
  61. \fIflags\fR
  62. parameter should be zero, or if
  63. NE_ADDR_CANON
  64. used, the canonical name for the hostname will be determined\&.
  65. .PP
  66. The
  67. \fIhostname\fR
  68. passed to
  69. \fBne_addr_resolve\fR
  70. can be a DNS hostname (e\&.g\&.
  71. "www\&.example\&.com") or an IPv4 dotted quad (e\&.g\&.
  72. "192\&.0\&.34\&.72"); or, on systems which support IPv6, an IPv6 hex address, which may be enclosed in brackets, e\&.g\&.
  73. "[::1]"\&.
  74. .PP
  75. To determine whether the hostname was successfully resolved, the
  76. \fBne_addr_result\fR
  77. function is used, which returns non\-zero if an error occurred\&. If an error did occur, the
  78. \fBne_addr_error\fR
  79. function can be used, which will copy the error string into a given
  80. \fIbuffer\fR
  81. (of size
  82. \fIbufsiz\fR)\&.
  83. .PP
  84. The functions
  85. \fBne_addr_first\fR
  86. and
  87. \fBne_addr_next\fR
  88. are used to retrieve the Internet addresses associated with an address object which has been successfully resolved\&.
  89. \fBne_addr_first\fR
  90. returns the first address;
  91. \fBne_addr_next\fR
  92. returns the next address after the most recent call to
  93. \fBne_addr_next\fR
  94. or
  95. \fBne_addr_first\fR, or
  96. NULL
  97. if there are no more addresses\&. The
  98. \fBne_inet_addr\fR
  99. pointer returned by these functions can be passed to
  100. \fBne_sock_connect\fR
  101. to connect a socket\&.
  102. .PP
  103. If the
  104. NE_ADDR_CANON
  105. flag was used with
  106. \fBne_addr_resolve\fR, the canonical hostname can be retrieved using
  107. \fBne_addr_canonical\fR\&.
  108. .PP
  109. After the address object has been used, it should be destroyed using
  110. \fBne_addr_destroy\fR\&.
  111. .SH "RETURN VALUE"
  112. .PP
  113. \fBne_addr_resolve\fR
  114. returns a pointer to an address object, and never
  115. NULL\&.
  116. \fBne_addr_error\fR
  117. returns the
  118. \fIbuffer\fR
  119. parameter\&.
  120. .SH "EXAMPLES"
  121. .PP
  122. The code below prints out the set of addresses associated with the hostname
  123. www\&.google\&.com\&.
  124. .sp
  125. .if n \{\
  126. .RS 4
  127. .\}
  128. .nf
  129. ne_sock_addr *addr;
  130. char buf[256];
  131. addr = ne_addr_resolve("www\&.google\&.com", 0);
  132. if (ne_addr_result(addr)) {
  133. printf("Could not resolve www\&.google\&.com: %s\en",
  134. ne_addr_error(addr, buf, sizeof buf));
  135. } else {
  136. const ne_inet_addr *ia;
  137. printf("www\&.google\&.com:");
  138. for (ia = ne_addr_first(addr); ia != NULL; ia = ne_addr_next(addr)) {
  139. printf(" %s", ne_iaddr_print(ia, buf, sizeof buf));
  140. }
  141. putchar(\*(Aq\en\*(Aq);
  142. }
  143. ne_addr_destroy(addr);
  144. .fi
  145. .if n \{\
  146. .RE
  147. .\}
  148. .SH "HISTORY"
  149. .PP
  150. \fBne_addr_canonical\fR
  151. was added in neon 0\&.30\&.0\&.
  152. .SH "SEE ALSO"
  153. .PP
  154. ne_iaddr_print
  155. .SH "COPYRIGHT"
  156. .br
  157. Copyright \(co 2001-2025 Joe Orton
  158. .br