📄 in6.h
字号:
//==========================================================================//// include/netinet6_in6.h//// ////==========================================================================//####BSDCOPYRIGHTBEGIN####//// -------------------------------------------//// Portions of this software may have been derived from OpenBSD or other sources,// and are covered by the appropriate copyright disclaimers included herein.//// -------------------------------------------////####BSDCOPYRIGHTEND####//==========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): gthomas// Contributors: gthomas// Date: 2000-01-10// Purpose: // Description: // ////####DESCRIPTIONEND####////==========================================================================/* $OpenBSD: in6.h,v 1.9 1999/12/10 08:53:17 angelos 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 */#ifndef _NETINET6_IN6_H_#define _NETINET6_IN6_H_#if !defined(_XOPEN_SOURCE)#include <sys/queue.h>#endif/* * Identification of the network protocol stack */#define __KAME__#define __KAME_VERSION "19991208/OpenBSD-current"/* * 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_ANONMIX 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 _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 */#if !defined(_XOPEN_SOURCE)#define SIN6_LEN#endifstruct sockaddr_in6 { u_char sin6_len; /* length of this struct(sa_family_t)*/ u_char 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; /* intface scope id */};/* * Local definition for masks */#ifdef _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 }}}#endif#ifdef _KERNELextern 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;#endif /* _KERNEL *//* * Macros started with IPV6_ADDR is KAME local */#ifdef _KERNEL /*XXX nonstandard*/#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/* * 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_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 }}}extern 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;/* * Equality * NOTE: Some of kernel programming environment (for example, openbsd/sparc) * does not supply memcmp(). For userland memcmp() is preferred as it is * in ANSI standard. */#ifdef _KERNEL#define IN6_ARE_ADDR_EQUAL(a, b) \ (bcmp((a), (b), sizeof(struct in6_addr)) == 0)#else#define IN6_ARE_ADDR_EQUAL(a, b) \ (memcmp((a), (b), sizeof(struct in6_addr)) == 0)#endif/* * Unspecified */#define IN6_IS_ADDR_UNSPECIFIED(a) \ ((*(u_int32_t *)(&(a)->s6_addr[0]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[4]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[8]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[12]) == 0))/* * Loopback */#define IN6_IS_ADDR_LOOPBACK(a) \ ((*(u_int32_t *)(&(a)->s6_addr[0]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[4]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[8]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[12]) == ntohl(1)))/* * IPv4 compatible */#define IN6_IS_ADDR_V4COMPAT(a) \ ((*(u_int32_t *)(&(a)->s6_addr[0]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[4]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[8]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[12]) != 0) && \ (*(u_int32_t *)(&(a)->s6_addr[12]) != ntohl(1)))/* * Mapped */#define IN6_IS_ADDR_V4MAPPED(a) \ ((*(u_int32_t *)(&(a)->s6_addr[0]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[4]) == 0) && \ (*(u_int32_t *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))/* * KAME Scope Values */#ifdef _KERNEL /*XXX nonstandard*/#define IPV6_ADDR_SCOPE_NODELOCAL 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_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)#ifdef _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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -