o to make its size a multiple of 8 bytes
c . The argument is the size of the structure defining the option, which must include any pad bytes at the beginning
o the value .Li y in the alignment term .Dq Li xn + y
c , the type byte, the length byte, and the option data.
p Note: If multiple options are stored in a single ancillary data object, which is the recommended technique, this function overestimates the amount of space required by the size of .Li N-1 .Li cmsghdr structures, where .Li N is the number of options to be stored in the object. This is of little consequence, since it is assumed that most Hop-by-Hop option headers and Destination option headers carry only one option
q appendix B of [RFC 2460] .
.Ss inet6_option_init
.Fn inet6_option_init
is called once per ancillary data object that will
contain either Hop-by-Hop or Destination options.
It returns
.Li 0
on success or
.Li -1
on an error.
p .Fa bp is a pointer to previously allocated space that will contain the ancillary data object. It must be large enough to contain all the individual options to be added by later calls to .Fn inet6_option_append and .Fn inet6_option_alloc .
p .Fa cmsgp is a pointer to a pointer to a .Li cmsghdr structure. .Fa *cmsgp is initialized by this function to point to the .Li cmsghdr structure constructed by this function in the buffer pointed to by .Fa bp .
p
.Fa type
is either
.Dv IPV6_HOPOPTS
or
.Dv IPV6_DSTOPTS .
This
.Fa type
is stored in the
.Li cmsg_type
member of the
.Li cmsghdr
structure pointed to by
.Fa *cmsgp .
.Ss inet6_option_append
This function appends a Hop-by-Hop option or a Destination option
into an ancillary data object that has been initialized by
.Fn inet6_option_init .
This function returns
.Li 0
if it succeeds or
.Li -1
on an error.
p .Fa cmsg is a pointer to the .Li cmsghdr structure that must have been initialized by .Fn inet6_option_init .
p .Fa typep is a pointer to the 8-bit option type. It is assumed that this field is immediately followed by the 8-bit option data length field, which is then followed immediately by the option data. The caller initializes these three fields
q the type-length-value, or TLV before calling this function.
p The option type must have a value from .Li 2 to .Li 255 , inclusive.
o .Li 0 and .Li 1 are reserved for the .Li Pad1 and .Li PadN options, respectively.
c
p The option data length must have a value between .Li 0 and .Li 255 , inclusive, and is the length of the option data that follows.
p .Fa multx is the value .Li x in the alignment term .Dq Li xn + y . It must have a value of .Li 1 , .Li 2 , .Li 4 , or .Li 8 .
p
.Fa plusy
is the value
.Li y
in the alignment term
.Dq Li xn + y .
It must have a value between
.Li 0
and
.Li 7 ,
inclusive.
.Ss inet6_option_alloc
This function appends a Hop-by-Hop option or a Destination option
into an ancillary data object that has been initialized by
.Fn inet6_option_init .
This function returns a pointer to the 8-bit
option type field that starts the option on success, or
.Dv NULL
on an error.
p The difference between this function and .Fn inet6_option_append is that the latter copies the contents of a previously built option into the ancillary data object while the current function returns a pointer to the space in the data object where the option's TLV must then be built by the caller.
p .Fa cmsg is a pointer to the .Li cmsghdr structure that must have been initialized by .Fn inet6_option_init .
p .Fa datalen is the value of the option data length byte for this option. This value is required as an argument to allow the function to determine if padding must be appended at the end of the option.
o The .Fn inet6_option_append function does not need a data length argument since the option data length must already be stored by the caller.
c
p .Fa multx is the value .Li x in the alignment term .Dq Li xn + y . It must have a value of .Li 1 , .Li 2 , .Li 4 , or .Li 8 .
p
.Fa plusy
is the value
.Li y
in the alignment term
.Dq Li xn + y .
It must have a value between
.Li 0
and
.Li 7 ,
inclusive.
.Ss inet6_option_next
This function processes the next Hop-by-Hop option or Destination
option in an ancillary data object.
If another option remains to be
processed, the return value of the function is
.Li 0
and
.Fa *tptrp
points to
the 8-bit option type field
o which is followed by the 8-bit option data length, followed by the option data
c . If no more options remain to be processed, the return value is .Li -1 and .Fa *tptrp is .Dv NULL . If an error occurs, the return value is .Li -1 and .Fa *tptrp is not .Dv NULL .
p .Fa cmsg is a pointer to .Li cmsghdr structure of which .Li cmsg_level equals .Dv IPPROTO_IPV6 and .Li cmsg_type equals either .Dv IPV6_HOPOPTS or .Dv IPV6_DSTOPTS .
p .Fa tptrp is a pointer to a pointer to an 8-bit byte and .Fa *tptrp is used by the function to remember its place in the ancillary data object each time the function is called. The first time this function is called for a given ancillary data object, .Fa *tptrp must be set to .Dv NULL .
p
Each time this function returns success,
.Fa *tptrp
points to the 8-bit
option type field for the next option to be processed.
.Ss inet6_option_find
This function is similar to the previously described
.Fn inet6_option_next
function, except this function lets the caller
specify the option type to be searched for, instead of always
returning the next option in the ancillary data object.
.Fa cmsg
is a
pointer to
.Li cmsghdr
structure of which
.Li cmsg_level
equals
.Dv IPPROTO_IPV6
and
.Li cmsg_type
equals either
.Dv IPV6_HOPOPTS
or
.Dv IPV6_DSTOPTS .
p .Fa tptrp is a pointer to a pointer to an 8-bit byte and .Fa *tptrp is used by the function to remember its place in the ancillary data object each time the function is called. The first time this function is called for a given ancillary data object, .Fa *tptrp must be set to .Dv NULL .
a
This function starts searching for an option of the specified type
beginning after the value of
.Fa *tptrp .
If an option of the specified
type is located, this function returns
.Li 0
and
.Fa *tptrp
points to the 8-
bit option type field for the option of the specified type.
If an
option of the specified type is not located, the return value is
.Li -1
and
.Fa *tptrp
is
.Dv NULL .
If an error occurs, the return value is
.Li -1
and
.Fa *tptrp
is not
.Dv NULL .
.Sh EXAMPLES
RFC 2292 gives comprehensive examples in chapter 6.
.Sh RETURN VALUES
.Fn inet6_option_init
and
.Fn inet6_option_append
return
.Li 0
on success or
.Li -1
on an error.
p .Fn inet6_option_alloc returns .Dv NULL on an error.
p
On errors,
.Fn inet6_option_next
and
.Fn inet6_option_find
return
.Li -1
setting
.Fa *tptrp
to non
.Dv NULL
value.
.Sh SEE ALSO
.Rs
.%A W. Stevens
.%A M. Thomas
.%T "Advanced Sockets API for IPv6"
.%N RFC 2292
.%D February 1998
.Re
.Rs
.%A S. Deering
.%A R. Hinden
.%T "Internet Protocol, Version 6 (IPv6) Specification"
.%N RFC 2460
.%D December 1998
.Re
.Sh STANDARDS
The functions
are documented in
.Dq Advanced Sockets API for IPv6
q RFC 2292 .
.Sh HISTORY
The implementation first appeared in KAME advanced networking kit.
.Sh BUGS
The text was shamelessly copied from RFC 2292.