123176Smckusick /* 265349Sbostic * Copyright (c) 1982, 1986, 1990, 1993 363218Sbostic * The Regents of the University of California. All rights reserved. 423176Smckusick * 544473Sbostic * %sccs.include.redist.c% 632787Sbostic * 7*65350Sbostic * @(#)in.h 8.3 (Berkeley) 01/03/94 823176Smckusick */ 94793Swnj 104793Swnj /* 114793Swnj * Constants and structures defined by the internet system, 12*65350Sbostic * Per RFC 790, September 1981, and numerous additions. 134793Swnj */ 144793Swnj 154793Swnj /* 164793Swnj * Protocols 174793Swnj */ 1824230Skarels #define IPPROTO_IP 0 /* dummy for IP */ 194793Swnj #define IPPROTO_ICMP 1 /* control message protocol */ 2054716Ssklower #define IPPROTO_IGMP 2 /* group mgmt protocol */ 2133517Skarels #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 224793Swnj #define IPPROTO_TCP 6 /* tcp */ 2316797Skarels #define IPPROTO_EGP 8 /* exterior gateway protocol */ 244793Swnj #define IPPROTO_PUP 12 /* pup */ 254793Swnj #define IPPROTO_UDP 17 /* user datagram protocol */ 2624230Skarels #define IPPROTO_IDP 22 /* xns idp */ 2737471Ssklower #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 2837471Ssklower #define IPPROTO_EON 80 /* ISO cnlp */ 2957417Sandrew #define IPPROTO_ENCAP 98 /* encapsulation header */ 304793Swnj 315611Swnj #define IPPROTO_RAW 255 /* raw IP packet */ 324897Swnj #define IPPROTO_MAX 256 334897Swnj 344793Swnj 354793Swnj /* 3644367Skarels * Local port number conventions: 376229Sroot * Ports < IPPORT_RESERVED are reserved for 386229Sroot * privileged processes (e.g. root). 3926025Skarels * Ports > IPPORT_USERRESERVED are reserved 4026025Skarels * for servers, not necessarily privileged. 416229Sroot */ 425994Swnj #define IPPORT_RESERVED 1024 4326025Skarels #define IPPORT_USERRESERVED 5000 445994Swnj 454793Swnj /* 4618371Skarels * Internet address (a structure for historical reasons) 474793Swnj */ 484922Swnj struct in_addr { 4918371Skarels u_long s_addr; 504793Swnj }; 514922Swnj 527034Swnj /* 538595Sroot * Definitions of bits in internet address integers. 5423556Skarels * On subnets, the decomposition of addresses to host and net parts 5523556Skarels * is done according to subnet mask, not the masks here. 567034Swnj */ 5726382Skarels #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 588595Sroot #define IN_CLASSA_NET 0xff000000 598595Sroot #define IN_CLASSA_NSHIFT 24 608595Sroot #define IN_CLASSA_HOST 0x00ffffff 6116378Skarels #define IN_CLASSA_MAX 128 628595Sroot 6326382Skarels #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 648595Sroot #define IN_CLASSB_NET 0xffff0000 658595Sroot #define IN_CLASSB_NSHIFT 16 668595Sroot #define IN_CLASSB_HOST 0x0000ffff 6716378Skarels #define IN_CLASSB_MAX 65536 688595Sroot 6931392Skarels #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 708595Sroot #define IN_CLASSC_NET 0xffffff00 718595Sroot #define IN_CLASSC_NSHIFT 8 728595Sroot #define IN_CLASSC_HOST 0x000000ff 737034Swnj 7431392Skarels #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 7554716Ssklower #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 7654716Ssklower #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 7754716Ssklower #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 7831392Skarels #define IN_MULTICAST(i) IN_CLASSD(i) 7931392Skarels 8057417Sandrew #define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000) 8131392Skarels #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 8231392Skarels 8326382Skarels #define INADDR_ANY (u_long)0x00000000 8426382Skarels #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 8530404Skarels #ifndef KERNEL 8630404Skarels #define INADDR_NONE 0xffffffff /* -1 return */ 8730404Skarels #endif 885994Swnj 89*65350Sbostic #define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ 90*65350Sbostic #define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ 91*65350Sbostic #define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ 9254716Ssklower 9331392Skarels #define IN_LOOPBACKNET 127 /* official! */ 9431392Skarels 954922Swnj /* 964922Swnj * Socket address, internet style. 974922Swnj */ 984922Swnj struct sockaddr_in { 9937471Ssklower u_char sin_len; 10037471Ssklower u_char sin_family; 1014922Swnj u_short sin_port; 1024922Swnj struct in_addr sin_addr; 1034922Swnj char sin_zero[8]; 1044922Swnj }; 1058970Sroot 10624230Skarels /* 10744367Skarels * Structure used to describe IP options. 10844367Skarels * Used to store options internally, to pass them to a process, 10944367Skarels * or to restore options retrieved earlier. 11044367Skarels * The ip_dst is used for the first-hop gateway when using a source route 11144367Skarels * (this gets put into the header proper). 11244367Skarels */ 11344367Skarels struct ip_opts { 11444367Skarels struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 11544367Skarels char ip_opts[40]; /* actually variable in size */ 11644367Skarels }; 11744367Skarels 11844367Skarels /* 11924230Skarels * Options for use with [gs]etsockopt at the IP level. 12044367Skarels * First word of comment is data type; bool is stored in int. 12124230Skarels */ 122*65350Sbostic #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 123*65350Sbostic #define IP_HDRINCL 2 /* int; header is included with data */ 124*65350Sbostic #define IP_TOS 3 /* int; IP type of service and preced. */ 125*65350Sbostic #define IP_TTL 4 /* int; IP time to live */ 126*65350Sbostic #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 127*65350Sbostic #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 128*65350Sbostic #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 129*65350Sbostic #define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 130*65350Sbostic #define IP_MULTICAST_IF 9 /* u_char; set/get IP multicast i/f */ 131*65350Sbostic #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 132*65350Sbostic #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 133*65350Sbostic #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 134*65350Sbostic #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 13524230Skarels 136*65350Sbostic /* 137*65350Sbostic * Defaults and limits for options 138*65350Sbostic */ 139*65350Sbostic #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 140*65350Sbostic #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 141*65350Sbostic #define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */ 14254716Ssklower 14354716Ssklower /* 14454716Ssklower * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 14554716Ssklower */ 14654716Ssklower struct ip_mreq { 147*65350Sbostic struct in_addr imr_multiaddr; /* IP multicast address of group */ 148*65350Sbostic struct in_addr imr_interface; /* local IP address of interface */ 14954716Ssklower }; 15054716Ssklower 15159126Smckusick /* 15259126Smckusick * Definitions for inet sysctl operations. 15359126Smckusick * 15459126Smckusick * Third level is protocol number. 15559126Smckusick * Fourth level is desired variable within that protocol. 15659126Smckusick */ 157*65350Sbostic #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ 15859126Smckusick 159*65350Sbostic #define CTL_IPPROTO_NAMES { \ 16059126Smckusick { "ip", CTLTYPE_NODE }, \ 16159126Smckusick { "icmp", CTLTYPE_NODE }, \ 16259126Smckusick { "igmp", CTLTYPE_NODE }, \ 16359126Smckusick { "ggp", CTLTYPE_NODE }, \ 16459126Smckusick { 0, 0 }, \ 16559126Smckusick { 0, 0 }, \ 16659126Smckusick { "tcp", CTLTYPE_NODE }, \ 16759126Smckusick { 0, 0 }, \ 16859126Smckusick { "egp", CTLTYPE_NODE }, \ 16959126Smckusick { 0, 0 }, \ 17059126Smckusick { 0, 0 }, \ 17159126Smckusick { 0, 0 }, \ 17259126Smckusick { "pup", CTLTYPE_NODE }, \ 17359126Smckusick { 0, 0 }, \ 17459126Smckusick { 0, 0 }, \ 17559126Smckusick { 0, 0 }, \ 17659126Smckusick { 0, 0 }, \ 17759126Smckusick { "udp", CTLTYPE_NODE }, \ 17859126Smckusick { 0, 0 }, \ 17959126Smckusick { 0, 0 }, \ 18059126Smckusick { 0, 0 }, \ 18159126Smckusick { 0, 0 }, \ 18259126Smckusick { "idp", CTLTYPE_NODE }, \ 18359126Smckusick } 18459126Smckusick 18559126Smckusick /* 18659126Smckusick * Names for IP sysctl objects 18759126Smckusick */ 18859126Smckusick #define IPCTL_FORWARDING 1 /* act as router */ 18959126Smckusick #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 19059126Smckusick #define IPCTL_DEFTTL 3 /* default TTL */ 19159126Smckusick #ifdef notyet 19259126Smckusick #define IPCTL_DEFMTU 4 /* default MTU */ 19359126Smckusick #endif 19459126Smckusick #define IPCTL_MAXID 5 19559126Smckusick 19659126Smckusick #define IPCTL_NAMES { \ 19759126Smckusick { 0, 0 }, \ 19859126Smckusick { "forwarding", CTLTYPE_INT }, \ 19959126Smckusick { "redirect", CTLTYPE_INT }, \ 20059126Smckusick { "ttl", CTLTYPE_INT }, \ 20159126Smckusick { "mtu", CTLTYPE_INT }, \ 20259126Smckusick } 20359126Smckusick 20459126Smckusick 2059029Sroot #ifdef KERNEL 20661335Sbostic int in_broadcast __P((struct in_addr, struct ifnet *)); 20761335Sbostic int in_canforward __P((struct in_addr)); 20861335Sbostic int in_cksum __P((struct mbuf *, int)); 20961335Sbostic int in_localaddr __P((struct in_addr)); 21061335Sbostic u_long in_netof __P((struct in_addr)); 21161335Sbostic void in_socktrim __P((struct sockaddr_in *)); 2129029Sroot #endif 213