/contrib/bind9/lib/lwres/man/lwres_getaddrinfo.html

https://bitbucket.org/freebsd/freebsd-head/ · HTML · 322 lines · 289 code · 16 blank · 17 comment · 0 complexity · 3ce1a0c80ebd0476ae9c3d989ef9379c MD5 · raw file

  1. <!--
  2. - Copyright (C) 2004, 2005, 2007, 2012 Internet Systems Consortium, Inc. ("ISC")
  3. - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
  4. -
  5. - Permission to use, copy, modify, and/or distribute this software for any
  6. - purpose with or without fee is hereby granted, provided that the above
  7. - copyright notice and this permission notice appear in all copies.
  8. -
  9. - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. - PERFORMANCE OF THIS SOFTWARE.
  16. -->
  17. <!-- $Id$ -->
  18. <html>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  21. <title>lwres_getaddrinfo</title>
  22. <meta name="generator" content="DocBook XSL Stylesheets V1.71.1">
  23. </head>
  24. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
  25. <a name="id2476275"></a><div class="titlepage"></div>
  26. <div class="refnamediv">
  27. <h2>Name</h2>
  28. <p>lwres_getaddrinfo, lwres_freeaddrinfo &#8212; socket address structure to host and service name</p>
  29. </div>
  30. <div class="refsynopsisdiv">
  31. <h2>Synopsis</h2>
  32. <div class="funcsynopsis">
  33. <pre class="funcsynopsisinfo">#include &lt;lwres/netdb.h&gt;</pre>
  34. <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
  35. <tr>
  36. <td><code class="funcdef">
  37. int
  38. <b class="fsfunc">lwres_getaddrinfo</b>(</code></td>
  39. <td>const char * </td>
  40. <td>
  41. <var class="pdparam">hostname</var>, </td>
  42. </tr>
  43. <tr>
  44. <td> </td>
  45. <td>const char * </td>
  46. <td>
  47. <var class="pdparam">servname</var>, </td>
  48. </tr>
  49. <tr>
  50. <td> </td>
  51. <td>const struct addrinfo * </td>
  52. <td>
  53. <var class="pdparam">hints</var>, </td>
  54. </tr>
  55. <tr>
  56. <td> </td>
  57. <td>struct addrinfo ** </td>
  58. <td>
  59. <var class="pdparam">res</var><code>)</code>;</td>
  60. </tr>
  61. </table>
  62. <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr>
  63. <td><code class="funcdef">
  64. void
  65. <b class="fsfunc">lwres_freeaddrinfo</b>(</code></td>
  66. <td>struct addrinfo * </td>
  67. <td>
  68. <var class="pdparam">ai</var><code>)</code>;</td>
  69. </tr></table>
  70. </div>
  71. <p>
  72. If the operating system does not provide a
  73. <span class="type">struct addrinfo</span>,
  74. the following structure is used:
  75. </p>
  76. <pre class="programlisting">
  77. struct addrinfo {
  78. int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
  79. int ai_family; /* PF_xxx */
  80. int ai_socktype; /* SOCK_xxx */
  81. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  82. size_t ai_addrlen; /* length of ai_addr */
  83. char *ai_canonname; /* canonical name for hostname */
  84. struct sockaddr *ai_addr; /* binary address */
  85. struct addrinfo *ai_next; /* next structure in linked list */
  86. };
  87. </pre>
  88. <p>
  89. </p>
  90. </div>
  91. <div class="refsect1" lang="en">
  92. <a name="id2543416"></a><h2>DESCRIPTION</h2>
  93. <p><code class="function">lwres_getaddrinfo()</code>
  94. is used to get a list of IP addresses and port numbers for host
  95. <em class="parameter"><code>hostname</code></em> and service
  96. <em class="parameter"><code>servname</code></em>.
  97. The function is the lightweight resolver's implementation of
  98. <code class="function">getaddrinfo()</code> as defined in RFC2133.
  99. <em class="parameter"><code>hostname</code></em> and
  100. <em class="parameter"><code>servname</code></em> are pointers to null-terminated
  101. strings or <span class="type">NULL</span>.
  102. <em class="parameter"><code>hostname</code></em> is either a host name or a
  103. numeric host address string: a dotted decimal IPv4 address or an
  104. IPv6 address. <em class="parameter"><code>servname</code></em> is either a
  105. decimal port number or a service name as listed in
  106. <code class="filename">/etc/services</code>.
  107. </p>
  108. <p><em class="parameter"><code>hints</code></em>
  109. is an optional pointer to a
  110. <span class="type">struct addrinfo</span>.
  111. This structure can be used to provide hints concerning the type of
  112. socket
  113. that the caller supports or wishes to use.
  114. The caller can supply the following structure elements in
  115. <em class="parameter"><code>*hints</code></em>:
  116. </p>
  117. <div class="variablelist"><dl>
  118. <dt><span class="term"><code class="constant">ai_family</code></span></dt>
  119. <dd><p>
  120. The protocol family that should be used.
  121. When
  122. <code class="constant">ai_family</code>
  123. is set to
  124. <span class="type">PF_UNSPEC</span>,
  125. it means the caller will accept any protocol family supported by
  126. the
  127. operating system.
  128. </p></dd>
  129. <dt><span class="term"><code class="constant">ai_socktype</code></span></dt>
  130. <dd><p>
  131. denotes the type of socket &#8212;
  132. <span class="type">SOCK_STREAM</span>,
  133. <span class="type">SOCK_DGRAM</span>
  134. or
  135. <span class="type">SOCK_RAW</span>
  136. &#8212; that is wanted.
  137. When
  138. <code class="constant">ai_socktype</code>
  139. is zero the caller will accept any socket type.
  140. </p></dd>
  141. <dt><span class="term"><code class="constant">ai_protocol</code></span></dt>
  142. <dd><p>
  143. indicates which transport protocol is wanted: IPPROTO_UDP or
  144. IPPROTO_TCP.
  145. If
  146. <code class="constant">ai_protocol</code>
  147. is zero the caller will accept any protocol.
  148. </p></dd>
  149. <dt><span class="term"><code class="constant">ai_flags</code></span></dt>
  150. <dd>
  151. <p>
  152. Flag bits.
  153. If the
  154. <span class="type">AI_CANONNAME</span>
  155. bit is set, a successful call to
  156. <code class="function">lwres_getaddrinfo()</code>
  157. will return a null-terminated string containing the canonical
  158. name
  159. of the specified hostname in
  160. <code class="constant">ai_canonname</code>
  161. of the first
  162. <span class="type">addrinfo</span>
  163. structure returned.
  164. Setting the
  165. <span class="type">AI_PASSIVE</span>
  166. bit indicates that the returned socket address structure is
  167. intended
  168. for used in a call to
  169. <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>.
  170. In this case, if the hostname argument is a
  171. <span class="type">NULL</span>
  172. pointer, then the IP address portion of the socket
  173. address structure will be set to
  174. <span class="type">INADDR_ANY</span>
  175. for an IPv4 address or
  176. <span class="type">IN6ADDR_ANY_INIT</span>
  177. for an IPv6 address.
  178. </p>
  179. <p>
  180. When
  181. <code class="constant">ai_flags</code>
  182. does not set the
  183. <span class="type">AI_PASSIVE</span>
  184. bit, the returned socket address structure will be ready
  185. for use in a call to
  186. <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>
  187. for a connection-oriented protocol or
  188. <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
  189. <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
  190. or
  191. <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2)</span>
  192. if a connectionless protocol was chosen.
  193. The IP address portion of the socket address structure will be
  194. set to the loopback address if
  195. <em class="parameter"><code>hostname</code></em>
  196. is a
  197. <span class="type">NULL</span>
  198. pointer and
  199. <span class="type">AI_PASSIVE</span>
  200. is not set in
  201. <code class="constant">ai_flags</code>.
  202. </p>
  203. <p>
  204. If
  205. <code class="constant">ai_flags</code>
  206. is set to
  207. <span class="type">AI_NUMERICHOST</span>
  208. it indicates that
  209. <em class="parameter"><code>hostname</code></em>
  210. should be treated as a numeric string defining an IPv4 or IPv6
  211. address
  212. and no name resolution should be attempted.
  213. </p>
  214. </dd>
  215. </dl></div>
  216. <p>
  217. </p>
  218. <p>
  219. All other elements of the <span class="type">struct addrinfo</span> passed
  220. via <em class="parameter"><code>hints</code></em> must be zero.
  221. </p>
  222. <p>
  223. A <em class="parameter"><code>hints</code></em> of <span class="type">NULL</span> is
  224. treated as if
  225. the caller provided a <span class="type">struct addrinfo</span> initialized to zero
  226. with <code class="constant">ai_family</code>set to
  227. <code class="constant">PF_UNSPEC</code>.
  228. </p>
  229. <p>
  230. After a successful call to
  231. <code class="function">lwres_getaddrinfo()</code>,
  232. <em class="parameter"><code>*res</code></em>
  233. is a pointer to a linked list of one or more
  234. <span class="type">addrinfo</span>
  235. structures.
  236. Each
  237. <span class="type">struct addrinfo</span>
  238. in this list cn be processed by following
  239. the
  240. <code class="constant">ai_next</code>
  241. pointer, until a
  242. <span class="type">NULL</span>
  243. pointer is encountered.
  244. The three members
  245. <code class="constant">ai_family</code>,
  246. <code class="constant">ai_socktype</code>,
  247. and
  248. <code class="constant">ai_protocol</code>
  249. in each
  250. returned
  251. <span class="type">addrinfo</span>
  252. structure contain the corresponding arguments for a call to
  253. <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.
  254. For each
  255. <span class="type">addrinfo</span>
  256. structure in the list, the
  257. <code class="constant">ai_addr</code>
  258. member points to a filled-in socket address structure of length
  259. <code class="constant">ai_addrlen</code>.
  260. </p>
  261. <p>
  262. All of the information returned by
  263. <code class="function">lwres_getaddrinfo()</code>
  264. is dynamically allocated: the addrinfo structures, and the socket
  265. address structures and canonical host name strings pointed to by the
  266. <code class="constant">addrinfo</code>structures.
  267. Memory allocated for the dynamically allocated structures created by
  268. a successful call to
  269. <code class="function">lwres_getaddrinfo()</code>
  270. is released by
  271. <code class="function">lwres_freeaddrinfo()</code>.
  272. <em class="parameter"><code>ai</code></em>
  273. is a pointer to a
  274. <span class="type">struct addrinfo</span>
  275. created by a call to
  276. <code class="function">lwres_getaddrinfo()</code>.
  277. </p>
  278. </div>
  279. <div class="refsect1" lang="en">
  280. <a name="id2543794"></a><h2>RETURN VALUES</h2>
  281. <p><code class="function">lwres_getaddrinfo()</code>
  282. returns zero on success or one of the error codes listed in
  283. <span class="citerefentry"><span class="refentrytitle">gai_strerror</span>(3)</span>
  284. if an error occurs. If both <em class="parameter"><code>hostname</code></em> and
  285. <em class="parameter"><code>servname</code></em> are <span class="type">NULL</span>
  286. <code class="function">lwres_getaddrinfo()</code> returns
  287. <span class="errorcode">EAI_NONAME</span>.
  288. </p>
  289. </div>
  290. <div class="refsect1" lang="en">
  291. <a name="id2543831"></a><h2>SEE ALSO</h2>
  292. <p><span class="citerefentry"><span class="refentrytitle">lwres</span>(3)</span>,
  293. <span class="citerefentry"><span class="refentrytitle">lwres_getaddrinfo</span>(3)</span>,
  294. <span class="citerefentry"><span class="refentrytitle">lwres_freeaddrinfo</span>(3)</span>,
  295. <span class="citerefentry"><span class="refentrytitle">lwres_gai_strerror</span>(3)</span>,
  296. <span class="citerefentry"><span class="refentrytitle">RFC2133</span></span>,
  297. <span class="citerefentry"><span class="refentrytitle">getservbyname</span>(3)</span>,
  298. <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>,
  299. <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
  300. <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
  301. <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2)</span>,
  302. <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.
  303. </p>
  304. </div>
  305. </div></body>
  306. </html>