[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here >

Compaq TCP/IP Services for OpenVMS
Release Notes


Previous Contents

D.3 Socket Calls to Build and Examine IPv6 Options Headers

The socket calls that are used to build and examine IPv6 option headers are:

  • inet6_opt_append
  • inet6_opt_find
  • inet6_opt_finish
  • inet6_opt_get_val
  • inet6_opt_init
  • inet6_opt_next
  • inet6_opt_set_val

D.3.1 The inet6_opt_append Socket Call

Returns the length of an IPv6 extension header with a new option and appends the option.


#include <netinet/ip6.h> 
 
int inet6_opt_apppend(void *extbuf, size_t extlen, int prevlen, 
           uint8_t type, size_t len, uint_t align, void **databufp ); 

D.3.1.1 Parameters

  • extbuf
    Points to a buffer that contains an extension header. This is either a valid pointer or a NULL pointer.
  • extlen
    Specifies the length of the extension header to initialize. Valid values are 0 if _extbuf equals 0, a value returned by inet6_opt_finish() , or any number that is a multiple of 8.
  • prevlen
    Specifies the length of the existing extension header. Obtain this value from a prior call to inet6_opt_init() or inet6_opt_append() .
  • type
    Specifies the type of option. Specify a value from 2 to 255, inclusive, excluding 194.
  • len
    Specifies the length of the option data, excluding the option type and option length fields. Specify a value from 0 to 255, inclusive.
  • align
    Specifies the alignment of the option. Specify one of the following values: 1, 2, 4, or 8.
  • databufp
    Points to a buffer that contains the option data.

D.3.1.2 Description

The inet6_opt_append() function, when called with extbuf as a NULL pointer and extlen as 0, returns the updated number of bytes in an extension header.

If you specify extbuf as a valid pointer and valid extlen and align parameters, the function returns the same information as in the previous case, but also inserts the pad option, initializes the type and length fields, and returns a pointer to the location for the option content.

After you call inet6_opt_append() , you can then use the data buffer directly or call inet6_optt_set_val() to specify the option contents.

D.3.1.3 Return Values

Upon successful completion, the inet6_opt_append() function returns the updated number of bytes in an extension header.

Upon failure, it returns a -1.

D.3.2 The inet6_opt_find Call

Finds a specific option in an extension header.


#include <netinet/ip6.h> 
 
int inet6_opt_find( 
        void *extbuf, size_t extlen, int prevlen, uint8_t type, 
        size_t *lenp, void **databufp ); 

D.3.2.1 Parameters

  • extbuf
    Points to a buffer that contains an extension header.
  • extlen
    Specifies the length, in bytes, of the extension header.
  • prevlen
    Specifies the location in the extension header of an option. Valid values are either 0 (zero) for the first option or the length returned from a previous call to either inet6_opt_next() or inet6_opt_find() .
  • type
    Specifies the type of option to find.
  • lenp
    Points to the length of the option found.
  • databufp
    Points to the option data.

D.3.2.2 Description

The inet6_opt_find() function searches a received option extension header for an option specified by type. If it finds the specified option, it returns the option length and a pointer to the option data. In addition, it returns an offset to the next option that you specify in the prevlen parameter to subsequent calls to inet6_opt_next() in order to search for additional occurrences of the same option type.

D.3.2.3 Return Values

Upon successful completion, the inet6_opt_find() function returns an offset from which you can begin the next search in the data buffer.

Upon failure, it returns a -1.

D.3.3 The inet6_opt_finish Call

Returns the total length of an IPv6 extension header, including padding, and initializes the option.


#include <netinet/ip6.h> 
 
int inet6_opt_finish( 
        void *extbuf, size_t extlen, int prevlen ); 

D.3.3.1 Parameters

  • extbuf
    Points to a buffer that contains an extension header. This is either a valid pointer or a NULL pointer.
  • extlen
    Specifies the length of the extension header to finish initializing. A valid value is any number greater than or equal to 0.
  • prevlen
    Specifies the length of the existing extension header. Obtain this value from a prior call to inet6_opt_init() or inet6_opt_append() .

D.3.3.2 Description

The inet6_opt_finish() function when called with extbuf as a NULL pointer and extlen as 0, returns the total number of bytes in an extension header, including final padding.

If you specify extbuf as a valid pointer and a valid extlen parameter, the function returns the same information as in the previous case, increments the buffer pointer, and verifies that the buffer is large enough to hold the header.

D.3.3.3 Return Values

Upon successful completion, the inet6_opt_finish() function returns the total number of bytes in an extension header, including padding.

Upon failure, it returns a -1.

D.3.4 The inet6_opt_get_val Call

Extracts data items from the data portion of an IPv6 option.


#include <netinet/ip6.h> 
 
int inet6_opt_get_val( 
        void *databuf, size_t offset, void *val, int vallen ); 

D.3.4.1 Parameters

  • databuf
    Points to a buffer that contains an extension header. This is a pointer returned by a call to inet6_opt_find() or inet6_opt_next() .
  • offset
    Specifies the location in the data portion of the option from which to extract the data. You can access the first byte after the option type and length by specifying the offset of 0.
  • val
    Points to a destination for the extracted data.
  • vallen
    Specifies the length of the data, in bytes, to be extracted.

D.3.4.2 Description

The inet6_opt_get_val() function copies data items from data buffer databuf beginning at offset to the location val . In addition, it returns the offset for the next data field to assist you in extracting option content that has multiple fields.

Make sure that each field is aligned on its natural boundaries.

D.3.4.3 Return Values

Upon successful completion, the inet6_opt_get_val() unction returns the offset for the next field in the data buffer.

Upon failure, it returns a -1.

D.3.5 The inet6_opt_init Call

Returns the length of an IPv6 extension header with no options and initializes the header.


#include <netinet/ip6.h> 
 
int inet6_opt_innit( void *extbuf, size_t extlen ); 

D.3.5.1 Parameters

  • extbuf
    Points to a buffer that contains an extension header. This is either a valid pointer or a NULL pointer.
  • extlen >D.4 Socket Calls to Build and Examine IPv6 Routing Headers

    The socket call used to build and examine IPv6 routing headers are:

    • inet6_rth_add
    • inet6_rth_getaddr
    • inet6_rth_init
    • inet6_rth_reverse
    • inet6_rth_segments
    • inet6_rth_space

    D.4.1 The inet6_rth_add Call

    Adds an IPv6 address to the routing header under construction.


    #include <netinet/ip6.h> 
     
    int inet6_rth_add( void *bp, const struct in6_addr *addr ); 
    

    D.4.1.1 Parameters

    • bp
      Points to a buffer that is to contain an IPv6 routing header.
    • addr
      Points to an IPv6 address to add to the routing header.

    D.4.1.2 Description

    The inet6_rth_add() function adds IPv6 address to the end of the routing header under construction. The address pointed to by addr cannot be either an IPv6 V4-mapped address or an IPv6 multicast address.

    The function increments the ip60r_segleft member in the ip6_rthdr0 structure . The ip6_rthdr0 structure is defined in netinet/ip6.h .

    Only routing header type 0 is supported.

    D.4.1.3 Return Values

    Upon successful completion, the inet6_rth_add() function returns 0 (zero).

    Upon failure, it returns a -1.

    D.4.2 The inet6_rth_getaddr Call

    Retrieves an address for an index from an IPv6 routing header.


    #include <netinet/ip6.h> 
     
    struct in6_addr *inet6_rth_getaddr( const void *bp,int index ); 
    

    D.4.2.1 Parameters

    • bp
      Points to a buffer that contains an IPv6 routing header.
    • index
      Specifies a value that identifies a position in a routing header for a specific address. Valid values range from 0 to the return value from inet6_rth_segments() minus 1.

    D.4.2.2 Description

    The inet6_rth_getaddr() function uses a specified index value and retrieves a pointer to an address in a Routing header specified by bp . Call inet6_rth_segments() before calling this function in order to determine the number of segments (addresses) in the routing header.

    D.4.2.3 Return Values

    Upon successful completion, the inet6_rth_getaddr() function returns a pointer to an address.

    Upon failure, it returns a NULL pointer.

    D.4.3 The inet6_rth_init Call

    Initializes an IPv6 routing header buffer.


    #include <netinet/ip6.h> 
     
    void inet6_rth_init( void *bp, int bp_len, int type, int segments ); 
    

    D.4.3.1 Parameters

    • bp
      Points to a buffer that is to contain an IPv6 routing header.
    • bp_len
      Specifies the length, in bytes, of the buffer.
    • type
      Specifies the type of routing header. The valid value is IPV6_RTHDR_TYPE_0 for IPv6 routing header type 0.
    • segments
      Specifies the number of segments or addresses that are to be included in the routing header. The valid value is from 0 to 127, inclusive.

    D.4.3.2 Description

    The inet6_rth_init() function initializes a buffer and buffer data for an IPv6 routing header. The function sets the ip60r_segleft , ip6r0_nxt , and ip6r0_reserved members in the ip6_rthdr0 structure to zero. In addition, it sets the ip6r0_type member to type and sets the ip6r0_len member based in the segments parameter. (See RFC 2460 for a description of the actual value.) The ip6_rthdr0 structure is defined in netinet/ip6.h .

    The application must allocate the buffer. Use the inet6_rth_space() function to determine the buffer size.

    Use the returned pointer as the first argument to the inet6_rth_add() function.

    D.4.3.3 Return Values

    Upon successful completion, the inet6_rth_init() function returns a pointer to the buffer that is to contain the routing header.

    If the type is not supported, the bp is a null, or the number of bp_len is invalid, the function returns a NULL pointer.

    D.4.4 The inet6_rth_reverse Call

    Reverses the order of addresses in an IPv6 routing header.


    #include <netinet/ip6.h> 
     
    int inet6_rth_reverse( const void *in, void *out ); 
    

    D.4.4.1 Parameters

    • in
      Points to a buffer that contains an IPv6 routing header.
    • out
      Points to a buffer that is to contain the routing header with the reversed addresses. This parameter can point to the same buffer specified by the in parameter.

    D.4.4.2 Description

    The inet6_rth_reverse() function reads an IPv6 routing header and writes a new routing header, reversing the order of addresses in the new header. The in and out parameters can point to the same buffer.

    The function sets the ip60r_segleft member in the ip6_rthdr0 structure to the number of segments (addresses) in the new header.

    The ip6_rthdr0 structure is defined in netinet/ip6.h .

    D.4.4.3 Return Values

    Upon successful completion, the inet6_rth_reverse() function returns 0.

    Upon failure, it returns a -1.

    D.4.5 The inet6_rth_segments Call

    Returns the number of segments (addresses) in an IPv6 routing header.


    #include <netinet/ip6.h> 
     
    int inet6_rth_segments( const void *bp ); 
    

    Parameters

    • bp
      Points to a buffer that contains an IPv6 routing header.

    D.4.5.1 Description

    The inet6_rth_segments() function returns the number of segments (or addresses) in an IPv6 routing header.

    D.4.5.2 Return Values

    Upon successful completion, the inet6_rth_segments() function returns the number of segments, 0 (zero) or greater than 0.

    Upon failure, it returns a -1.

    D.4.6 The inet6_rth_space Call

    Returns the number of bytes required for an IPv6 routing header.


    #include <netinet/ip6.h> 
     
    size_t inet6_rth_space( int type, int segments ); 
    

    D.4.6.1 Parameters

    • type
      Specifies the type of routing header. The valid value is IPV6_RTHDR_TYPE_0 for IPv6 routing header type 0.
    • segments
      Specifies the number of segments or addresses that are to be included in the routing header. The valid value is from 0 to 127, inclusive.

    D.4.6.2 Description

    The inet6_rth_space() function determines the amount of space, in bytes, required for a routing header. Although the function returns the amount of space required, it does not allocate buffer space. This enables the application to allocate a larger buffer.

    If the application uses ancillary data, it must pass the returned length to CMSG_LEN() to determine the amount of memory required for the ancillary data object, including the cmsghdr structure.

    Note

    If an appli