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.In netinet/in.h 90header. 91.\" 92.Ss inet6_rth_space 93The 94.Fn inet6_rth_space 95function 96returns the number of bytes required to hold a Routing 97header of the specified type containing the specified number of 98segments (addresses). 99For an IPv6 Type 0 Routing header, the number 100of 101segments 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(including the 109.Vt cmsghdr 110structure). 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.Xr sendmsg 2 122as a single msg_control buffer. 123.Ss inet6_rth_init 124The 125.Fn inet6_rth_init 126function 127initializes the buffer pointed to by 128.Fa bp 129to contain a 130Routing header of the specified type and sets 131.Va ip6r_len 132based on the 133.Fa segments 134parameter. 135The 136.Fa bp_len 137argument 138is only used to verify that the buffer is 139large enough. 140The 141.Va ip6r_segleft 142field is set to zero; 143.Fn inet6_rth_add 144will increment it. 145.Pp 146When the application uses ancillary data the application must 147initialize any 148.Vt cmsghdr 149fields. 150.Pp 151The caller must allocate the buffer and its size can be determined by 152calling 153.Fn inet6_rth_space . 154.Pp 155Upon success the return value is the pointer to the buffer 156.Fa bp , 157and this is then used as the first argument to the next two functions. 158Upon an error the return value is 159.Dv NULL . 160.\" 161.Ss inet6_rth_add 162The 163.Fn inet6_rth_add 164function 165adds the IPv6 address pointed to by 166.Fa addr 167to the end of the Routing header being constructed. 168.Pp 169If successful, the 170.Va segleft 171member of the Routing Header is updated to 172account for the new address in the Routing header and the return 173value of the function is 0. 174Upon an error the return value of the function is \-1. 175.\" 176.Ss inet6_rth_reverse 177The 178.Fn inet6_rth_reverse 179function 180takes a Routing header extension header 181(pointed to by the first argument 182.Fa in ) 183and writes a new Routing header that sends 184datagrams along the reverse of that route. 185Both arguments are allowed to point to the same buffer 186(that is, the reversal can occur in place). 187.Pp 188The return value of the function is 0 on success, or \-1 upon an error. 189.\" 190.Ss inet6_rth_segments 191The 192.Fn inet6_rth_segments 193function 194returns the number of segments 195(addresses) 196contained in the Routing header described by 197.Fa bp . 198On success the return value is 199zero or greater. 200The return value of the function is \-1 upon an error. 201.\" 202.Ss inet6_rth_getaddr 203The 204.Fn inet6_rth_getaddr 205function 206returns a pointer to the IPv6 address specified by 207.Fa index 208(which must have a value between 0 and one less than the value 209returned by 210.Fn inet6_rth_segments ) 211in the Routing header described by 212.Fa bp . 213An application should first call 214.Fn inet6_rth_segments 215to obtain the number of segments in the Routing header. 216.Pp 217Upon an error the return value of the function is 218.Dv NULL . 219.\" 220.Sh DIAGNOSTICS 221The 222.Fn inet6_rth_space 223and 224.Fn inet6_rth_getaddr 225functions 226return 0 on errors. 227.Pp 228The 229.Fn inet6_rthdr_init 230function 231returns 232.Dv NULL 233on error. 234The 235.Fn inet6_rth_add 236and 237.Fn inet6_rth_reverse 238functions 239return 0 on success, or \-1 upon an error. 240.\" 241.Sh EXAMPLES 242draft-ietf-ipngwg-rfc2292bis-08.txt 243gives comprehensive examples in Section 22. 244.Pp 245KAME also provides examples in the advapitest directory of its kit. 246.\" 247.Sh SEE ALSO 248.Rs 249.%A W. Stevens 250.%A M. Thomas 251.%A E. Nordmark 252.%A E. Jinmei 253.%T "Advanced Sockets API for IPv6" 254.%N draft-ietf-ipngwg-rfc2292bis-08 255.%D October 2002 256.Re 257.Rs 258.%A S. Deering 259.%A R. Hinden 260.%T "Internet Protocol, Version 6 (IPv6) Specification" 261.%N RFC2460 262.%D December 1998 263.Re 264.Sh HISTORY 265The implementation first appeared in KAME advanced networking kit. 266.Sh STANDARDS 267The functions 268are documented in 269.Dq Advanced Sockets API for IPv6 270.Pq draft-ietf-ipngwg-rfc2292bis-08.txt . 271.\" 272.Sh BUGS 273The text was shamelessly copied from internet-drafts for RFC2292bis. 274