1.\" $KAME: kame/kame/kame/libinet6/inet6_rth_space.3,v 1.4 2002/10/17 14:13:48 jinmei Exp $ 2.\" 3.\" Copyright (C) 2000 WIDE Project. 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the project nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" $FreeBSD$ 31.\" 32.Dd February 5, 2000 33.Dt INET6_RTH_SPACE 3 34.Os 35.\" 36.Sh NAME 37.Nm inet6_rth_space 38.Nm inet6_rth_init 39.Nm inet6_rth_add 40.Nm inet6_rth_reverse 41.Nm inet6_rth_segments 42.Nm inet6_rth_getaddr 43.Nd IPv6 Routing Header Options manipulation 44.\" 45.Sh SYNOPSIS 46.In netinet/in.h 47.Ft socklen_t 48.Fn inet6_rth_space "int" "int" 49.Ft "void *" 50.Fn inet6_rth_init "void *" "socklen_t" "int" "int" 51.Ft int 52.Fn inet6_rth_add "void *" "const struct in6_addr *" 53.Ft int 54.Fn inet6_rth_reverse "const void *" "void *" 55.Ft int 56.Fn inet6_rth_segments "const void *" 57.Ft "struct in6_addr *" 58.Fn inet6_rth_getaddr "const void *" "int" 59.\" 60.Sh DESCRIPTION 61The IPv6 advanced API defines six 62functions that the application calls to build and examine a Routing 63header, and the ability to use sticky options or ancillary data to 64communicate this information between the application and the kernel 65using the IPV6_RTHDR option. 66.Pp 67Three functions build a Routing header: 68.Bl -hang 69.It Fn inet6_rth_space 70returns #bytes required for Routing header 71.It Fn inet6_rth_init 72initializes buffer data for Routing header 73.It Fn inet6_rth_add 74adds one IPv6 address to the Routing header 75.El 76.Pp 77Three functions deal with a returned Routing header: 78.Bl -hang 79.It Fn inet6_rth_reverse 80reverses a Routing header 81.It Fn inet6_rth_segments 82returns #segments in a Routing header 83.It Fn inet6_rth_getaddr 84fetches one address from a Routing header 85.El 86.Pp 87The function prototypes for these functions are defined as a result 88of including the 89.Aq Li netinet/in.h 90header. 91.\" 92.Ss inet6_rth_space 93.Fn inet6_rth_space 94returns the number of bytes required to hold a Routing 95header of the specified type containing the specified number of 96.Li segments 97.Po addresses. 98.Pc 99For an IPv6 Type 0 Routing header, the number 100of 101.Li segments 102must be between 0 and 127, inclusive. 103The return value is just the space for the Routing header. 104When the application uses 105ancillary data it must pass the returned length to 106.Fn CMSG_LEN 107to determine how much memory is needed for the ancillary data object 108.Po 109including the cmsghdr structure. 110.Pc 111.Pp 112If the return value is 0, then either the type of the Routing header 113is not supported by this implementation or the number of segments is 114invalid for this type of Routing header. 115.Pp 116Note: This function returns the size but does not allocate the space 117required for the ancillary data. 118This allows an application to 119allocate a larger buffer, if other ancillary data objects are 120desired, since all the ancillary data objects must be specified to 121.Fn sendmsg 122as a single msg_control buffer. 123.Ss inet6_rth_init 124.Fn inet6_rth_init 125initializes the buffer pointed to by 126.Li bp 127to contain a 128Routing header of the specified type and sets ip6r_len based on the 129.Li segments 130parameter. 131.Li bp_len 132is only used to verify that the buffer is 133large enough. 134The ip6r_segleft field is set to zero; 135.Fn inet6_rth_add 136will increment it. 137.Pp 138When the application uses ancillary data the application must 139initialize any cmsghdr fields. 140.Pp 141The caller must allocate the buffer and its size can be determined by 142calling 143.Fn inet6_rth_space . 144.Pp 145Upon success the return value is the pointer to the buffer 146.Li bp , 147and this is then used as the first argument to the next two functions. 148Upon an error the return value is NULL. 149.\" 150.Ss inet6_rth_add 151.Fn inet6_rth_add 152adds the IPv6 address pointed to by 153.Li addr 154to the end of the Routing header being constructed. 155.Pp 156If successful, the segleft member of the Routing Header is updated to 157account for the new address in the Routing header and the return 158value of the function is 0. 159Upon an error the return value of the function is -1. 160.\" 161.Ss inet6_rth_reverse 162.Fn inet6_rth_reverse 163takes a Routing header extension header 164.Po 165pointed to by the first argument 166.Li in 167.Pc 168and writes a new Routing header that sends 169datagrams along the reverse of that route. 170Both arguments are allowed to point to the same buffer 171.Po 172that is, the reversal can occur in place. 173.Pc 174.Pp 175The return value of the function is 0 on success, or -1 upon an error. 176.\" 177.Ss inet6_rth_segments 178.Fn inet6_rth_segments 179returns the number of segments 180.Po 181addresses 182.Pc 183contained in the Routing header described by 184.Li bp . 185On success the return value is 186zero or greater. 187The return value of the function is -1 upon an error. 188.\" 189.Ss inet6_rth_getaddr 190.Fn inet6_rth_getaddr 191returns a pointer to the IPv6 address specified by 192.Li index 193.Po 194which must have a value between 0 and one less than the value 195returned by 196.Fn inet6_rth_segments 197.Pc 198in the Routing header described by 199.Li bp . 200An application should first call 201.Fn inet6_rth_segments 202to obtain the number of segments in the Routing header. 203.Pp 204Upon an error the return value of the function is NULL. 205.\" 206.Sh DIAGNOSTICS 207.Fn inet6_rth_space 208and 209.FN inet6_rth_getaddr 210return 0 on errors. 211.Pp 212.Fn inet6_rthdr_init 213returns 214.Dv NULL 215on error. 216.Fn inet6_rth_add 217and 218.Fn inet6_rth_reverse 219return0 on success, or -1 upon an error. 220.\" 221.Sh EXAMPLES 222draft-ietf-ipngwg-rfc2292bis-08.txt 223gives comprehensive examples in Section 22. 224.Pp 225KAME also provides examples in the advapitest directry of its kit. 226.\" 227.Sh SEE ALSO 228.Rs 229.%A W. Stevens 230.%A M. Thomas 231.%A E. Nordmark 232.%A E. Jinmei 233.%T "Advanced Sockets API for IPv6" 234.%N draft-ietf-ipngwg-rfc2292bis-08 235.%D October 2002 236.Re 237.Rs 238.%A S. Deering 239.%A R. Hinden 240.%T "Internet Protocol, Version 6 (IPv6) Specification" 241.%N RFC2460 242.%D December 1998 243.Re 244.Sh HISTORY 245The implementation first appeared in KAME advanced networking kit. 246.Sh STANDARDS 247The functions 248are documented in 249.Dq Advanced Sockets API for IPv6 250.Pq draft-ietf-ipngwg-rfc2292bis-08.txt . 251.\" 252.Sh BUGS 253The text was shamelessly copied from internet-drafts for RFC2292bis. 254