#include <netinet/in.h> int inet6_opt_finish(void *extension_buffer, socklen_t extension_length, int offset)
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.
No authorization is required.
inet6_opt_finish() returns an integer. Possible values are:
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:
|
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);