1 .\" $NetBSD: inet6_opt_init.3,v 1.2 2014/01/04 15:37:26 wiz Exp $
2 .\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $
4 .\" Copyright (C) 2004 WIDE Project.
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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.
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
37 .Nm inet6_opt_append ,
38 .Nm inet6_opt_finish ,
39 .Nm inet6_opt_set_val ,
43 .Nd IPv6 Hop-by-Hop and Destination Options manipulation
48 .Fn inet6_opt_init "void *extbuf" "socklen_t extlen"
50 .Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp"
52 .Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset"
54 .Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen"
56 .Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp"
58 .Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp"
60 .Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen"
63 Building and parsing the Hop-by-Hop and Destination options is
65 The advanced sockets API defines a set of functions to
66 help applications create and manipulate Hop-by-Hope and Destination
68 .\"This man page describes the functions specified in
69 .\"IETF Draft RFC3542 while the
70 .\".Xr inet6_options_space 3
71 .\"man page documents the functions defined in RFC 2292.
73 .\"that this set of functions will supersede those in RFC 2292 but for
74 .\"the time being both APIs are retained.
75 These functions use the
76 formatting rules specified in Appendix B in RFC2460, i.e., that the
77 largest field is placed last in the option.
78 The function prototypes
79 for these functions are all contained in the
87 returns the number of bytes needed for an empty
88 extension header, one without any options.
91 argument points to a valid section of memory
94 function also initializes the extension header's length field.
95 When attempting to initialize an extension buffer passed in the
98 must be a positive multiple of 8 or else the function fails and
99 returns \-1 to the caller.
104 function can perform to different jobs.
107 argument is supplied it appends an option to the extension buffer and
108 returns the updated total length as well as a pointer to the newly
117 .Fn inet6_opt_append function only reports what the total length would
118 be if the option were actually appended.
123 arguments specify the length of the option and the required data
124 alignment which must be used when appending the option.
127 argument should be the length returned by the
129 function or a previous call to
130 .Fn inet6_opt_append .
134 argument is the 8-bit option type.
138 has been called, the application can use the buffer pointed to by
141 .Fn inet6_opt_set_val
142 to specify the data to be contained in the option.
153 All other values from 2 through 255 may be used by applications.
155 The length of the option data is contained in an 8-bit value and so
156 may contain any value from 0 through 255.
160 parameter must have a value of 1, 2, 4, or 8 and cannot exceed the
163 The alignment values represent no alignment, 16 bit, 32 bit and 64 bit
164 alignments respectively.
169 calculates the final padding necessary to make the extension header a
170 multiple of 8 bytes, as required by the IPv6 extension header
171 specification, and returns the extension header's updated total
175 argument should be the length returned by
178 .Fn inet6_opt_append .
183 the function also sets up the appropriate padding bytes by inserting a
184 Pad1 or PadN option of the proper length.
186 If the extension header is too small to contain the proper padding
187 then an error of \-1 is returned to the caller.
189 .Ss inet6_opt_set_val
191 .Fn inet6_opt_set_val
192 function inserts data items of various sizes into the data portion of
196 argument is a pointer to memory that was returned by the
199 .Fa offset argument specifies where the option should be placed in the
203 argument points to an area of memory containing the data to be
204 inserted into the extension header, and the
206 argument indicates how much data to copy.
208 The caller should ensure that each field is aligned on its natural
209 boundaries as described in Appendix B of RFC2460.
211 The function returns the offset for the next field which is calculated as
215 and is used when composing options with multiple fields.
220 function parses received extension headers.
225 arguments specify the location and length of the extension header
229 argument should either be zero, for the first option, or the length value
230 returned by a previous call to
234 The return value specifies the position where to continue scanning the
236 The option is returned in the arguments
243 point to the 8-bit option type, the 8-bit option length and the option
245 This function does not return any PAD1 or PADN options.
246 When an error occurs or there are no more options the return
252 function searches the extension buffer for a particular option type,
253 passed in through the
256 If the option is found then the
260 arguments are updated to point to the option's length and data
265 must point to a valid extension buffer and give its length.
268 argument can be used to search from a location anywhere in the
270 .Ss inet6_opt_get_val
272 .Fn inet6_opt_get_val
273 function extracts data items of various sizes in the data portion of
277 is a pointer returned by the
284 argument points where the data will be extracted.
287 argument specifies from where in the data portion of the option the
288 value should be extracted; the first byte of option data is specified
289 by an offset of zero.
291 It is expected that each field is aligned on its natural boundaries as
292 described in Appendix B of RFC2460.
294 The function returns the offset for the next field
299 which can be used when extracting option content with multiple fields.
300 Robust receivers must verify alignment before calling this function.
303 RFC3542 gives comprehensive examples in Section 23.
305 KAME also provides examples in the
307 directory of its kit.
310 All the functions return
320 .%T "Advanced Sockets API for IPv6"
327 .%T "Internet Protocol, Version 6 (IPv6) Specification"
332 The functions are documented in
333 .Dq Advanced Sockets API for IPv6
337 The implementation first appeared in KAME advanced networking kit.