summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritojun <>2005-01-06 03:50:46 +0000
committeritojun <>2005-01-06 03:50:46 +0000
commit5cd91abe22e27dff54bafd3c933875170e8050b3 (patch)
treef7183ae01ae9185706105a0d04b95df5c1ebd270
parenta245c0c3e4906a7edc9c51d13b92a181df2b6d8d (diff)
downloadopenbsd-5cd91abe22e27dff54bafd3c933875170e8050b3.tar.gz
openbsd-5cd91abe22e27dff54bafd3c933875170e8050b3.tar.bz2
openbsd-5cd91abe22e27dff54bafd3c933875170e8050b3.zip
IPv6 manpage, wrote from scratch. deraadt ok
-rw-r--r--src/lib/libc/net/gai_strerror.33
-rw-r--r--src/lib/libc/net/getaddrinfo.318
-rw-r--r--src/lib/libc/net/getnameinfo.320
-rw-r--r--src/lib/libc/net/inet6_option_space.3434
-rw-r--r--src/lib/libc/net/inet6_rthdr_space.3305
5 files changed, 764 insertions, 16 deletions
diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3
index 06caac0993..d0a636ee03 100644
--- a/src/lib/libc/net/gai_strerror.3
+++ b/src/lib/libc/net/gai_strerror.3
@@ -1,4 +1,5 @@
1.\" $OpenBSD: gai_strerror.3,v 1.4 2004/12/20 23:04:53 millert Exp $ 1.\" $OpenBSD: gai_strerror.3,v 1.5 2005/01/06 03:50:46 itojun Exp $
2.\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $
2.\" 3.\"
3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 4.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4.\" Copyright (C) 2000, 2001 Internet Software Consortium. 5.\" Copyright (C) 2000, 2001 Internet Software Consortium.
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3
index 4fba44bb73..64f317c010 100644
--- a/src/lib/libc/net/getaddrinfo.3
+++ b/src/lib/libc/net/getaddrinfo.3
@@ -1,4 +1,5 @@
1.\" $OpenBSD: getaddrinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $ 1.\" $OpenBSD: getaddrinfo.3,v 1.36 2005/01/06 03:50:46 itojun Exp $
2.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $
2.\" 3.\"
3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 4.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4.\" Copyright (C) 2000, 2001 Internet Software Consortium. 5.\" Copyright (C) 2000, 2001 Internet Software Consortium.
@@ -222,7 +223,8 @@ member points to a filled-in socket address structure of length
222.Pp 223.Pp
223This implementation of 224This implementation of
224.Fn getaddrinfo 225.Fn getaddrinfo
225allows experimental numeric IPv6 address notation with scope identifiers. 226allows numeric IPv6 address notation with scope identifier,
227as documented in chapter 11 of draft-ietf-ipv6-scoping-arch-02.txt.
226By appending the percent character and scope identifier to addresses, 228By appending the percent character and scope identifier to addresses,
227one can fill the 229one can fill the
228.Li sin6_scope_id 230.Li sin6_scope_id
@@ -248,7 +250,6 @@ on the link associated with the
248interface 250interface
249.Dc . 251.Dc .
250.Pp 252.Pp
251The IPv6 implementation is still very experimental and non-standard.
252The current implementation assumes a one-to-one relationship between 253The current implementation assumes a one-to-one relationship between
253the interface and link, which is not necessarily true from the specification. 254the interface and link, which is not necessarily true from the specification.
254.Pp 255.Pp
@@ -403,11 +404,14 @@ freeaddrinfo(res0);
403.%D February 2003 404.%D February 2003
404.Re 405.Re
405.Rs 406.Rs
406.%A Tatsuya Jinmei 407.%A S. Deering
407.%A Atsushi Onoe 408.%A B. Haberman
408.%T "An Extension of Format for IPv6 Scoped Addresses" 409.%A T. Jinmei
410.%A E. Nordmark
411.%A B. Zill
412.%T "IPv6 Scoped Address Architecture"
409.%R internet draft 413.%R internet draft
410.%N draft-ietf-ipngwg-scopedaddr-format-02.txt 414.%N draft-ietf-ipv6-scoping-arch-02.txt
411.%O work in progress material 415.%O work in progress material
412.Re 416.Re
413.Rs 417.Rs
diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3
index a6f2c63a91..39f9b8e14e 100644
--- a/src/lib/libc/net/getnameinfo.3
+++ b/src/lib/libc/net/getnameinfo.3
@@ -1,4 +1,5 @@
1.\" $OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $ 1.\" $OpenBSD: getnameinfo.3,v 1.37 2005/01/06 03:50:46 itojun Exp $
2.\" $KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
2.\" 3.\"
3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 4.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4.\" Copyright (C) 2000, 2001 Internet Software Consortium. 5.\" Copyright (C) 2000, 2001 Internet Software Consortium.
@@ -115,8 +116,8 @@ and
115.Tn TCP . 116.Tn TCP .
116.El 117.El
117.Pp 118.Pp
118This implementation allows experimental numeric IPv6 address notation with 119This implementation allows numeric IPv6 address notation with scope identifier,
119scope identifier. 120as documented in chapter 11 of draft-ietf-ipv6-scoping-arch-02.txt.
120IPv6 link-local address will appear as a string like 121IPv6 link-local address will appear as a string like
121.Dq Li fe80::1%ne0 . 122.Dq Li fe80::1%ne0 .
122Refer to 123Refer to
@@ -177,11 +178,14 @@ printf("host=%s\en", hbuf);
177.%D March 1999 178.%D March 1999
178.Re 179.Re
179.Rs 180.Rs
180.%A Tatsuya Jinmei 181.%A S. Deering
181.%A Atsushi Onoe 182.%A B. Haberman
182.%T "An Extension of Format for IPv6 Scoped Addresses" 183.%A T. Jinmei
184.%A E. Nordmark
185.%A B. Zill
186.%T "IPv6 Scoped Address Architecture"
183.%R internet draft 187.%R internet draft
184.%N draft-ietf-ipngwg-scopedaddr-format-02.txt 188.%N draft-ietf-ipv6-scoping-arch-02.txt
185.%O work in progress material 189.%O work in progress material
186.Re 190.Re
187.Rs 191.Rs
@@ -255,7 +259,7 @@ if (error == 0) {
255.Ed 259.Ed
256.Sh BUGS 260.Sh BUGS
257The implementation of 261The implementation of
258.Fn getaddrinfo 262.Fn getnameinfo
259is not thread-safe. 263is not thread-safe.
260.Pp 264.Pp
261.Ox 265.Ox
diff --git a/src/lib/libc/net/inet6_option_space.3 b/src/lib/libc/net/inet6_option_space.3
new file mode 100644
index 0000000000..9b5cac95e8
--- /dev/null
+++ b/src/lib/libc/net/inet6_option_space.3
@@ -0,0 +1,434 @@
1.\" $OpenBSD: inet6_option_space.3,v 1.15 2005/01/06 03:50:46 itojun Exp $
2.\" $KAME: inet6_option_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $
3.\"
4.\" Copyright (C) 2004 WIDE Project.
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the project nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd December 23, 2004
32.Dt INET6_OPTION_SPACE 3
33.Os
34.\"
35.Sh NAME
36.Nm inet6_option_space ,
37.Nm inet6_option_init ,
38.Nm inet6_option_append ,
39.Nm inet6_option_alloc ,
40.Nm inet6_option_next ,
41.Nm inet6_option_find
42.Nd IPv6 Hop-by-Hop and Destination Option Manipulation
43.\"
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In sys/types.h
48.In netinet/in.h
49.Ft "int"
50.Fn inet6_option_space "int nbytes"
51.Ft "int"
52.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type"
53.Ft "int"
54.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy"
55.Ft "u_int8_t *"
56.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy"
57.Ft "int"
58.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp"
59.Ft "int"
60.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type"
61.\"
62.Sh DESCRIPTION
63.\"
64Manipulating and parsing IPv6's Hop-by-Hop and Destination options is
65complicated by the need to properly align and pad data as well as the
66need to manipulate ancillary information that is not part of the data
67stream.
68RFC2292 defines a set of functions, which are implemented as
69part of the Kame libraries, to support help developers create, change,
70and parse Hop-by-Hope and Destination options.
71All of the prototypes
72for the option functions are defined in the
73.In netinet/in.h
74header file.
75.\"
76.Ss inet6_option_space
77In order to determine the amount of space necessary to hold any option
78the
79.Fn inet6_option_space
80function is called.
81It returns the number of bytes required to hold
82an option when it is stored as ancillary data, including the
83.Li cmsghdr
84structure at the beginning, and any necessary padding at the end.
85The
86.Li nbytes
87argument indicates the size of the structure defining the option,
88and must include any pad bytes at the beginning (the value
89.Li y
90in the alignment term
91.Dq Li "xn + y" ) ,
92the type byte, the length byte, and the option data.
93.Pp
94Note: If multiple options are stored in a single ancillary data
95object, which is the recommended technique, the
96.Fn inet6_option_space
97function overestimates the amount of space required by the size of
98.Li N-1
99.Li cmsghdr
100structures, where
101.Li N
102is the number of options to be stored in the object.
103Usually this has
104no impact because it is assumed that most Hop-by-Hop and Destination
105option headers carry only one option as indicated in appendix B of RFC2460.
106.\"
107.Ss inet6_option_init
108The
109.Fn inet6_option_init
110function is called to initialize any ancillary data object that will contain
111a Hop-by-Hop or Destination option.
112It returns
113.Li 0
114on success and
115.Li -1
116when an error occurs.
117.Pp
118The
119.Fa bp
120argument points to a previously allocated area of memory which must be
121large enough to contain all the arguments that the application indents
122to add later via
123.Fn inet6_option_append
124and
125.Fn inet6_option_alloc
126routines.
127.Pp
128The
129.Fa cmsgp
130argument is a pointer to a pointer to a
131.Li cmsghdr
132structure.
133The
134.Fa *cmsgp
135argument
136points to a
137.Li cmsghdr
138structure which is constructed by this function and stored in the
139area of memory pointed to by
140.Fa bp .
141.Pp
142The
143.Fa type
144is either
145.Dv IPV6_HOPOPTS
146or
147.Dv IPV6_DSTOPTS
148and is stored in the
149.Li cmsg_type
150member of the
151.Li cmsghdr
152structure mentioned above.
153.\"
154.Ss inet6_option_append
155This function appends a Hop-by-Hop option or a Destination option into
156an ancillary data object previously initialized by a call to
157.Fn inet6_option_init .
158The
159.Fn inet6_option_append function returns
160.Li 0
161if it succeeds or
162.Li -1
163when an error occurs.
164.Pp
165The
166.Fa cmsg
167argument is a pointer to the
168.Li cmsghdr
169structure that was initialized by a call to
170.Fn inet6_option_init .
171.Pp
172The
173.Fa typep
174argument is a pointer to the 8-bit option type.
175All options are
176encoded as type-length-value tuples and it is assumed that
177the
178.Fa typep
179field is immediately followed by the 8-bit option data length field,
180which is then followed by the option data.
181.Pp
182The option types of
183.Li 0
184and
185.Li 1 are reserved for the
186.Li Pad1
187and
188.Li PadN
189options respectively.
190All other values from
191.Li 2
192through
193.Li 255
194are available for applications to use.
195.Pp
196The option data length, since it is stored in 8 bites, must have a
197value between
198.Li 0
199and
200.Li 255 ,
201inclusive.
202.Pp
203The
204.Fa multx
205argument
206is the value
207.Li x
208in the alignment term
209.Dq Li xn + y
210and indicates the byte alignment necessary for the data.
211Alignments may be specified as
212.Li 1 ,
213.Li 2 ,
214.Li 4 ,
215or
216.Li 8
217bytes, which is no alignment, 16 bit, 32 bit and 64 bit alignments
218respectively.
219.Pp
220The
221.Fa plusy
222argument
223is the value
224.Li y
225in the alignment term
226.Dq Li xn + y
227and must have a value between
228.Li 0
229and
230.Li 7 ,
231inclusive, indicating the amount of padding that is necessary for an
232option.
233.\"
234.Ss inet6_option_alloc
235The
236.Fn inet6_option_alloc
237function appends a Hop-by-Hop option or a Destination option into an
238ancillary data object that has previously been initialized by a call to
239.Fn inet6_option_init .
240The
241.Fn inet6_option_alloc
242function returns a pointer to the 8-bit option type field that at the
243beginning of the allocated the option on success, or
244.Dv NULL
245on an error.
246.Pp
247The difference between the
248.Fn inet6_option_alloc
249and
250.Fn inet6_option_append
251functions is that the latter copies the contents of a previously built
252option into the ancillary data object while the former returns a
253pointer to the place in the data object where the option's TLV must
254then be built by the application.
255.Pp
256The
257.Fa cmsg
258argument is a pointer to a
259.Li cmsghdr
260structure that was initialized by
261.Fn inet6_option_init .
262.Pp
263The
264.Fa datalen
265argument is the value of the option data length byte for this option.
266This value is required as an argument to allow the function to
267determine if padding must be appended at the end of the option.
268(The
269.Fn inet6_option_append
270function does not need a data length argument
271since the option data length must already be stored by the caller)
272.Pp
273The
274.Fa multx
275and
276.Fa plusy
277arguments
278are identical to the arguments of the same name described in the
279.Fn inet6_option_init
280function above.
281.\"
282.Ss inet6_option_next
283The
284.Fn inet6_option_next
285function is used to process Hop-by-Hop and Destination options that
286are present in an ancillary data object.
287When an option remains to
288be processed, the return value of the
289.Fn inet6_option_next
290function is
291.Li 0
292and the
293.Fa *tptrp
294argument points to the 8-bit option type field, which is followed by
295the 8-bit option data length, and then the option data.
296When no more
297options remain to be processed, the return value is
298.Li -1
299and
300.Fa *tptrp
301is
302.Dv NULL
303and when an error occurs, the return value is
304.Li -1
305but the
306.Fa *tptrp
307argument is not
308.Dv NULL .
309This set of return values allows a program to easily loop through all
310the options in an ancillary data object, checking for the error and
311end of stream conditions along the way.
312.Pp
313When a valid option is returned the
314.Fa cmsg
315argument points to a
316.Li cmsghdr
317where the
318.Li cmsg_level
319equals
320.Dv IPPROTO_IPV6
321and
322.Li cmsg_type
323is either
324.Dv IPV6_HOPOPTS
325or
326.Dv IPV6_DSTOPTS .
327.Pp
328The
329.Fa tptrp
330argument is a pointer to a pointer to an 8-bit byte and
331.Fa *tptrp
332is used by the function to remember its place in the ancillary data
333object each time the function is called.
334When the
335.Fn inet6_option_next
336function is called for the first time on a given ancillary data object,
337.Fa *tptrp
338must be set to
339.Dv NULL .
340.Pp
341Each time the function returns success,
342the
343.Fa *tptrp
344argument points to the 8-bit option type field for the next option to
345be processed.
346.\"
347.Ss inet6_option_find
348The
349.Fn inet6_option_find
350function allows an application to search for a particular option type
351in an ancillary data object.
352The
353.Fa cmsg
354argument is a pointer to
355.Li cmsghdr
356structure in which the
357.Li cmsg_level
358element equals
359.Dv IPPROTO_IPV6
360and the
361.Li cmsg_type
362element is either
363.Dv IPV6_HOPOPTS
364or
365.Dv IPV6_DSTOPTS .
366.Pp
367The
368.Fa tptrp
369argument is handled exactly as in the
370.Fn inet6_option_next
371function described above.
372.Pa
373The
374.fn inet6_option_find
375function starts searching for an option of the specified type
376beginning after the value of
377.Fa *tptrp .
378.\"
379.Sh DIAGNOSTICS
380The
381.Fn inet6_option_init
382and
383.Fn inet6_option_append
384functions return
385.Li 0
386on success or
387.Li -1
388on an error.
389.Pp
390The
391.Fn inet6_option_alloc
392function returns
393.Dv NULL
394on an error.
395.Pp
396When
397.Fn inet6_option_next
398or
399.Fn inet6_option_find
400detect an error they return
401.Li -1
402setting
403.Fa *tptrp
404to non
405.Dv NULL
406value.
407.\"
408.Sh EXAMPLES
409RFC2292 gives comprehensive examples in chapter 6.
410.\"
411.Sh SEE ALSO
412.Rs
413.%A W. Stevens
414.%A M. Thomas
415.%T "Advanced Sockets API for IPv6"
416.%N RFC2292
417.%D February 1998
418.Re
419.Rs
420.%A S. Deering
421.%A R. Hinden
422.%T "Internet Protocol, Version 6 (IPv6) Specification"
423.%N RFC2460
424.%D December 1998
425.Re
426.\"
427.Sh HISTORY
428The implementation first appeared in KAME advanced networking kit.
429.\"
430.Sh STANDARDS
431The functions are documented in
432.Dq Advanced Sockets API for IPv6
433(RFC2292).
434.\"
diff --git a/src/lib/libc/net/inet6_rthdr_space.3 b/src/lib/libc/net/inet6_rthdr_space.3
new file mode 100644
index 0000000000..77dbd64e3c
--- /dev/null
+++ b/src/lib/libc/net/inet6_rthdr_space.3
@@ -0,0 +1,305 @@
1.\" $OpenBSD: inet6_rthdr_space.3,v 1.15 2005/01/06 03:50:46 itojun Exp $
2.\" $KAME: inet6_rthdr_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $
3.\"
4.\" Copyright (C) 2004 WIDE Project.
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the project nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd December 27, 2004
32.Dt INET6_RTHDR_SPACE 3
33.Os
34.\"
35.Sh NAME
36.Nm inet6_rthdr_space ,
37.Nm inet6_rthdr_init ,
38.Nm inet6_rthdr_add ,
39.Nm inet6_rthdr_lasthop ,
40.Nm inet6_rthdr_reverse ,
41.Nm inet6_rthdr_segments ,
42.Nm inet6_rthdr_getaddr ,
43.Nm inet6_rthdr_getflags
44.Nd IPv6 Routing Header Options Manipulation
45.\"
46.Sh LIBRARY
47.Lb libc
48.Sh SYNOPSIS
49.In sys/types.h
50.In netinet/in.h
51.Ft size_t
52.Fn inet6_rthdr_space "int type" "int segments"
53.Ft "struct cmsghdr *"
54.Fn inet6_rthdr_init "void *bp" "int type"
55.Ft int
56.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags"
57.Ft int
58.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags"
59.Ft int
60.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out"
61.Ft int
62.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg"
63.Ft "struct in6_addr *"
64.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index"
65.Ft int
66.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index"
67.\"
68.Sh DESCRIPTION
69.\"The RFC 2292 IPv6 Advanced API has been deprecated in favor of the
70.\"newer, RFC 3542 APIs.
71.\"On platforms that support it, currently only
72.\"FreeBSD, please use the newer API to manipulate routing header
73.\"options.
74.\".Pp
75The RFC 2292 IPv6 Advanced API defined eight functions for
76applications to use for building and parsing routing headers.
77The
78eight functions are split into two groups, the first of which builds
79the header and the second of which can parse it.
80The function prototypes for these functions are all in the
81.In netinet/in.h
82header.
83Although direct manipulation of a routing header is possible
84this set of APIs make it unnecessary and such direct manipulation
85should be avoided so that changes to the underlying structures do not
86break applications.
87.Pp
88Please note that RFC 2292 uses the term
89.Dq segments
90instead of the term
91.Dq addresses
92but they are considered equivalent for this manual page.
93.\"
94.Ss inet6_rthdr_space
95The
96.Fn inet6_rthdr_space
97function returns the number of bytes required to hold a routing header
98of the specified
99.Fa type
100and containing the specified number of
101.Fa segments .
102Only one
103.Fa type
104is supported,
105.Dv IPV6_RTHDR_TYPE_0 ,
106and it can hold from 1 to 23 segments.
107The return value includes the
108size of the cmsghdr structure that precedes the routing header, and
109any required padding.
110.Pp
111A return value of 0 indicates an error.
112Either the type was specified
113incorrectly, or the number of segments was less than one or greater
114than 23.
115.Pp
116Note: The
117.Fn inet6_rthdr_space
118function only returns the size required by the routing header and does
119not allocate memory for the caller.
120.\"
121.Ss inet6_rthdr_init
122The
123.Fn inet6_rthdr_init
124function initializes a buffer, pointed to by
125.Fa bp
126with an appropriate
127.Li cmsghdr
128structure followed by a routing header of the specified
129.Fa type .
130.Pp
131The caller must use the
132.Fn inet6_rthdr_space
133function to determine the size of the buffer, and then allocate that
134buffer before calling
135.Fn inet6_rthdr_init .
136.Pp
137The return value is a pointer to a
138.Li cmsghdr
139structure, which is used as the first argument to the
140.Fn inet6_rthdr_add
141and
142.Fn inet6_rthdr_lasthop
143functions in order to construct the routing header.
144When an error occurs the return value is
145.Dv NULL .
146.\"
147.Ss inet6_rthdr_add
148The
149.Fn inet6_rthdr_add
150function adds the IPv6 address pointed to by
151.Fa addr
152to the end of the
153routing header being constructed and sets the type of this address to the
154value of
155.Fa flags .
156The
157.Fa flags
158must be either
159.Dv IPV6_RTHDR_LOOSE
160or
161.Dv IPV6_RTHDR_STRICT
162indicating whether loose or strict source routing is required.
163.Pp
164When the function succeeds it returns 0, otherwise \-1 is returned.
165.\"
166.Ss inet6_rthdr_lasthop
167The
168.Fn inet6_rthdr_lasthop
169function specifies the strict or loose flag for the final hop of a
170routing header.
171The
172.Fa flags
173must be either
174.Dv IPV6_RTHDR_LOOSE
175or
176.Dv IPV6_RTHDR_STRICT .
177.Pp
178The return value of the function is 0 upon success, and \-1 when an
179error has occurred.
180.Pp
181Please note that a routing header specifying
182.Li N
183intermediate nodes requires
184.Li N+1
185strict or loose flags meaning that
186.Fn inet6_rthdr_add
187must be called
188.Li N
189times and then
190.Fn inet6_rthdr_lasthop
191must be called once.
192.\"
193.Ss inet6_rthdr_reverse
194This function was never implemented.
195.Pp
196The following four functions provide an API for parsing a received
197routing header.
198.\"
199.Ss inet6_rthdr_segments
200The
201.Fn inet6_rthdr_segments
202function returns the number of segments contained in the Routing
203header pointed to by the
204.Fa cmsg
205argument.
206On success the return value is from 1 to 23.
207When an error occurs \-1 is returned.
208.\"
209.Ss inet6_rthdr_getaddr
210The
211.Fn inet6_rthdr_getaddr
212function returns a pointer to the IPv6 address specified by the
213.Fa index
214argument from the routing header pointed to by
215.Fa cmsg .
216The index must be between 1 and the number returned by
217.Fn inet6_rthdr_segments
218described above.
219An application must call
220.Fn inet6_rthdr_segments
221to obtain the number of segments in the routing header.
222.Pp
223If an error occurs the
224.Dv NULL
225is returned.
226.\"
227.Ss inet6_rthdr_getflags
228The
229.Fn inet6_rthdr_getflags
230function returns the flags value of the segment specified by
231.Fa index
232of the routing header pointed to by
233.Fa cmsg .
234The
235.Fa index
236argument must be between 0 and the value returned by
237.Fn inet6_rthdr_segments .
238The return value will be either
239.Dv IPV6_RTHDR_LOOSE
240or
241.Dv IPV6_RTHDR_STRICT
242indicating whether loose or strict source routing was requested for
243that segment.
244.Pp
245When an error occurs \-1 is returned.
246.Pp
247Note: Flags begin at index 0 while segments begin at index 1, to
248maintain consistency with the terminology and figures in RFC2460.
249.\"
250.Sh DIAGNOSTICS
251The
252.Fn inet6_rthdr_space
253function returns 0 when an error occurs.
254.Pp
255The
256.Fn inet6_rthdr_add ,
257.Fn inet6_rthdr_lasthop
258functions return 0 on success, and \-1 on error.
259.Pp
260The
261.Fn inet6_rthdr_init
262and
263.Fn inet6_rthdr_getaddr
264functions
265return
266.Dv NULL
267on error.
268.Pp
269The
270.Fn inet6_rthdr_segments
271and
272.Fn inet6_rthdr_getflags
273functions return -1 on error.
274.\"
275.Sh EXAMPLES
276RFC2292 gives comprehensive examples in chapter 8.
277.\"
278.Sh SEE ALSO
279.Rs
280.%A W. Stevens
281.%A M. Thomas
282.%T "Advanced Sockets API for IPv6"
283.%N RFC2292
284.%D February 1998
285.Re
286.Rs
287.%A S. Deering
288.%A R. Hinden
289.%T "Internet Protocol, Version 6 (IPv6) Specification"
290.%N RFC2460
291.%D December 1998
292.Re
293.\"
294.Sh HISTORY
295The implementation first appeared in KAME advanced networking kit.
296.\"
297.Sh BUGS
298The
299.Fn inet6_rthdr_reverse
300function was never implemented.
301.\".Pp
302.\"This API is deprecated in favor of
303.\".Xr inet6_rth_space 3
304.\".Sh SEE ALSO
305.\".Xr inet6_rth_space 3