📄 in6.h
字号:
/* in6.c - in6 header file *//* * Copyright (c) 2001-2005 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. *//* $KAME: in6.h,v 1.159 2005/03/19 07:28:59 suz Exp $ *//* $KAME: in6.h,v 1.155 2004/06/02 05:53:14 itojun Exp $ *//* $FreeBSD: src/sys/netinet6/in6.h,v 1.7.2.7 2002/08/01 19:38:50 ume Exp $ *//* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ *//* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* * Copyright (c) 1982, 1986, 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)in.h 8.3 (Berkeley) 1/3/94 *//*modification history--------------------01u,06aug05,dlk Added in6_pseudo() declaration.01t,04jun05,dlk Make inet6_opt* functions from RFCs 2292 and 3542 visible in user space.01s,31may05,tlu Added IN6_IS_ADDR_GLOBAL 01r,09may05,kch Merged from Kame v 1.159.01q,19apr05,rp merged from comp_wn_ipv6_mld_interim-dev01p,23feb05,dlk Make functions from rthdr.c visible in user space.01o,07feb05,vvv _KERNEL cleanup01n,24jan05,vvv osdep.h cleanup01m,20jan05,sar Removal of divert, dummynet and fw code.01l,23aug04,rp merged from COMP_WN_IPV6_BASE6_ITER5_TO_UNIFIED_PRE_MERGE01k,28may04,niq Merging from base6 label POST_ITER5_FRZ16_REBASE (ver /main/vdt/base6_itn5_networking-int/1)01j,20nov03,niq Remove copyright_wrs.h file inclusion01i,04nov03,rlm Ran batch header path update for header re-org.01h,03nov03,rlm Removed wrn/coreip/ prefix from #includes for header re-org.01g,27oct03,rlm update include statements post header re-org.01f,11aug03,nee Merging from label ACCORDION_BASE6_MERGE_BASELINE in accordion codeline to Base601e,09may03,vvv fixed check for in.h01d,30apr03,syy Added #ifdef for __cplusplus01c,01feb03,pas merge from FreeBSD 4.7 - added faithprefix_p01b,30sep02,sar IFDEF out the KAME IPsec mflags01a,03feb02,ham changes for tornado.*/#ifndef _NETINET_IN_H_#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"#endif#ifndef _NETINET6_IN6_H_#define _NETINET6_IN6_H_#ifdef __cplusplusextern "C" {#endif/* * Identification of the network protocol stack * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE * has the table of implementation/integration differences. */#define __KAME__#define __KAME_VERSION "SNAP 20050404"/* * Local port number conventions: * * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), * unless a kernel is compiled with IPNOPRIVPORTS defined. * * When a user does a bind(2) or connect(2) with a port number of zero, * a non-conflicting local port address is chosen. * * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although * that is settable by sysctl(3); net.inet.ip.anonportmin and * net.inet.ip.anonportmax respectively. * * A user may set the IPPROTO_IP option IP_PORTRANGE to change this * default assignment range. * * The value IP_PORTRANGE_DEFAULT causes the default behavior. * * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, * and exists only for FreeBSD compatibility purposes. * * The value IP_PORTRANGE_LOW changes the range to the "low" are * that is (by convention) restricted to privileged processes. * This convention is based on "vouchsafe" principles only. * It is only secure if you trust the remote host to restrict these ports. * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. */#define IPV6PORT_RESERVED 1024#define IPV6PORT_ANONMIN 49152#define IPV6PORT_ANONMAX 65535#define IPV6PORT_RESERVEDMIN 600#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)/* * IPv6 address */struct in6_addr { union { u_int8_t __u6_addr8[16]; u_int16_t __u6_addr16[8]; u_int32_t __u6_addr32[4]; } __u6_addr; /* 128-bit IP6 address */};#define s6_addr __u6_addr.__u6_addr8#ifdef _WRS_KERNEL /* XXX nonstandard */#define s6_addr8 __u6_addr.__u6_addr8#define s6_addr16 __u6_addr.__u6_addr16#define s6_addr32 __u6_addr.__u6_addr32#endif#define INET6_ADDRSTRLEN 46/* * Socket address for IPv6 */#ifndef _XOPEN_SOURCE#define SIN6_LEN#endifstruct sockaddr_in6 { u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ u_int8_t sin6_family; /* AF_INET6 (sa_family_t) */ u_int16_t sin6_port; /* Transport layer port # (in_port_t)*/ u_int32_t sin6_flowinfo; /* IP6 flow information */ struct in6_addr sin6_addr; /* IP6 address */ u_int32_t sin6_scope_id; /* scope zone index */};/* * Local definition for masks */#ifdef _WRS_KERNEL /* XXX nonstandard */#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}extern const struct sockaddr_in6 sa6_any;extern const struct in6_addr in6mask0;extern const struct in6_addr in6mask32;extern const struct in6_addr in6mask64;extern const struct in6_addr in6mask96;extern const struct in6_addr in6mask128;/* * Macros started with IPV6_ADDR is KAME local */#if _BYTE_ORDER == _BIG_ENDIAN#define IPV6_ADDR_INT32_ONE 1#define IPV6_ADDR_INT32_TWO 2#define IPV6_ADDR_INT32_MNL 0xff010000#define IPV6_ADDR_INT32_MLL 0xff020000#define IPV6_ADDR_INT32_SMP 0x0000ffff#define IPV6_ADDR_INT16_ULL 0xfe80#define IPV6_ADDR_INT16_USL 0xfec0#define IPV6_ADDR_INT16_MLL 0xff02#elif _BYTE_ORDER == _LITTLE_ENDIAN#define IPV6_ADDR_INT32_ONE 0x01000000#define IPV6_ADDR_INT32_TWO 0x02000000#define IPV6_ADDR_INT32_MNL 0x000001ff#define IPV6_ADDR_INT32_MLL 0x000002ff#define IPV6_ADDR_INT32_SMP 0xffff0000#define IPV6_ADDR_INT16_ULL 0x80fe#define IPV6_ADDR_INT16_USL 0xc0fe#define IPV6_ADDR_INT16_MLL 0x02ff#endif#endif /* _WRS_KERNEL *//* * Definition of some useful macros to handle IP6 addresses */#define IN6ADDR_ANY_INIT \ {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}#define IN6ADDR_LOOPBACK_INIT \ {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}#ifdef MLDV2#define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \ {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}#endifextern const struct in6_addr in6addr_any;extern const struct in6_addr in6addr_loopback;extern const struct in6_addr in6addr_nodelocal_allnodes;extern const struct in6_addr in6addr_linklocal_allnodes;extern const struct in6_addr in6addr_linklocal_allrouters;#ifdef MLDV2extern const struct in6_addr in6addr_linklocal_allv2routers;#endif/* Equality */#define IN6_ARE_ADDR_EQUAL(a, b) \ (bcmp ((char *) &(a)->s6_addr[0], (char *) &(b)->s6_addr[0], \ sizeof(struct in6_addr)) == 0)#ifdef _WRS_KERNEL /* non standard */#if 0/* see if two addresses are equal in a scope-conscious manner. */#define SA6_ARE_ADDR_EQUAL(a, b) \ (((a)->sin6_scope_id == 0 || (b)->sin6_scope_id == 0 || \ ((a)->sin6_scope_id == (b)->sin6_scope_id)) && \ (bcmp ((char *) &(a)->sin6_addr, (char *) &(b)->sin6_addr, \ sizeof (struct in6_addr)) == 0))#endif#endif/* * Unspecified */#define IN6_IS_ADDR_UNSPECIFIED(a) \ ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))/* * Loopback */#define IN6_IS_ADDR_LOOPBACK(a) \ ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1)))/* * IPv4 compatible */#define IN6_IS_ADDR_V4COMPAT(a) \ ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1)))/* * Mapped */#define IN6_IS_ADDR_V4MAPPED(a) \ ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))/* * KAME Scope Values */#ifdef _WRS_KERNEL /* XXX nonstandard */#define IPV6_ADDR_SCOPE_NODELOCAL 0x01#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02#define IPV6_ADDR_SCOPE_SITELOCAL 0x05#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */#define IPV6_ADDR_SCOPE_GLOBAL 0x0e#else#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e#endif/* * Unicast Scope * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). */#define IN6_IS_ADDR_LINKLOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))#define IN6_IS_ADDR_SITELOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))/* * Multicast */#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)/* * Global Scope */#define IN6_IS_ADDR_GLOBAL(adr) \ ((!IN6_IS_ADDR_MULTICAST(adr)) && \ (!IN6_IS_ADDR_LINKLOCAL(adr)) && \ (!IN6_IS_ADDR_SITELOCAL(adr)))#ifdef _WRS_KERNEL /* XXX nonstandard */#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)#else#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)#endif/* * Multicast Scope */#ifdef _WRS_KERNEL /* refers nonstandard items */#define IN6_IS_ADDR_MC_NODELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))#define IN6_IS_ADDR_MC_SITELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))#define IN6_IS_ADDR_MC_GLOBAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))#else#define IN6_IS_ADDR_MC_NODELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))#define IN6_IS_ADDR_MC_SITELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -