summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authormillert <>2004-12-20 21:13:00 +0000
committermillert <>2004-12-20 21:13:00 +0000
commit8d1da2e74a2ad861ec64a6439e30200a09d5db48 (patch)
treedcc3701cb2baeaf295852861f218fa322aed3f00 /src/lib
parente415ebc824a0a2e9b3a0b9aee96454fe90ffaf40 (diff)
downloadopenbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.tar.gz
openbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.tar.bz2
openbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.zip
New getaddrinfo.3 man page, derived from the ISC version and fleshed
out a bit by me. Needs more work.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/net/getaddrinfo.3300
1 files changed, 300 insertions, 0 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3
new file mode 100644
index 0000000000..2209100c8b
--- /dev/null
+++ b/src/lib/libc/net/getaddrinfo.3
@@ -0,0 +1,300 @@
1.\" $OpenBSD: getaddrinfo.3,v 1.31 2004/12/20 21:13:00 millert Exp $
2.\"
3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4.\" Copyright (C) 2000, 2001 Internet Software Consortium.
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16.\" PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd December 20, 2004
19.Dt GETADDRINFO 3
20.Os
21.Sh NAME
22.Nm getaddrinfo ,
23.Nm freeaddrinfo
24.Nd socket address structure to host and service name
25.Sh SYNOPSIS
26.Fd #include <sys/types.h>
27.Fd #include <sys/socket.h>
28.Fd #include <netdb.h>
29.Ft int
30.Fn getaddrinfo "const char *hostname" "const char *servname" "const struct addrinfo *hints" "struct addrinfo **res"
31.Ft void
32.Fn freeaddrinfo "struct addrinfo *ai"
33.Sh DESCRIPTION
34.Fn getaddrinfo
35is used to get a list of
36.Dv IP
37addresses and port numbers for host
38.Fa hostname
39and service
40.Fa servname .
41It is a replacement for and provides more flexibility than the
42.Xr gethostbyname 3
43and
44.Xr getservbyname 3
45functions.
46.Pp
47.Fa hostname
48and
49.Fa servname
50are either pointers to NUL-terminated strings or the null pointer.
51An acceptable value for
52.Fa hostname
53is either a host name or a numeric host address string consisting
54of a dotted decimal IPv4 address or an IPv6 address.
55The
56.Fa servname
57is either a decimal port number or a service name listed in
58.Xr services 5 .
59At least one of
60.Fa hostname
61and
62.Fa servname
63must be non-null.
64.Pp
65.Fa hints
66is an optional pointer to a
67.Li struct addrinfo ,
68as defined by
69.Aq Pa netdb.h :
70.Bd -literal
71struct addrinfo {
72 int ai_flags; /* input flags */
73 int ai_family; /* protocol family for socket */
74 int ai_socktype; /* socket type */
75 int ai_protocol; /* protocol for socket */
76 socklen_t ai_addrlen; /* length of socket-address */
77 struct sockaddr *ai_addr; /* socket-address for socket */
78 char *ai_canonname; /* canonical name for service location */
79 struct addrinfo *ai_next; /* pointer to next in list */
80};
81.Ed
82.Pp
83This structure can be used to provide hints concerning the type of socket
84that the caller supports or wishes to use.
85The caller can supply the following structure elements in
86.Fa hints :
87.Bl -tag -width "ai_socktypeXX"
88.It Fa ai_family
89The protocol family that should be used.
90When
91.Fa ai_family
92is set to
93.Dv PF_UNSPEC ,
94it means the caller will accept any protocol family supported by the
95operating system.
96.It Fa ai_socktype
97Denotes the type of socket that is wanted:
98.Dv SOCK_STREAM ,
99.Dv SOCK_DGRAM
100or
101.Dv SOCK_RAW .
102When
103.Fa ai_socktype
104is zero the caller will accept any socket type.
105.It Fa ai_protocol
106Indicates which transport protocol is desired,
107.Dv IPPROTO_UDP
108or
109.Dv IPPROTO_TCP .
110If
111.Fa ai_protocol
112is zero the caller will accept any protocol.
113.It Fa ai_flags
114Flag bits.
115.Bl -tag -width "AI_CANONNAMEXX"
116.It Dv AI_CANONNAME
117If the
118.Dv AI_CANONNAME
119bit is set, a successful call to
120.Fn getaddrinfo
121will return a NUL-terminated string containing the canonical name
122of the specified hostname in the
123.Fa ai_canonname
124element of the first
125.Li addrinfo
126structure returned.
127.It Dv AI_NUMERICHOST
128If the
129.Dv AI_NUMERICHOST
130bit is set, it indicates that
131.Fa hostname
132should be treated as a numeric string defining an IPv4 or IPv6 address
133and no name resolution should be attempted.
134.It Dv AI_PASSIVE
135If the
136.Dv AI_PASSIVE
137bit is set it indicates that the returned socket address structure
138is intended for used in a call to
139.Xr bind 2 .
140In this case, if the
141.Fa hostname
142argument is a the null pointer, then the IP address portion of the
143socket address structure will be set to
144.Dv INADDR_ANY
145for an IPv4 address or
146.Dv IN6ADDR_ANY_INIT
147for an IPv6 address.
148.Pp
149If the
150.Dv AI_PASSIVE
151bit is not set, the returned socket address structure will be ready
152for use in a call to
153.Xr connect 2
154for a connection-oriented protocol or
155.Xr connect 2 ,
156.Xr sendto 2
157or
158.Xr sendmsg 2
159if a connectionless protocol was chosen.
160The
161.Dv IP
162address portion of the socket address structure will be set to the
163loopback address if
164.Fa hostname
165is the null pointer and the
166.Dv AI_PASSIVE
167is not set.
168.El
169.El
170.Pp
171All other elements of the
172.Li addrinfo
173structure passed via
174.Fa hints
175must be zero or the null pointer.
176.Pp
177If
178.Fa hints
179is the null pointer,
180.Fn getaddrinfo
181behaves as if the caller provided a
182.Li struct addrinfo
183initialized to zero and with
184.Fa ai_family
185set to
186.Dv PF_UNSPEC .
187.Pp
188After a successful call to
189.Fn getaddrinfo ,
190.Fa *res
191is a pointer to a linked list of one or more
192.Li addrinfo
193structures.
194The list can be traversed by following the
195.Fa ai_next
196pointer in each
197.Li addrinfo
198structure until a null pointer is encountered.
199The three members,
200.Fa ai_family,
201.Fa ai_socktype,
202and
203.Fa ai_protocol
204in each returned
205.Li addrinfo
206structure are suitable for a call to
207.Xr socket 2 .
208For each
209.Li addrinfo
210structure in the list, the
211.Fa ai_addr
212member points to a filled-in socket address structure of length
213.Fa ai_addrlen .
214.Pp
215All of the information returned by
216.Fn getaddrinfo
217is dynamically allocated: the
218.Li addrinfo
219structures themselves as well as the socket address structures and
220the canonical host name strings included in the
221.Li addrinfo
222structures.
223.Pp
224Memory allocated for the dynamically allocated structures created by
225a successful call to
226.Fn getaddrinfo
227is released by the
228.Fn freeaddrinfo
229function.
230The
231.Fa ai
232pointer should be a
233.Li addrinfo
234structure created by a call to
235.Fn getaddrinfo .
236.Sh RETURN VALUES
237.Fn getaddrinfo
238returns zero on success or one of the error codes listed in
239.Xr gai_strerror 3
240if an error occurs.
241If both
242.Fa hostname
243and
244.Fa servname
245are
246.Dv NULL ,
247.Fn getaddrinfo
248returns
249.Dv EAI_NONAME .
250.Sh SEE ALSO
251.Xr bind 2 ,
252.Xr connect 2 ,
253.Xr send 2 ,
254.Xr socket 2 ,
255.Xr gai_strerror 3 ,
256.Xr gethostbyname 3 ,
257.Xr getnameinfo 3 ,
258.Xr getservbyname 3 ,
259.Xr resolver 3 ,
260.Xr hosts 5 ,
261.Xr resolv.conf 5 ,
262.Xr services 5 ,
263.Xr hostname 7 ,
264.Xr named 8
265.Rs
266.%A R. Gilligan
267.%A S. Thomson
268.%A J. Bound
269.%A J. McCann
270.%A W. Stevens
271.%T Basic Socket Interface Extensions for IPv6
272.%R RFC 3493
273.%D February 2003
274.Re
275.Rs
276.%A Tatsuya Jinmei
277.%A Atsushi Onoe
278.%T "An Extension of Format for IPv6 Scoped Addresses"
279.%R internet draft
280.%N draft-ietf-ipngwg-scopedaddr-format-02.txt
281.%O work in progress material
282.Re
283.Rs
284.%A Craig Metz
285.%T Protocol Independence Using the Sockets API
286.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference"
287.%D June 2000
288.Re
289.Sh STANDARDS
290The
291.Fn getaddrinfo
292function is defined by the
293.St -p1003.1g-2000
294draft specification and documented in
295.Dv "RFC 3493" ,
296.Dq Basic Socket Interface Extensions for IPv6 .
297.Sh BUGS
298Due to the use of dynamic allocation,
299.Fn getaddrinfo
300is not thread-safe.