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:


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:

  • The extension_length field contains a value that is not positive.
  • The offset field contains a value that is not positive.
  • The necessary padding will not fit in the extension header.


Usage Notes

  1. 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




API introduced: V6R1

[ Back to top | UNIX-Type APIs | APIs by category ]