1 /* 2 * Copyright (c) 1982, 1986, 1990 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)in.h 7.12 (Berkeley) 07/06/92 8 */ 9 10 /* 11 * Constants and structures defined by the internet system, 12 * Per RFC 790, September 1981. 13 */ 14 15 /* 16 * Protocols 17 */ 18 #define IPPROTO_IP 0 /* dummy for IP */ 19 #define IPPROTO_ICMP 1 /* control message protocol */ 20 #define IPPROTO_IGMP 2 /* group mgmt protocol */ 21 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 22 #define IPPROTO_TCP 6 /* tcp */ 23 #define IPPROTO_EGP 8 /* exterior gateway protocol */ 24 #define IPPROTO_PUP 12 /* pup */ 25 #define IPPROTO_UDP 17 /* user datagram protocol */ 26 #define IPPROTO_IDP 22 /* xns idp */ 27 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 28 #define IPPROTO_EON 80 /* ISO cnlp */ 29 30 #define IPPROTO_RAW 255 /* raw IP packet */ 31 #define IPPROTO_MAX 256 32 33 34 /* 35 * Local port number conventions: 36 * Ports < IPPORT_RESERVED are reserved for 37 * privileged processes (e.g. root). 38 * Ports > IPPORT_USERRESERVED are reserved 39 * for servers, not necessarily privileged. 40 */ 41 #define IPPORT_RESERVED 1024 42 #define IPPORT_USERRESERVED 5000 43 44 /* 45 * Internet address (a structure for historical reasons) 46 */ 47 struct in_addr { 48 u_long s_addr; 49 }; 50 51 /* 52 * Definitions of bits in internet address integers. 53 * On subnets, the decomposition of addresses to host and net parts 54 * is done according to subnet mask, not the masks here. 55 */ 56 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 57 #define IN_CLASSA_NET 0xff000000 58 #define IN_CLASSA_NSHIFT 24 59 #define IN_CLASSA_HOST 0x00ffffff 60 #define IN_CLASSA_MAX 128 61 62 #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 63 #define IN_CLASSB_NET 0xffff0000 64 #define IN_CLASSB_NSHIFT 16 65 #define IN_CLASSB_HOST 0x0000ffff 66 #define IN_CLASSB_MAX 65536 67 68 #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 69 #define IN_CLASSC_NET 0xffffff00 70 #define IN_CLASSC_NSHIFT 8 71 #define IN_CLASSC_HOST 0x000000ff 72 73 #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 74 #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 75 #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 76 #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 77 #define IN_MULTICAST(i) IN_CLASSD(i) 78 79 #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000) 80 #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 81 82 #define INADDR_ANY (u_long)0x00000000 83 #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 84 #ifndef KERNEL 85 #define INADDR_NONE 0xffffffff /* -1 return */ 86 #endif 87 88 #define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ 89 #define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ 90 #define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ 91 92 #define IN_LOOPBACKNET 127 /* official! */ 93 94 /* 95 * Socket address, internet style. 96 */ 97 struct sockaddr_in { 98 u_char sin_len; 99 u_char sin_family; 100 u_short sin_port; 101 struct in_addr sin_addr; 102 char sin_zero[8]; 103 }; 104 105 /* 106 * Structure used to describe IP options. 107 * Used to store options internally, to pass them to a process, 108 * or to restore options retrieved earlier. 109 * The ip_dst is used for the first-hop gateway when using a source route 110 * (this gets put into the header proper). 111 */ 112 struct ip_opts { 113 struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 114 char ip_opts[40]; /* actually variable in size */ 115 }; 116 117 /* 118 * Options for use with [gs]etsockopt at the IP level. 119 * First word of comment is data type; bool is stored in int. 120 */ 121 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */ 122 123 #define IP_MULTICAST_IF 2 /* set/get IP multicast interface */ 124 #define IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */ 125 #define IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */ 126 #define IP_ADD_MEMBERSHIP 5 /* add an IP group membership */ 127 #define IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */ 128 129 #define IP_HDRINCL 7 /* int; header is included with data (raw) */ 130 #define IP_TOS 8 /* int; IP type of service and precedence */ 131 #define IP_TTL 9 /* int; IP time to live */ 132 #define IP_RECVOPTS 10 /* bool; receive all IP options w/datagram */ 133 #define IP_RECVRETOPTS 11 /* bool; receive IP options for response */ 134 #define IP_RECVDSTADDR 12 /* bool; receive IP dst addr w/datagram */ 135 #define IP_RETOPTS 13 /* ip_opts; set/get IP per-packet options */ 136 137 #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 138 #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 139 #define IP_MAX_MEMBERSHIPS 20 /* per socket */ 140 141 /* 142 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 143 */ 144 struct ip_mreq { 145 struct in_addr imr_multiaddr; /* IP multicast address of group */ 146 struct in_addr imr_interface; /* local IP address of interface */ 147 }; 148 149 #ifdef KERNEL 150 struct in_addr in_makeaddr(); 151 u_long in_netof(), in_lnaof(); 152 #endif 153