INET6_RTH_SPACE(3)

NAME
inet6_rth_space inet6_rth_init inet6_rth_add inet6_rth_reverse inet6_rth_segments inet6_rth_getaddr - IPv6 Routing Header Options manipulation

SYNOPSIS
#include <netinet/in.h>
socklen_t
inet6_rth_space(int, int);
void *
inet6_rth_init(void *, socklen_t, int, int);
int
inet6_rth_add(void *, const struct in6_addr *);
int
inet6_rth_reverse(const void *, void *);
int
inet6_rth_segments(const void *);
struct in6_addr *
inet6_rth_getaddr(const void *, int);

DESCRIPTION
The IPv6 advanced API defines six functions that the application calls to build and examine a Routing header, and the ability to use sticky options or ancillary data to communicate this information between the application and the kernel using the IPV6_RTHDR option.

Three functions build a Routing header:

inet6_rth_space()
    returns #bytes required for Routing header

inet6_rth_init()
    initializes buffer data for Routing header

inet6_rth_add()
    adds one IPv6 address to the Routing header

Three functions deal with a returned Routing header:

inet6_rth_reverse()
    reverses a Routing header

inet6_rth_segments()
    returns #segments in a Routing header

inet6_rth_getaddr()
    fetches one address from a Routing header

The function prototypes for these functions are defined as a result of including the <netinet/in.h> header.

  inet6_rth_space
inet6_rth_space() returns the number of bytes required to hold a Routing header of the specified type containing the specified number of segments (addresses.) For an IPv6 Type 0 Routing header, the number of segments must be between 0 and 127, inclusive. The return value is just the space for the Routing header. When the application uses ancillary data it must pass the returned length to CMSG_LEN() to determine how much memory is needed for the ancillary data object ( including the cmsghdr structure.)

If the return value is 0, then either the type of the Routing header is not supported by this implementation or the number of segments is invalid for this type of Routing header.

Note: This function returns the size but does not allocate the space required for the ancillary data. This allows an application to allocate a larger buffer, if other ancillary data objects are desired, since all the ancillary data objects must be specified to sendmsg() as a single msg_control buffer.

  inet6_rth_init
inet6_rth_init() initializes the buffer pointed to by bp to contain a Routing header of the specified type and sets ip6r_len based on the segments parameter. bp_len is only used to verify that the buffer is large enough. The ip6r_segleft field is set to zero; inet6_rth_add() will increment it.

When the application uses ancillary data the application must initialize any cmsghdr fields.

The caller must allocate the buffer and its size can be determined by calling inet6_rth_space().

Upon success the return value is the pointer to the buffer bp, and this is then used as the first argument to the next two functions. Upon an error the return value is NULL.

  inet6_rth_add
inet6_rth_add() adds the IPv6 address pointed to by addr to the end of the Routing header being constructed.

If successful, the segleft member of the Routing Header is updated to account for the new address in the Routing header and the return value of the function is 0. Upon an error the return value of the function is -1.

  inet6_rth_reverse
inet6_rth_reverse() takes a Routing header extension header ( pointed to by the first argument in) and writes a new Routing header that sends datagrams along the reverse of that route. Both arguments are allowed to point to the same buffer ( that is, the reversal can occur in place.)

The return value of the function is 0 on success, or -1 upon an error.

  inet6_rth_segments
inet6_rth_segments() returns the number of segments ( addresses) contained in the Routing header described by bp. On success the return value is zero or greater. The return value of the function is -1 upon an error.

  inet6_rth_getaddr
inet6_rth_getaddr() returns a pointer to the IPv6 address specified by index ( which must have a value between 0 and one less than the value returned by inet6_rth_segments()) in the Routing header described by bp. An application should first call inet6_rth_segments() to obtain the number of segments in the Routing header.

Upon an error the return value of the function is NULL.

DIAGNOSTICS
inet6_rth_space() and return 0 on errors.

inet6_rthdr_init() returns NULL on error. inet6_rth_add() and inet6_rth_reverse() return0 on success, or -1 upon an error.

EXAMPLES
draft-ietf-ipngwg-rfc2292bis-08.txt gives comprehensive examples in Section 22.

KAME also provides examples in the advapitest directory of its kit.

SEE ALSO
W. Stevens, M. Thomas, E. Nordmark, E. Jinmei, Advanced Sockets API for IPv6, draft-ietf-ipngwg-rfc2292bis-08, October 2002. S. Deering, R. Hinden, Internet Protocol, Version 6 (IPv6) Specification, RFC2460, December 1998.

HISTORY
The implementation first appeared in KAME advanced networking kit.

STANDARDS
The functions are documented in “Advanced Sockets API for IPv6” (draft-ietf-ipngwg-rfc2292bis-08.txt).

BUGS
The text was shamelessly copied from internet-drafts for RFC2292bis.