#include <netinet/in.h> int inet6_opt_append(void *extension_buffer, socklen_t extension_length, int offset, uint8_t option_type, socklen_t option_length, uint32_t alignment, void **data_bufferp)
The inet6_opt_append() function returns the updated total length of the extension header after adding the new option and alignment. If extension_buffer is not NULL, padding will be inserted to align the option, initialize the option by setting the type and length fields, and return a pointer to the location for the option content in data_bufferp.
No authorization is required.
inet6_opt_append() returns an integer. Possible values are:
When inet6_opt_append() 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 or data_bufferp parameter. |
[EINVAL] | Parameter not valid.
This error code indicates one of the following:
|
The first call is used to update the total length of the extension header based on an option to be appended, 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);After the total length is calculated by calling inet6_opt_append(), as shown in the preceding example, for each option to be added, and by calling inet6_opt_finish() to calculate the final extension length to be used when actually building the extension header, the desired option(s) are appended to the initialized header 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);After inet6_opt_append() has been called, the application can use databufp directly or use inet6_opt_set_val() to specify the content of the option.