📄 in.h
字号:
/* $OpenBSD: in.h,v 1.23 1999/04/11 19:41:36 niklas Exp $ *//* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ *//* * 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 *//* * Constants and structures defined by the internet system, * Per RFC 790, September 1981, and numerous additions. */#ifndef _NETINET_IN_H_#define _NETINET_IN_H_/* * Protocols */#define IPPROTO_IP 0 /* dummy for IP */#define IPPROTO_HOPOPTS IPPROTO_IP /* Hop-by-hop option header. */#define IPPROTO_ICMP 1 /* control message protocol */#define IPPROTO_IGMP 2 /* group mgmt protocol */#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */#define IPPROTO_IPIP 4 /* IP inside IP */#define IPPROTO_IPV4 IPPROTO_IPIP /* IP inside IP */#define IPPROTO_TCP 6 /* tcp */#define IPPROTO_EGP 8 /* exterior gateway protocol */#define IPPROTO_PUP 12 /* pup */#define IPPROTO_UDP 17 /* user datagram protocol */#define IPPROTO_IDP 22 /* xns idp */#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */#define IPPROTO_IPV6 41 /* IPv6 in IPv6 */#define IPPROTO_ROUTING 43 /* Routing header. */#define IPPROTO_FRAGMENT 44 /* Fragmentation/reassembly header. */#define IPPROTO_ESP 50 /* Encap. Security Payload */#define IPPROTO_AH 51 /* Authentication header */#define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */#define IPPROTO_NONE 59 /* No next header */#define IPPROTO_DSTOPTS 60 /* Destination options header. */#define IPPROTO_EON 80 /* ISO cnlp */#define IPPROTO_ENCAP 98 /* encapsulation header */#define IPPROTO_RAW 255 /* raw IP packet */#define IPPROTO_MAX 256/* * From FreeBSD: * * Local port number conventions: * * 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_RESERVED through * IPPORT_USERRESERVED, although that is settable by sysctl. * * 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 changes the range of candidate port numbers * into the "high" range. These are reserved for client outbound connections * which do not want to be filtered by any firewalls. * * 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 default range of ports and the high range can be changed by * sysctl(3). (net.inet.ip.port{hi}{first,last}) * * Changing those values has bad security implications if you are * using a a stateless firewall that is allowing packets outside of that * range in order to allow transparent outgoing connections. * * Such a firewall configuration will generally depend on the use of these * default values. If you change them, you may find your Security * Administrator looking for you with a heavy object. *//* * Ports < IPPORT_RESERVED are reserved for * privileged processes (e.g. root). * Ports > IPPORT_USERRESERVED are reserved * for servers, not necessarily privileged. */#define IPPORT_RESERVED 1024#define IPPORT_USERRESERVED 49151/* * Default local port range to use by setting IP_PORTRANGE_HIGH */#define IPPORT_HIFIRSTAUTO 49152#define IPPORT_HILASTAUTO 65535/* * IP Version 4 Internet address (a structure for historical reasons) */struct in_addr { in_addr_t s_addr;};/* * IP Version 6 Internet address */struct in6_addr { union { u_int8_t s6u_addr8[16]; u_int16_t s6u_addr16[8]; u_int32_t s6u_addr32[4]; } s6_u;#define s6_addr s6_u.s6u_addr8/* * The rest are common, but not guaranteed to be portable. 64 bit access are * not available because the in6_addr in a sockaddr_in6 is not 64 bit aligned. */#define s6_addr8 s6_u.s6u_addr8#define s6_addr16 s6_u.s6u_addr16#define s6_addr32 s6_u.s6u_addr32};/* * Definitions of bits in internet address integers. * On subnets, the decomposition of addresses to host and net parts * is done according to subnet mask, not the masks here. * * By byte-swapping the constants, we avoid ever having to byte-swap IP * addresses inside the kernel. Unfortunately, user-level programs rely * on these macros not doing byte-swapping. */#ifdef _KERNEL#define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x)))#else#define __IPADDR(x) ((u_int32_t)(x))#endif#define IN_CLASSA(i) (((u_int32_t)(i) & __IPADDR(0x80000000)) == \ __IPADDR(0x00000000))#define IN_CLASSA_NET __IPADDR(0xff000000)#define IN_CLASSA_NSHIFT 24#define IN_CLASSA_HOST __IPADDR(0x00ffffff)#define IN_CLASSA_MAX 128#define IN_CLASSB(i) (((u_int32_t)(i) & __IPADDR(0xc0000000)) == \ __IPADDR(0x80000000))#define IN_CLASSB_NET __IPADDR(0xffff0000)#define IN_CLASSB_NSHIFT 16#define IN_CLASSB_HOST __IPADDR(0x0000ffff)#define IN_CLASSB_MAX 65536#define IN_CLASSC(i) (((u_int32_t)(i) & __IPADDR(0xe0000000)) == \ __IPADDR(0xc0000000))#define IN_CLASSC_NET __IPADDR(0xffffff00)#define IN_CLASSC_NSHIFT 8#define IN_CLASSC_HOST __IPADDR(0x000000ff)#define IN_CLASSD(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ __IPADDR(0xe0000000))/* These ones aren't really net and host fields, but routing needn't know. */#define IN_CLASSD_NET __IPADDR(0xf0000000)#define IN_CLASSD_NSHIFT 28#define IN_CLASSD_HOST __IPADDR(0x0fffffff)#define IN_MULTICAST(i) IN_CLASSD(i)#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ __IPADDR(0xf0000000))#define IN_BADCLASS(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ __IPADDR(0xf0000000))#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & __IPADDR(0xffffff00)) == \ __IPADDR(0xe0000000))#define INADDR_ANY __IPADDR(0x00000000)#define INADDR_LOOPBACK __IPADDR(0x7f000001)#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */#ifndef _KERNEL#define INADDR_NONE __IPADDR(0xffffffff) /* -1 return */#endif#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */#define IN_LOOPBACKNET 127 /* official! *//* * Tests for IPv6 address types */#define IN6_IS_ADDR_LINKLOCAL(addr) \ (((addr)->s6_addr32[0] & htonl(0xffc00000)) == htonl(0xfe800000))#define IN6_IS_ADDR_LOOPBACK(addr) \ (((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \ ((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] == htonl(1)))#define IN6_IS_ADDR_MULTICAST(addr) \ ((addr)->s6_addr8[0] == 0xff) #define IN6_IS_ADDR_SITELOCAL(addr) \ (((addr)->s6_addr32[0] & htonl(0xffc00000)) == htonl(0xfec00000))#define IN6_IS_ADDR_UNSPECIFIED(addr) \ (((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \ ((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] == 0))#define IN6_IS_ADDR_V4COMPAT(addr) \ (((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \ ((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] & ~htonl(1)))#define IN6_IS_ADDR_V4MAPPED(addr) \ (((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \ ((addr)->s6_addr32[2] == htonl(0xffff)))#define IN6_ARE_ADDR_EQUAL(addr1, addr2) \ (((addr1)->s6_addr32[0] == (addr2)->s6_addr32[0]) && \ ((addr1)->s6_addr32[1] == (addr2)->s6_addr32[1]) && \ ((addr1)->s6_addr32[2] == (addr2)->s6_addr32[2]) && \ ((addr1)->s6_addr32[3] == (addr2)->s6_addr32[3]))/* * IPv6 Multicast scoping. The scope is stored * in the bottom 4 bits of the second byte of the * multicast address. */ /* 0x0 */ /* reserved */#define IN6_NODE_LOCAL 0x1 /* node-local scope */#define IN6_LINK_LOCAL 0x2 /* link-local scope */ /* 0x3 */ /* (unassigned) */ /* 0x4 */ /* (unassigned) */#define IN6_SITE_LOCAL 0x5 /* site-local scope */ /* 0x6 */ /* (unassigned) */ /* 0x7 */ /* (unassigned) */#define IN6_ORG_LOCAL 0x8 /* organization-local scope */ /* 0x9 */ /* (unassigned) */ /* 0xA */ /* (unassigned) */ /* 0xB */ /* (unassigned) */ /* 0xC */ /* (unassigned) */ /* 0xD */ /* (unassigned) */#define IN6_GLOBAL 0xE /* global scope */ /* 0xF */ /* reserved */#define IN6_MSCOPE(addr) ((addr)->s6_addr8[1] & 0x0f)#define IN6_IS_ADDR_MC_NODELOCAL(addr) \ (IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_NODE_LOCAL))#define IN6_IS_ADDR_MC_LINKLOCAL(addr) \ (IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_LINK_LOCAL))#define IN6_IS_ADDR_MC_SITELOCAL(addr) \ (IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_SITE_LOCAL))#define IN6_IS_ADDR_MC_ORGLOCAL(addr) \ (IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_ORG_LOCAL))#define IN6_IS_ADDR_MC_GLOBAL(addr) \ (IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_GLOBAL))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -