p The .Fa type argument is the 8-bit option type.
p After .Fn inet6_opt_append has been called, the application can use the buffer pointed to by .Fa databufp directly, or use .Fn inet6_opt_set_val to specify the data to be contained in the option.
p Option types of .Li 0 and .Li 1 are reserved for the .Li Pad1 and .Li PadN options. All other values from 2 through 255 may be used by applications.
p The length of the option data is contained in an 8-bit value and so may contain any value from 0 through 255.
p
The
.Fa align
parameter must have a value of 1, 2, 4, or 8 and cannot exceed the
value of
.Fa len .
The alignment values represent no alignment, 16 bit, 32 bit and 64 bit
alignments respectively.
.Ss inet6_opt_finish
The
.Fn inet6_opt_finish
calculates the final padding necessary to make the extension header a
multiple of 8 bytes, as required by the IPv6 extension header
specification, and returns the extension header's updated total
length.
The
.Fa offset
argument should be the length returned by
.Fn inet6_opt_init
or
.Fn inet6_opt_append .
When
.Fa extbuf
is not
.Dv NULL
the function also sets up the appropriate padding bytes by inserting a
Pad1 or PadN option of the proper length.
p
If the extension header is too small to contain the proper padding
then an error of -1 is returned to the caller.
.Ss inet6_opt_set_val
The
.Fn inet6_opt_set_val
function inserts data items of various sizes into the data portion of
the option.
The
.Fa databuf
argument is a pointer to memory that was returned by the
.Fn inet6_opt_append
call and the
.Fa offset argument specifies where the option should be placed in the
data buffer.
The
.Fa val
argument points to an area of memory containing the data to be
inserted into the extension header, and the
.Fa vallen
argument indicates how much data to copy.
p The caller should ensure that each field is aligned on its natural boundaries as described in Appendix B of RFC2460.
p
The function returns the offset for the next field which is calculated as
.Fa offset
+
.Fa vallen
and is used when composing options with multiple fields.
.Ss inet6_opt_next
The
.Fn inet6_opt_next
function parses received extension headers.
The
.Fa extbuf
and
.Fa extlen
arguments specify the location and length of the extension header
being parsed.
The
.Fa offset
argument should either be zero, for the first option, or the length value
returned by a previous call to
.Fn inet6_opt_next
or
.Fn inet6_opt_find .
The return value specifies the position where to continue scanning the
extension buffer.
The option is returned in the arguments
.Fa typep , lenp ,
and
.Fa databufp .
.Fa typep , lenp ,
and
.Fa databufp
point to the 8-bit option type, the 8-bit option length and the option
data respectively.
This function does not return any PAD1 or PADN options.
When an error occurs or there are no more options the return
value is -1.
.Ss inet6_opt_find
The
.Fn inet6_opt_find
function searches the extension buffer for a particular option type,
passed in through the
.Fa type
argument.
If the option is found then the
.Fa lenp
and
.Fa databufp
arguments are updated to point to the option's length and data
respectively.
.Fa extbuf
and
.Fa extlen
must point to a valid extension buffer and give its length.
The
.Fa offset
argument can be used to search from a location anywhere in the
extension header.
.Ss inet6_opt_get_val
The
.Fn inet6_opt_get_val
function extracts data items of various sizes in the data portion of
the option.
The
.Fa databuf
is a pointer returned by the
.Fn inet6_opt_next
or
.Fn inet6_opt_find
functions.
The
.Fa val
argument points where the data will be extracted.
The
.Fa offset
argument specifies from where in the data portion of the option the
value should be extracted; the first byte of option data is specified
by an offset of zero.
p It is expected that each field is aligned on its natural boundaries as described in Appendix B of RFC2460.
p
The function returns the offset for the next field
by calculating
.Fa offset
+
.Fa vallen
which can be used when extracting option content with multiple fields.
Robust receivers must verify alignment before calling this function.
.Sh EXAMPLES
RFC3542 gives comprehensive examples in Section 23.
p KAME also provides examples in the
a advapitest
directory of its kit.
.Sh RETURN VALUES
All the functions return
-1
on an error.
.Sh SEE ALSO
.Rs
.%A W. Stevens
.%A M. Thomas
.%A E. Nordmark
.%A T. Jinmei
.%T "Advanced Sockets API for IPv6"
.%N RFC3542
.%D October 2002
.Re
.Rs
.%A S. Deering
.%A R. Hinden
.%T "Internet Protocol, Version 6 (IPv6) Specification"
.%N RFC2460
.%D December 1998
.Re
.Sh STANDARDS
The functions are documented in
.Dq Advanced Sockets API for IPv6
q RFC3542 .
.Sh HISTORY
The implementation first appeared in KAME advanced networking kit.