in.h revision 206022
1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1990, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)in.h 8.3 (Berkeley) 1/3/94 3050477Speter * $FreeBSD: head/sys/netinet/in.h 206022 2010-03-31 23:02:25Z delphij $ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_IN_H_ 34121498Sume#define _NETINET_IN_H_ 352169Spaul 3695336Smike#include <sys/cdefs.h> 3793514Smike#include <sys/_types.h> 3895336Smike#include <machine/endian.h> 3993514Smike 4095336Smike/* Protocols common to RFC 1700, POSIX, and X/Open. */ 4195336Smike#define IPPROTO_IP 0 /* dummy for IP */ 4295336Smike#define IPPROTO_ICMP 1 /* control message protocol */ 4395336Smike#define IPPROTO_TCP 6 /* tcp */ 4495336Smike#define IPPROTO_UDP 17 /* user datagram protocol */ 4595336Smike 4695336Smike#define INADDR_ANY (u_int32_t)0x00000000 4795336Smike#define INADDR_BROADCAST (u_int32_t)0xffffffff /* must be masked */ 4895336Smike 4995336Smike#ifndef _UINT8_T_DECLARED 5095336Smiketypedef __uint8_t uint8_t; 5195336Smike#define _UINT8_T_DECLARED 5295336Smike#endif 5395336Smike 5495336Smike#ifndef _UINT16_T_DECLARED 5595336Smiketypedef __uint16_t uint16_t; 5695336Smike#define _UINT16_T_DECLARED 5795336Smike#endif 5895336Smike 5995336Smike#ifndef _UINT32_T_DECLARED 6095336Smiketypedef __uint32_t uint32_t; 6195336Smike#define _UINT32_T_DECLARED 6295336Smike#endif 6395336Smike 6495336Smike#ifndef _IN_ADDR_T_DECLARED 6595336Smiketypedef uint32_t in_addr_t; 6695336Smike#define _IN_ADDR_T_DECLARED 6795336Smike#endif 6895336Smike 6995336Smike#ifndef _IN_PORT_T_DECLARED 7095336Smiketypedef uint16_t in_port_t; 7195336Smike#define _IN_PORT_T_DECLARED 7295336Smike#endif 7395336Smike 74102227Smike#ifndef _SA_FAMILY_T_DECLARED 75102227Smiketypedef __sa_family_t sa_family_t; 76102227Smike#define _SA_FAMILY_T_DECLARED 7795336Smike#endif 7895336Smike 7995336Smike/* Internet address (a structure for historical reasons). */ 8095336Smike#ifndef _STRUCT_IN_ADDR_DECLARED 8195336Smikestruct in_addr { 8295336Smike in_addr_t s_addr; 8395336Smike}; 8495336Smike#define _STRUCT_IN_ADDR_DECLARED 8595336Smike#endif 8695336Smike 87170613Sbms#ifndef _SOCKLEN_T_DECLARED 88170613Sbmstypedef __socklen_t socklen_t; 89170613Sbms#define _SOCKLEN_T_DECLARED 90170613Sbms#endif 91170613Sbms 92196967Sphk#include <sys/_sockaddr_storage.h> 93170613Sbms 9495336Smike/* Socket address, internet style. */ 9595336Smikestruct sockaddr_in { 9695336Smike uint8_t sin_len; 9795336Smike sa_family_t sin_family; 9895336Smike in_port_t sin_port; 9995336Smike struct in_addr sin_addr; 10095336Smike char sin_zero[8]; 10195336Smike}; 10295336Smike 103189829Sdas#if !defined(_KERNEL) && __BSD_VISIBLE 10495336Smike 10595336Smike#ifndef _BYTEORDER_PROTOTYPED 10695336Smike#define _BYTEORDER_PROTOTYPED 10795336Smike__BEGIN_DECLS 10895336Smikeuint32_t htonl(uint32_t); 10995336Smikeuint16_t htons(uint16_t); 11095336Smikeuint32_t ntohl(uint32_t); 11195336Smikeuint16_t ntohs(uint16_t); 11295336Smike__END_DECLS 11395336Smike#endif 11495336Smike 11595336Smike#ifndef _BYTEORDER_FUNC_DEFINED 11695336Smike#define _BYTEORDER_FUNC_DEFINED 11795336Smike#define htonl(x) __htonl(x) 11895336Smike#define htons(x) __htons(x) 11995336Smike#define ntohl(x) __ntohl(x) 12095336Smike#define ntohs(x) __ntohs(x) 12195336Smike#endif 12295336Smike 123189829Sdas#endif /* !_KERNEL && __BSD_VISIBLE */ 12495336Smike 12595336Smike#if __POSIX_VISIBLE >= 200112 12695336Smike#define IPPROTO_RAW 255 /* raw IP packet */ 12795336Smike#define INET_ADDRSTRLEN 16 12895336Smike#endif 12995336Smike 13095336Smike#if __BSD_VISIBLE 1311541Srgrimes/* 1321541Srgrimes * Constants and structures defined by the internet system, 1331541Srgrimes * Per RFC 790, September 1981, and numerous additions. 1341541Srgrimes */ 1351541Srgrimes 1361541Srgrimes/* 13733804Sjulian * Protocols (RFC 1700) 1381541Srgrimes */ 13952904Sshin#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */ 1401541Srgrimes#define IPPROTO_IGMP 2 /* group mgmt protocol */ 1411541Srgrimes#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 142133874Srwatson#define IPPROTO_IPV4 4 /* IPv4 encapsulation */ 143133874Srwatson#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */ 14433804Sjulian#define IPPROTO_ST 7 /* Stream protocol II */ 1451541Srgrimes#define IPPROTO_EGP 8 /* exterior gateway protocol */ 14633804Sjulian#define IPPROTO_PIGP 9 /* private interior gateway */ 14733804Sjulian#define IPPROTO_RCCMON 10 /* BBN RCC Monitoring */ 14833804Sjulian#define IPPROTO_NVPII 11 /* network voice protocol*/ 1491541Srgrimes#define IPPROTO_PUP 12 /* pup */ 15033804Sjulian#define IPPROTO_ARGUS 13 /* Argus */ 15133804Sjulian#define IPPROTO_EMCON 14 /* EMCON */ 15233804Sjulian#define IPPROTO_XNET 15 /* Cross Net Debugger */ 15333804Sjulian#define IPPROTO_CHAOS 16 /* Chaos*/ 15433804Sjulian#define IPPROTO_MUX 18 /* Multiplexing */ 15533804Sjulian#define IPPROTO_MEAS 19 /* DCN Measurement Subsystems */ 15633804Sjulian#define IPPROTO_HMP 20 /* Host Monitoring */ 15733804Sjulian#define IPPROTO_PRM 21 /* Packet Radio Measurement */ 1581541Srgrimes#define IPPROTO_IDP 22 /* xns idp */ 15933804Sjulian#define IPPROTO_TRUNK1 23 /* Trunk-1 */ 16033804Sjulian#define IPPROTO_TRUNK2 24 /* Trunk-2 */ 16133804Sjulian#define IPPROTO_LEAF1 25 /* Leaf-1 */ 16233804Sjulian#define IPPROTO_LEAF2 26 /* Leaf-2 */ 16333804Sjulian#define IPPROTO_RDP 27 /* Reliable Data */ 16433804Sjulian#define IPPROTO_IRTP 28 /* Reliable Transaction */ 165133874Srwatson#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 16633804Sjulian#define IPPROTO_BLT 30 /* Bulk Data Transfer */ 16733804Sjulian#define IPPROTO_NSP 31 /* Network Services */ 16833804Sjulian#define IPPROTO_INP 32 /* Merit Internodal */ 16933804Sjulian#define IPPROTO_SEP 33 /* Sequential Exchange */ 17033804Sjulian#define IPPROTO_3PC 34 /* Third Party Connect */ 17133804Sjulian#define IPPROTO_IDPR 35 /* InterDomain Policy Routing */ 17233804Sjulian#define IPPROTO_XTP 36 /* XTP */ 17333804Sjulian#define IPPROTO_DDP 37 /* Datagram Delivery */ 17433804Sjulian#define IPPROTO_CMTP 38 /* Control Message Transport */ 17533804Sjulian#define IPPROTO_TPXX 39 /* TP++ Transport */ 17633804Sjulian#define IPPROTO_IL 40 /* IL transport protocol */ 17752904Sshin#define IPPROTO_IPV6 41 /* IP6 header */ 17833804Sjulian#define IPPROTO_SDRP 42 /* Source Demand Routing */ 17952904Sshin#define IPPROTO_ROUTING 43 /* IP6 routing header */ 18052904Sshin#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */ 18133804Sjulian#define IPPROTO_IDRP 45 /* InterDomain Routing*/ 182133874Srwatson#define IPPROTO_RSVP 46 /* resource reservation */ 18333804Sjulian#define IPPROTO_GRE 47 /* General Routing Encap. */ 18433804Sjulian#define IPPROTO_MHRP 48 /* Mobile Host Routing */ 18533804Sjulian#define IPPROTO_BHA 49 /* BHA */ 18652904Sshin#define IPPROTO_ESP 50 /* IP6 Encap Sec. Payload */ 18752904Sshin#define IPPROTO_AH 51 /* IP6 Auth Header */ 18833804Sjulian#define IPPROTO_INLSP 52 /* Integ. Net Layer Security */ 18933804Sjulian#define IPPROTO_SWIPE 53 /* IP with encryption */ 19033804Sjulian#define IPPROTO_NHRP 54 /* Next Hop Resolution */ 191133874Srwatson#define IPPROTO_MOBILE 55 /* IP Mobility */ 192133874Srwatson#define IPPROTO_TLSP 56 /* Transport Layer Security */ 193133874Srwatson#define IPPROTO_SKIP 57 /* SKIP */ 19452904Sshin#define IPPROTO_ICMPV6 58 /* ICMP6 */ 19552904Sshin#define IPPROTO_NONE 59 /* IP6 no next header */ 19652904Sshin#define IPPROTO_DSTOPTS 60 /* IP6 destination option */ 19733804Sjulian#define IPPROTO_AHIP 61 /* any host internal protocol */ 19833804Sjulian#define IPPROTO_CFTP 62 /* CFTP */ 19933804Sjulian#define IPPROTO_HELLO 63 /* "hello" routing protocol */ 20033804Sjulian#define IPPROTO_SATEXPAK 64 /* SATNET/Backroom EXPAK */ 20133804Sjulian#define IPPROTO_KRYPTOLAN 65 /* Kryptolan */ 20233804Sjulian#define IPPROTO_RVD 66 /* Remote Virtual Disk */ 20333804Sjulian#define IPPROTO_IPPC 67 /* Pluribus Packet Core */ 20433804Sjulian#define IPPROTO_ADFS 68 /* Any distributed FS */ 20533804Sjulian#define IPPROTO_SATMON 69 /* Satnet Monitoring */ 20633804Sjulian#define IPPROTO_VISA 70 /* VISA Protocol */ 20733804Sjulian#define IPPROTO_IPCV 71 /* Packet Core Utility */ 20833804Sjulian#define IPPROTO_CPNX 72 /* Comp. Prot. Net. Executive */ 20933804Sjulian#define IPPROTO_CPHB 73 /* Comp. Prot. HeartBeat */ 21033804Sjulian#define IPPROTO_WSN 74 /* Wang Span Network */ 21133804Sjulian#define IPPROTO_PVP 75 /* Packet Video Protocol */ 21233804Sjulian#define IPPROTO_BRSATMON 76 /* BackRoom SATNET Monitoring */ 21333804Sjulian#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */ 21433804Sjulian#define IPPROTO_WBMON 78 /* WIDEBAND Monitoring */ 21533804Sjulian#define IPPROTO_WBEXPAK 79 /* WIDEBAND EXPAK */ 2161541Srgrimes#define IPPROTO_EON 80 /* ISO cnlp */ 21733804Sjulian#define IPPROTO_VMTP 81 /* VMTP */ 21833804Sjulian#define IPPROTO_SVMTP 82 /* Secure VMTP */ 21933804Sjulian#define IPPROTO_VINES 83 /* Banyon VINES */ 22033804Sjulian#define IPPROTO_TTP 84 /* TTP */ 22133804Sjulian#define IPPROTO_IGP 85 /* NSFNET-IGP */ 22233804Sjulian#define IPPROTO_DGP 86 /* dissimilar gateway prot. */ 22333814Sjulian#define IPPROTO_TCF 87 /* TCF */ 22433804Sjulian#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */ 22533804Sjulian#define IPPROTO_OSPFIGP 89 /* OSPFIGP */ 22633804Sjulian#define IPPROTO_SRPC 90 /* Strite RPC protocol */ 22733804Sjulian#define IPPROTO_LARP 91 /* Locus Address Resoloution */ 22833804Sjulian#define IPPROTO_MTP 92 /* Multicast Transport */ 22933804Sjulian#define IPPROTO_AX25 93 /* AX.25 Frames */ 23033804Sjulian#define IPPROTO_IPEIP 94 /* IP encapsulated in IP */ 23133804Sjulian#define IPPROTO_MICP 95 /* Mobile Int.ing control */ 23233804Sjulian#define IPPROTO_SCCSP 96 /* Semaphore Comm. security */ 23333804Sjulian#define IPPROTO_ETHERIP 97 /* Ethernet IP encapsulation */ 2341541Srgrimes#define IPPROTO_ENCAP 98 /* encapsulation header */ 23533804Sjulian#define IPPROTO_APES 99 /* any private encr. scheme */ 23633804Sjulian#define IPPROTO_GMTP 100 /* GMTP*/ 23752904Sshin#define IPPROTO_IPCOMP 108 /* payload compression (IPComp) */ 238153553Sdelphij#define IPPROTO_SCTP 132 /* SCTP */ 239206022Sdelphij#define IPPROTO_MH 135 /* IPv6 Mobility Header */ 24046420Sluigi/* 101-254: Partly Unassigned */ 24152904Sshin#define IPPROTO_PIM 103 /* Protocol Independent Mcast */ 242142215Sglebius#define IPPROTO_CARP 112 /* CARP */ 24346420Sluigi#define IPPROTO_PGM 113 /* PGM */ 244130609Smlaier#define IPPROTO_PFSYNC 240 /* PFSYNC */ 24533804Sjulian/* 255: Reserved */ 246106152Sfenner/* BSD Private, local use, namespace incursion, no longer used */ 247106152Sfenner#define IPPROTO_OLD_DIVERT 254 /* OLD divert pseudo-proto */ 2481541Srgrimes#define IPPROTO_MAX 256 2491541Srgrimes 25052904Sshin/* last return value of *_input(), meaning "all job for this pkt is done". */ 25152904Sshin#define IPPROTO_DONE 257 2521541Srgrimes 253106152Sfenner/* Only used internally, so can be outside the range of valid IP protocols. */ 254106152Sfenner#define IPPROTO_DIVERT 258 /* divert pseudo-protocol */ 255106152Sfenner 2561541Srgrimes/* 257136712Sandre * Defined to avoid confusion. The master value is defined by 258136712Sandre * PROTO_SPACER in sys/protosw.h. 259136712Sandre */ 260136712Sandre#define IPPROTO_SPACER 32767 /* spacer for loadable protos */ 261136712Sandre 262136712Sandre/* 2631541Srgrimes * Local port number conventions: 26414195Speter * 26514195Speter * When a user does a bind(2) or connect(2) with a port number of zero, 26614195Speter * a non-conflicting local port address is chosen. 26794291Ssilby * The default range is IPPORT_HIFIRSTAUTO through 26894291Ssilby * IPPORT_HILASTAUTO, although that is settable by sysctl. 26914195Speter * 27014195Speter * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 27114195Speter * default assignment range. 27214195Speter * 27314195Speter * The value IP_PORTRANGE_DEFAULT causes the default behavior. 27414195Speter * 27514195Speter * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers 27614195Speter * into the "high" range. These are reserved for client outbound connections 277176805Srpaulo * which do not want to be filtered by any firewalls. 27814195Speter * 27914195Speter * The value IP_PORTRANGE_LOW changes the range to the "low" are 28014195Speter * that is (by convention) restricted to privileged processes. This 28114195Speter * convention is based on "vouchsafe" principles only. It is only secure 28214195Speter * if you trust the remote host to restrict these ports. 28314195Speter * 28414195Speter * The default range of ports and the high range can be changed by 28517541Speter * sysctl(3). (net.inet.ip.port{hi,low}{first,last}_auto) 28614195Speter * 28714195Speter * Changing those values has bad security implications if you are 288108533Sschweikh * using a stateless firewall that is allowing packets outside of that 28914195Speter * range in order to allow transparent outgoing connections. 29014195Speter * 29114195Speter * Such a firewall configuration will generally depend on the use of these 29214195Speter * default values. If you change them, you may find your Security 29314195Speter * Administrator looking for you with a heavy object. 29435304Sphk * 29535304Sphk * For a slightly more orthodox text view on this: 29635304Sphk * 29735304Sphk * ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers 29835304Sphk * 29935304Sphk * port numbers are divided into three ranges: 30035304Sphk * 30135304Sphk * 0 - 1023 Well Known Ports 30235304Sphk * 1024 - 49151 Registered Ports 30335304Sphk * 49152 - 65535 Dynamic and/or Private Ports 30435304Sphk * 30514195Speter */ 30614195Speter 30714195Speter/* 3081541Srgrimes * Ports < IPPORT_RESERVED are reserved for 30914195Speter * privileged processes (e.g. root). (IP_PORTRANGE_LOW) 3101541Srgrimes */ 3111541Srgrimes#define IPPORT_RESERVED 1024 3121541Srgrimes 3131541Srgrimes/* 314176805Srpaulo * Default local port range, used by IP_PORTRANGE_DEFAULT 31513491Speter */ 316176805Srpaulo#define IPPORT_EPHEMERALFIRST 10000 317176805Srpaulo#define IPPORT_EPHEMERALLAST 65535 318176805Srpaulo 319176805Srpaulo/* 320176805Srpaulo * Dynamic port range, used by IP_PORTRANGE_HIGH. 321176805Srpaulo */ 32235304Sphk#define IPPORT_HIFIRSTAUTO 49152 32335304Sphk#define IPPORT_HILASTAUTO 65535 32413491Speter 32513491Speter/* 32617541Speter * Scanning for a free reserved port return a value below IPPORT_RESERVED, 32717541Speter * but higher than IPPORT_RESERVEDSTART. Traditionally the start value was 32817541Speter * 512, but that conflicts with some well-known-services that firewalls may 32917541Speter * have a fit if we use. 33017541Speter */ 331133874Srwatson#define IPPORT_RESERVEDSTART 600 33217541Speter 33387158Smike#define IPPORT_MAX 65535 33487158Smike 33517541Speter/* 3361541Srgrimes * Definitions of bits in internet address integers. 3371541Srgrimes * On subnets, the decomposition of addresses to host and net parts 3381541Srgrimes * is done according to subnet mask, not the masks here. 3391541Srgrimes */ 34035919Sjb#define IN_CLASSA(i) (((u_int32_t)(i) & 0x80000000) == 0) 3411541Srgrimes#define IN_CLASSA_NET 0xff000000 3421541Srgrimes#define IN_CLASSA_NSHIFT 24 3431541Srgrimes#define IN_CLASSA_HOST 0x00ffffff 3441541Srgrimes#define IN_CLASSA_MAX 128 3451541Srgrimes 34635919Sjb#define IN_CLASSB(i) (((u_int32_t)(i) & 0xc0000000) == 0x80000000) 3471541Srgrimes#define IN_CLASSB_NET 0xffff0000 3481541Srgrimes#define IN_CLASSB_NSHIFT 16 3491541Srgrimes#define IN_CLASSB_HOST 0x0000ffff 3501541Srgrimes#define IN_CLASSB_MAX 65536 3511541Srgrimes 35235919Sjb#define IN_CLASSC(i) (((u_int32_t)(i) & 0xe0000000) == 0xc0000000) 3531541Srgrimes#define IN_CLASSC_NET 0xffffff00 3541541Srgrimes#define IN_CLASSC_NSHIFT 8 3551541Srgrimes#define IN_CLASSC_HOST 0x000000ff 3561541Srgrimes 35735919Sjb#define IN_CLASSD(i) (((u_int32_t)(i) & 0xf0000000) == 0xe0000000) 3581541Srgrimes#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 3591541Srgrimes#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 3601541Srgrimes#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 3611541Srgrimes#define IN_MULTICAST(i) IN_CLASSD(i) 3621541Srgrimes 36335919Sjb#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000) 36435919Sjb#define IN_BADCLASS(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000) 3651541Srgrimes 366166368Sbms#define IN_LINKLOCAL(i) (((u_int32_t)(i) & 0xffff0000) == 0xa9fe0000) 367178280Sgnn#define IN_LOOPBACK(i) (((u_int32_t)(i) & 0xff000000) == 0x7f000000) 368178280Sgnn#define IN_ZERONET(i) (((u_int32_t)(i) & 0xff000000) == 0) 369166368Sbms 370166368Sbms#define IN_PRIVATE(i) ((((u_int32_t)(i) & 0xff000000) == 0x0a000000) || \ 371166368Sbms (((u_int32_t)(i) & 0xfff00000) == 0xac100000) || \ 372166368Sbms (((u_int32_t)(i) & 0xffff0000) == 0xc0a80000)) 373166368Sbms 374166368Sbms#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & 0xffffff00) == 0xe0000000) 375166368Sbms 376166368Sbms#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i)) 377166368Sbms 37835919Sjb#define INADDR_LOOPBACK (u_int32_t)0x7f000001 37955205Speter#ifndef _KERNEL 3801541Srgrimes#define INADDR_NONE 0xffffffff /* -1 return */ 3811541Srgrimes#endif 3821541Srgrimes 38335919Sjb#define INADDR_UNSPEC_GROUP (u_int32_t)0xe0000000 /* 224.0.0.0 */ 38435919Sjb#define INADDR_ALLHOSTS_GROUP (u_int32_t)0xe0000001 /* 224.0.0.1 */ 38535919Sjb#define INADDR_ALLRTRS_GROUP (u_int32_t)0xe0000002 /* 224.0.0.2 */ 386167072Sbms#define INADDR_ALLRPTS_GROUP (u_int32_t)0xe0000016 /* 224.0.0.22, IGMPv3 */ 387142215Sglebius#define INADDR_CARP_GROUP (u_int32_t)0xe0000012 /* 224.0.0.18 */ 388130609Smlaier#define INADDR_PFSYNC_GROUP (u_int32_t)0xe00000f0 /* 224.0.0.240 */ 389114259Smdodd#define INADDR_ALLMDNS_GROUP (u_int32_t)0xe00000fb /* 224.0.0.251 */ 39035919Sjb#define INADDR_MAX_LOCAL_GROUP (u_int32_t)0xe00000ff /* 224.0.0.255 */ 3911541Srgrimes 3921541Srgrimes#define IN_LOOPBACKNET 127 /* official! */ 3931541Srgrimes 3941541Srgrimes/* 3951541Srgrimes * Options for use with [gs]etsockopt at the IP level. 3961541Srgrimes * First word of comment is data type; bool is stored in int. 3971541Srgrimes */ 3981541Srgrimes#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 3991541Srgrimes#define IP_HDRINCL 2 /* int; header is included with data */ 4001541Srgrimes#define IP_TOS 3 /* int; IP type of service and preced. */ 4011541Srgrimes#define IP_TTL 4 /* int; IP time to live */ 4021541Srgrimes#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 4031541Srgrimes#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 4041541Srgrimes#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 405105651Siedowse#define IP_SENDSRCADDR IP_RECVDSTADDR /* cmsg_type to set src addr */ 4061541Srgrimes#define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 407170613Sbms#define IP_MULTICAST_IF 9 /* struct in_addr *or* struct ip_mreqn; 408170613Sbms * set/get IP multicast i/f */ 4091541Srgrimes#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 4101541Srgrimes#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 4111541Srgrimes#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 4121541Srgrimes#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 413133874Srwatson#define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */ 414133874Srwatson#define IP_RSVP_ON 15 /* enable RSVP in kernel */ 415133874Srwatson#define IP_RSVP_OFF 16 /* disable RSVP in kernel */ 416133874Srwatson#define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */ 417133874Srwatson#define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */ 418133874Srwatson#define IP_PORTRANGE 19 /* int; range to choose for unspec port */ 41919622Sfenner#define IP_RECVIF 20 /* bool; receive reception if w/dgram */ 42052904Sshin/* for IPSEC */ 42152904Sshin#define IP_IPSEC_POLICY 21 /* int; set/get security policy */ 42252904Sshin#define IP_FAITH 22 /* bool; accept FAITH'ed connections */ 4231541Srgrimes 424119178Sbms#define IP_ONESBCAST 23 /* bool: send all-ones broadcast */ 425193217Spjd#define IP_BINDANY 24 /* bool: allow bind to any address */ 426119178Sbms 427200023Sluigi/* 428200023Sluigi * Options for controlling the firewall and dummynet. 429200023Sluigi * Historical options (from 40 to 64) will eventually be 430200023Sluigi * replaced by only two options, IP_FW3 and IP_DUMMYNET3. 431200023Sluigi */ 432130281Sru#define IP_FW_TABLE_ADD 40 /* add entry */ 433130281Sru#define IP_FW_TABLE_DEL 41 /* delete entry */ 434130281Sru#define IP_FW_TABLE_FLUSH 42 /* flush table */ 435130281Sru#define IP_FW_TABLE_GETSIZE 43 /* get table size */ 436130281Sru#define IP_FW_TABLE_LIST 44 /* list table contents */ 437130281Sru 438200023Sluigi#define IP_FW3 48 /* generic ipfw v.3 sockopts */ 439200023Sluigi#define IP_DUMMYNET3 49 /* generic dummynet v.3 sockopts */ 440200023Sluigi 441133874Srwatson#define IP_FW_ADD 50 /* add a firewall rule to chain */ 442133874Srwatson#define IP_FW_DEL 51 /* delete a firewall rule from chain */ 443133874Srwatson#define IP_FW_FLUSH 52 /* flush firewall rule chain */ 444133874Srwatson#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */ 445133874Srwatson#define IP_FW_GET 54 /* get entire firewall rule chain */ 44652904Sshin#define IP_FW_RESETLOG 55 /* reset logging counters */ 44717758Ssos 448165648Spiso#define IP_FW_NAT_CFG 56 /* add/config a nat rule */ 449165648Spiso#define IP_FW_NAT_DEL 57 /* delete a nat rule */ 450165648Spiso#define IP_FW_NAT_GET_CONFIG 58 /* get configuration of a nat rule */ 451165648Spiso#define IP_FW_NAT_GET_LOG 59 /* get log of a nat rule */ 452165648Spiso 45341793Sluigi#define IP_DUMMYNET_CONFIGURE 60 /* add/configure a dummynet pipe */ 45441793Sluigi#define IP_DUMMYNET_DEL 61 /* delete a dummynet pipe from chain */ 45541793Sluigi#define IP_DUMMYNET_FLUSH 62 /* flush dummynet */ 45641793Sluigi#define IP_DUMMYNET_GET 64 /* get entire dummynet pipes */ 45741793Sluigi 458114258Smdodd#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */ 459149371Sandre#define IP_MINTTL 66 /* minimum TTL for packet or drop */ 460150594Sandre#define IP_DONTFRAG 67 /* don't fragment packet */ 461114258Smdodd 462170613Sbms/* IPv4 Source Filter Multicast API [RFC3678] */ 463170613Sbms#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */ 464170613Sbms#define IP_DROP_SOURCE_MEMBERSHIP 71 /* drop a single source */ 465170613Sbms#define IP_BLOCK_SOURCE 72 /* block a source */ 466170613Sbms#define IP_UNBLOCK_SOURCE 73 /* unblock a source */ 467170613Sbms 468170613Sbms/* The following option is private; do not use it from user applications. */ 469170613Sbms#define IP_MSFILTER 74 /* set/get filter list */ 470170613Sbms 471170613Sbms/* Protocol Independent Multicast API [RFC3678] */ 472170613Sbms#define MCAST_JOIN_GROUP 80 /* join an any-source group */ 473170613Sbms#define MCAST_LEAVE_GROUP 81 /* leave all sources for group */ 474170613Sbms#define MCAST_JOIN_SOURCE_GROUP 82 /* join a source-specific group */ 475170613Sbms#define MCAST_LEAVE_SOURCE_GROUP 83 /* leave a single source */ 476170613Sbms#define MCAST_BLOCK_SOURCE 84 /* block a source */ 477170613Sbms#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */ 478170613Sbms 4791541Srgrimes/* 4801541Srgrimes * Defaults and limits for options 4811541Srgrimes */ 4821541Srgrimes#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 4831541Srgrimes#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 4841541Srgrimes 4851541Srgrimes/* 486158563Sbms * The imo_membership vector for each socket is now dynamically allocated at 487158563Sbms * run-time, bounded by USHRT_MAX, and is reallocated when needed, sized 488158563Sbms * according to a power-of-two increment. 489158563Sbms */ 490158563Sbms#define IP_MIN_MEMBERSHIPS 31 491158563Sbms#define IP_MAX_MEMBERSHIPS 4095 492189346Sbms#define IP_MAX_SOURCE_FILTER 1024 /* XXX to be unused */ 493158563Sbms 494158563Sbms/* 495189346Sbms * Default resource limits for IPv4 multicast source filtering. 496189346Sbms * These may be modified by sysctl. 497189346Sbms */ 498189346Sbms#define IP_MAX_GROUP_SRC_FILTER 512 /* sources per group */ 499189346Sbms#define IP_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */ 500189592Sbms#define IP_MAX_SOCK_MUTE_FILTER 128 /* XXX no longer used */ 501189346Sbms 502189346Sbms/* 5031541Srgrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 5041541Srgrimes */ 5051541Srgrimesstruct ip_mreq { 5061541Srgrimes struct in_addr imr_multiaddr; /* IP multicast address of group */ 5071541Srgrimes struct in_addr imr_interface; /* local IP address of interface */ 5081541Srgrimes}; 5091541Srgrimes 5101541Srgrimes/* 511170613Sbms * Modified argument structure for IP_MULTICAST_IF, obtained from Linux. 512170613Sbms * This is used to specify an interface index for multicast sends, as 513170613Sbms * the IPv4 legacy APIs do not support this (unless IP_SENDIF is available). 514170613Sbms */ 515170613Sbmsstruct ip_mreqn { 516170613Sbms struct in_addr imr_multiaddr; /* IP multicast address of group */ 517170613Sbms struct in_addr imr_address; /* local IP address of interface */ 518170613Sbms int imr_ifindex; /* Interface index; cast to uint32_t */ 519170613Sbms}; 520170613Sbms 521170613Sbms/* 522170613Sbms * Argument structure for IPv4 Multicast Source Filter APIs. [RFC3678] 523170613Sbms */ 524170613Sbmsstruct ip_mreq_source { 525170613Sbms struct in_addr imr_multiaddr; /* IP multicast address of group */ 526170613Sbms struct in_addr imr_sourceaddr; /* IP address of source */ 527170613Sbms struct in_addr imr_interface; /* local IP address of interface */ 528170613Sbms}; 529170613Sbms 530170613Sbms/* 531170613Sbms * Argument structures for Protocol-Independent Multicast Source 532170613Sbms * Filter APIs. [RFC3678] 533170613Sbms */ 534170613Sbmsstruct group_req { 535170613Sbms uint32_t gr_interface; /* interface index */ 536170613Sbms struct sockaddr_storage gr_group; /* group address */ 537170613Sbms}; 538170613Sbms 539170613Sbmsstruct group_source_req { 540170613Sbms uint32_t gsr_interface; /* interface index */ 541170613Sbms struct sockaddr_storage gsr_group; /* group address */ 542170613Sbms struct sockaddr_storage gsr_source; /* source address */ 543170613Sbms}; 544170613Sbms 545170613Sbms#ifndef __MSFILTERREQ_DEFINED 546170613Sbms#define __MSFILTERREQ_DEFINED 547170613Sbms/* 548170613Sbms * The following structure is private; do not use it from user applications. 549170613Sbms * It is used to communicate IP_MSFILTER/IPV6_MSFILTER information between 550170613Sbms * the RFC 3678 libc functions and the kernel. 551170613Sbms */ 552170613Sbmsstruct __msfilterreq { 553170613Sbms uint32_t msfr_ifindex; /* interface index */ 554170613Sbms uint32_t msfr_fmode; /* filter mode for group */ 555170613Sbms uint32_t msfr_nsrcs; /* # of sources in msfr_srcs */ 556170613Sbms struct sockaddr_storage msfr_group; /* group address */ 557170613Sbms struct sockaddr_storage *msfr_srcs; /* pointer to the first member 558170613Sbms * of a contiguous array of 559170613Sbms * sources to filter in full. 560170613Sbms */ 561170613Sbms}; 562170613Sbms#endif 563170613Sbms 564170613Sbmsstruct sockaddr; 565170613Sbms 566170613Sbms/* 567170613Sbms * Advanced (Full-state) APIs [RFC3678] 568170613Sbms * The RFC specifies uint_t for the 6th argument to [sg]etsourcefilter(). 569170613Sbms * We use uint32_t here to be consistent. 570170613Sbms */ 571170613Sbmsint setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t, 572170613Sbms uint32_t, struct in_addr *); 573170613Sbmsint getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *, 574170613Sbms uint32_t *, struct in_addr *); 575170613Sbmsint setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, 576170613Sbms uint32_t, uint32_t, struct sockaddr_storage *); 577170613Sbmsint getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, 578170613Sbms uint32_t *, uint32_t *, struct sockaddr_storage *); 579170613Sbms 580170613Sbms/* 581170613Sbms * Filter modes; also used to represent per-socket filter mode internally. 582170613Sbms */ 583189346Sbms#define MCAST_UNDEFINED 0 /* fmode: not yet defined */ 584170613Sbms#define MCAST_INCLUDE 1 /* fmode: include these source(s) */ 585170613Sbms#define MCAST_EXCLUDE 2 /* fmode: exclude these source(s) */ 586170613Sbms 587170613Sbms/* 58814195Speter * Argument for IP_PORTRANGE: 58914195Speter * - which range to search when port is unspecified at bind() or connect() 59014195Speter */ 59114195Speter#define IP_PORTRANGE_DEFAULT 0 /* default range */ 59214195Speter#define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 59314195Speter#define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 59414195Speter 59514195Speter/* 5961541Srgrimes * Definitions for inet sysctl operations. 5971541Srgrimes * 5981541Srgrimes * Third level is protocol number. 5991541Srgrimes * Fourth level is desired variable within that protocol. 6001541Srgrimes */ 60162587Sitojun#define IPPROTO_MAXID (IPPROTO_AH + 1) /* don't list to IPPROTO_MAX */ 6021541Srgrimes 6031541Srgrimes#define CTL_IPPROTO_NAMES { \ 6041541Srgrimes { "ip", CTLTYPE_NODE }, \ 6051541Srgrimes { "icmp", CTLTYPE_NODE }, \ 6061541Srgrimes { "igmp", CTLTYPE_NODE }, \ 6071541Srgrimes { "ggp", CTLTYPE_NODE }, \ 6081541Srgrimes { 0, 0 }, \ 6091541Srgrimes { 0, 0 }, \ 6101541Srgrimes { "tcp", CTLTYPE_NODE }, \ 6111541Srgrimes { 0, 0 }, \ 6121541Srgrimes { "egp", CTLTYPE_NODE }, \ 6131541Srgrimes { 0, 0 }, \ 6141541Srgrimes { 0, 0 }, \ 6151541Srgrimes { 0, 0 }, \ 6161541Srgrimes { "pup", CTLTYPE_NODE }, \ 6171541Srgrimes { 0, 0 }, \ 6181541Srgrimes { 0, 0 }, \ 6191541Srgrimes { 0, 0 }, \ 6201541Srgrimes { 0, 0 }, \ 6211541Srgrimes { "udp", CTLTYPE_NODE }, \ 6221541Srgrimes { 0, 0 }, \ 6231541Srgrimes { 0, 0 }, \ 6241541Srgrimes { 0, 0 }, \ 6251541Srgrimes { 0, 0 }, \ 6261541Srgrimes { "idp", CTLTYPE_NODE }, \ 62762587Sitojun { 0, 0 }, \ 62862587Sitojun { 0, 0 }, \ 62962587Sitojun { 0, 0 }, \ 63062587Sitojun { 0, 0 }, \ 63162587Sitojun { 0, 0 }, \ 63262587Sitojun { 0, 0 }, \ 63362587Sitojun { 0, 0 }, \ 63462587Sitojun { 0, 0 }, \ 63562587Sitojun { 0, 0 }, \ 63662587Sitojun { 0, 0 }, \ 63762587Sitojun { 0, 0 }, \ 63862587Sitojun { 0, 0 }, \ 63962587Sitojun { 0, 0 }, \ 64062587Sitojun { 0, 0 }, \ 64162587Sitojun { 0, 0 }, \ 64262587Sitojun { 0, 0 }, \ 64362587Sitojun { 0, 0 }, \ 64462587Sitojun { 0, 0 }, \ 64562587Sitojun { 0, 0 }, \ 64662587Sitojun { 0, 0 }, \ 64762587Sitojun { 0, 0 }, \ 64862587Sitojun { 0, 0 }, \ 64962587Sitojun { 0, 0 }, \ 65062587Sitojun { 0, 0 }, \ 65162587Sitojun { 0, 0 }, \ 65262587Sitojun { 0, 0 }, \ 65362587Sitojun { 0, 0 }, \ 65462587Sitojun { 0, 0 }, \ 65562587Sitojun { "ipsec", CTLTYPE_NODE }, \ 656118622Shsu { 0, 0 }, \ 657118622Shsu { 0, 0 }, \ 658118622Shsu { 0, 0 }, \ 659118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 660118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 661118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 662118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 663118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 664118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 665118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 666118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 667118622Shsu { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 668118622Shsu { 0, 0 }, \ 669118622Shsu { 0, 0 }, \ 670118622Shsu { 0, 0 }, \ 671118622Shsu { "pim", CTLTYPE_NODE }, \ 6721541Srgrimes} 6731541Srgrimes 6741541Srgrimes/* 6751541Srgrimes * Names for IP sysctl objects 6761541Srgrimes */ 6771541Srgrimes#define IPCTL_FORWARDING 1 /* act as router */ 6781541Srgrimes#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 6791541Srgrimes#define IPCTL_DEFTTL 3 /* default TTL */ 6801541Srgrimes#ifdef notyet 6811541Srgrimes#define IPCTL_DEFMTU 4 /* default MTU */ 6821541Srgrimes#endif 683133874Srwatson#define IPCTL_RTEXPIRE 5 /* cloned route expiration time */ 684133874Srwatson#define IPCTL_RTMINEXPIRE 6 /* min value for expiration time */ 685133874Srwatson#define IPCTL_RTMAXCACHE 7 /* trigger level for dynamic expire */ 6867091Swollman#define IPCTL_SOURCEROUTE 8 /* may perform source routes */ 6879575Speter#define IPCTL_DIRECTEDBROADCAST 9 /* may re-broadcast received packets */ 688133874Srwatson#define IPCTL_INTRQMAXLEN 10 /* max length of netisr queue */ 68952904Sshin#define IPCTL_INTRQDROPS 11 /* number of netisr q drops */ 69029838Swollman#define IPCTL_STATS 12 /* ipstat structure */ 69133440Sguido#define IPCTL_ACCEPTSOURCEROUTE 13 /* may accept source routed packets */ 69252904Sshin#define IPCTL_FASTFORWARDING 14 /* use fast IP forwarding code */ 69355009Sshin#define IPCTL_KEEPFAITH 15 /* FAITH IPv4->IPv6 translater ctl */ 69452904Sshin#define IPCTL_GIF_TTL 16 /* default TTL for gif encap packet */ 69552904Sshin#define IPCTL_MAXID 17 6961541Srgrimes 6971541Srgrimes#define IPCTL_NAMES { \ 6981541Srgrimes { 0, 0 }, \ 6991541Srgrimes { "forwarding", CTLTYPE_INT }, \ 7001541Srgrimes { "redirect", CTLTYPE_INT }, \ 7011541Srgrimes { "ttl", CTLTYPE_INT }, \ 7021541Srgrimes { "mtu", CTLTYPE_INT }, \ 7035109Swollman { "rtexpire", CTLTYPE_INT }, \ 7046399Swollman { "rtminexpire", CTLTYPE_INT }, \ 7056399Swollman { "rtmaxcache", CTLTYPE_INT }, \ 7067091Swollman { "sourceroute", CTLTYPE_INT }, \ 707133874Srwatson { "directed-broadcast", CTLTYPE_INT }, \ 70812003Swollman { "intr-queue-maxlen", CTLTYPE_INT }, \ 70912003Swollman { "intr-queue-drops", CTLTYPE_INT }, \ 71029838Swollman { "stats", CTLTYPE_STRUCT }, \ 71133440Sguido { "accept_sourceroute", CTLTYPE_INT }, \ 71236192Sdg { "fastforwarding", CTLTYPE_INT }, \ 7131541Srgrimes} 7141541Srgrimes 71595336Smike#endif /* __BSD_VISIBLE */ 71695336Smike 71778243Speter#ifdef _KERNEL 71895336Smike 71978243Speterstruct ifnet; struct mbuf; /* forward declarations for Standard C */ 72078243Speter 72192723Salfredint in_broadcast(struct in_addr, struct ifnet *); 72292723Salfredint in_canforward(struct in_addr); 72392723Salfredint in_localaddr(struct in_addr); 724133486Sandreint in_localip(struct in_addr); 725199208Sattilioint inet_aton(const char *, struct in_addr *); /* in libkern */ 726133874Srwatsonchar *inet_ntoa(struct in_addr); /* in libkern */ 72792723Salfredchar *inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */ 728150296Srwatsonvoid in_ifdetach(struct ifnet *); 7292169Spaul 730133874Srwatson#define in_hosteq(s, t) ((s).s_addr == (t).s_addr) 731133874Srwatson#define in_nullhost(x) ((x).s_addr == INADDR_ANY) 732189346Sbms#define in_allhosts(x) ((x).s_addr == htonl(INADDR_ALLHOSTS_GROUP)) 733102925Ssobomax 734133874Srwatson#define satosin(sa) ((struct sockaddr_in *)(sa)) 735133874Srwatson#define sintosa(sin) ((struct sockaddr *)(sin)) 736133874Srwatson#define ifatoia(ifa) ((struct in_ifaddr *)(ifa)) 73784101Sjlemon 738201122Sluigi/* 739201122Sluigi * Historically, BSD keeps ip_len and ip_off in host format 740201122Sluigi * when doing layer 3 processing, and this often requires 741201122Sluigi * to translate the format back and forth. 742201122Sluigi * To make the process explicit, we define a couple of macros 743201122Sluigi * that also take into account the fact that at some point 744201122Sluigi * we may want to keep those fields always in net format. 745201122Sluigi */ 746201122Sluigi 747201122Sluigi#if (BYTE_ORDER == BIG_ENDIAN) || defined(HAVE_NET_IPLEN) 748201122Sluigi#define SET_NET_IPLEN(p) do {} while (0) 749201122Sluigi#define SET_HOST_IPLEN(p) do {} while (0) 750201122Sluigi#else 751201122Sluigi#define SET_NET_IPLEN(p) do { \ 752201122Sluigi struct ip *h_ip = (p); \ 753201122Sluigi h_ip->ip_len = htons(h_ip->ip_len); \ 754201122Sluigi h_ip->ip_off = htons(h_ip->ip_off); \ 755201122Sluigi } while (0) 756201122Sluigi 757201122Sluigi#define SET_HOST_IPLEN(p) do { \ 758201122Sluigi struct ip *h_ip = (p); \ 759201122Sluigi h_ip->ip_len = ntohs(h_ip->ip_len); \ 760201122Sluigi h_ip->ip_off = ntohs(h_ip->ip_off); \ 761201122Sluigi } while (0) 762201122Sluigi#endif /* !HAVE_NET_IPLEN */ 763201122Sluigi 76495336Smike#endif /* _KERNEL */ 76590868Smike 76695336Smike/* INET6 stuff */ 76795336Smike#if __POSIX_VISIBLE >= 200112 76895336Smike#define __KAME_NETINET_IN_H_INCLUDED_ 76995336Smike#include <netinet6/in6.h> 77095336Smike#undef __KAME_NETINET_IN_H_INCLUDED_ 77191959Smike#endif 77291959Smike 77395336Smike#endif /* !_NETINET_IN_H_*/ 774