inet6_opt_finish()--Finish Adding Options to IPv6 Extension Header
Syntax
#include <netinet/in.h> int inet6_opt_finish(void *extension_buffer, socklen_t extension_length, int offset)
Service Program Name: QSOSRV1IP6
Default Public Authority: *USE
Threadsafe: Yes
The inet6_opt_finish() function returns the length of the IPv6 extension header, including padding, to make the extension header 8-byte aligned. If extension_buffer is not NULL, it will add the padding option, Pad1 or PadN of required length, for alignment.
Parameters
- extension_buffer
- (Input/Output) Pointer to the buffer that contains the extension header.
- extension_length
- (Input) Total number of bytes in the buffer pointed to by extension_buffer.
- offset
- (Input) Length of the existing extension header.
The value returned from inet6_opt_init() or a previous call to inet6_opt_append() can be used here.
Authorities
No authorization is required.
Return Value
inet6_opt_finish() returns an integer. Possible values are:
- -1 (unsuccessful)
- n (successful, where n is the updated total number of bytes in the extension header, including padding, to make the extension header 8-byte aligned
Error Conditions
When inet6_opt_finish() fails, errno can be set to one of the following:
[EFAULT] | Bad address.
The system detected an address that was not valid while attempting to access the buffer pointed to by the extension_buffer parameter. |
[EINVAL] | Parameter not valid.
This error code indicates one of the following:
|
Usage Notes
- inet6_opt_finish() is normally called twice when building an options header.
The first call is used to calculate the final total length of the extension header, as shown in this example:
int currentlen, extlen; void *extbuf; void *databufp; currentlen = inet6_opt_init(NULL, 0); currentlen = inet6_opt_append(NULL, 0, currentlen, OPT_X, 12, 8, NULL); currentlen = inet6_opt_finish(NULL, 0, currentlen);
After the total length is calculated and the extension header is built, the required padding is added as follows:extlen = currentlen; extbuf = malloc(extlen); currentlen = inet6_opt_init(extbuf, extlen); currentlen = inet6_opt_append(extbuf, extlen, currentlen, OPT_X, 12, 8, &databufp); currentlen = inet6_opt_finish(extbuf, extlen, currentlen);
Related Information
- inet6_opt_append()--Append New Option to IPv6 Extension Header
- inet6_opt_find()--Extract Option of Specified Type from IPv6 Extension Header
- inet6_opt_get_val()--Retrieve Data Item from an IPv6 Option
- inet6_opt_init()--Get Length of IPv6 Extension Header
- inet6_opt_next()--Extract the Next Option from the IPv6 Extension Header
- inet6_opt_set_val()--Insert Data Items into IPv6 Option
API introduced: V6R1