Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
51c74ceb | 2 | * Copyright (c) 1982,1986,1990,1993 Regents of the University of California. |
2b6b6284 | 3 | * All rights reserved. |
8ae0e4b4 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
2b6b6284 | 6 | * |
51c74ceb | 7 | * @(#)in.h 7.14 (Berkeley) %G% |
8ae0e4b4 | 8 | */ |
8958351e BJ |
9 | |
10 | /* | |
11 | * Constants and structures defined by the internet system, | |
12 | * Per RFC 790, September 1981. | |
13 | */ | |
14 | ||
15 | /* | |
16 | * Protocols | |
17 | */ | |
55f549b4 | 18 | #define IPPROTO_IP 0 /* dummy for IP */ |
8958351e | 19 | #define IPPROTO_ICMP 1 /* control message protocol */ |
d6fa15c2 | 20 | #define IPPROTO_IGMP 2 /* group mgmt protocol */ |
8114dc67 | 21 | #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ |
8958351e | 22 | #define IPPROTO_TCP 6 /* tcp */ |
c49e68cc | 23 | #define IPPROTO_EGP 8 /* exterior gateway protocol */ |
8958351e BJ |
24 | #define IPPROTO_PUP 12 /* pup */ |
25 | #define IPPROTO_UDP 17 /* user datagram protocol */ | |
55f549b4 | 26 | #define IPPROTO_IDP 22 /* xns idp */ |
b4dc7708 KS |
27 | #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ |
28 | #define IPPROTO_EON 80 /* ISO cnlp */ | |
e0d32d4f | 29 | #define IPPROTO_ENCAP 98 /* encapsulation header */ |
8958351e | 30 | |
13ab51b7 | 31 | #define IPPROTO_RAW 255 /* raw IP packet */ |
eb44bfb2 BJ |
32 | #define IPPROTO_MAX 256 |
33 | ||
becdab37 BJ |
34 | |
35 | /* | |
bab61b5b | 36 | * Local port number conventions: |
becdab37 BJ |
37 | * Ports < IPPORT_RESERVED are reserved for |
38 | * privileged processes (e.g. root). | |
f44e5691 MK |
39 | * Ports > IPPORT_USERRESERVED are reserved |
40 | * for servers, not necessarily privileged. | |
becdab37 | 41 | */ |
1aa87517 | 42 | #define IPPORT_RESERVED 1024 |
f44e5691 | 43 | #define IPPORT_USERRESERVED 5000 |
1aa87517 | 44 | |
8958351e | 45 | /* |
e4dfb782 | 46 | * Internet address (a structure for historical reasons) |
8958351e | 47 | */ |
2b4b57cd | 48 | struct in_addr { |
e4dfb782 | 49 | u_long s_addr; |
8958351e | 50 | }; |
2b4b57cd | 51 | |
ae34128e | 52 | /* |
a8d3bf7f | 53 | * Definitions of bits in internet address integers. |
14c6a3d7 MK |
54 | * On subnets, the decomposition of addresses to host and net parts |
55 | * is done according to subnet mask, not the masks here. | |
ae34128e | 56 | */ |
8011f5df | 57 | #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) |
a8d3bf7f BJ |
58 | #define IN_CLASSA_NET 0xff000000 |
59 | #define IN_CLASSA_NSHIFT 24 | |
60 | #define IN_CLASSA_HOST 0x00ffffff | |
3adde5ac | 61 | #define IN_CLASSA_MAX 128 |
a8d3bf7f | 62 | |
8011f5df | 63 | #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) |
a8d3bf7f BJ |
64 | #define IN_CLASSB_NET 0xffff0000 |
65 | #define IN_CLASSB_NSHIFT 16 | |
66 | #define IN_CLASSB_HOST 0x0000ffff | |
3adde5ac | 67 | #define IN_CLASSB_MAX 65536 |
ae34128e | 68 | |
b4f9e9c7 | 69 | #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) |
a8d3bf7f BJ |
70 | #define IN_CLASSC_NET 0xffffff00 |
71 | #define IN_CLASSC_NSHIFT 8 | |
72 | #define IN_CLASSC_HOST 0x000000ff | |
ae34128e | 73 | |
b4f9e9c7 | 74 | #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) |
d6fa15c2 KS |
75 | #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ |
76 | #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ | |
77 | #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ | |
b4f9e9c7 MK |
78 | #define IN_MULTICAST(i) IN_CLASSD(i) |
79 | ||
e0d32d4f | 80 | #define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000) |
b4f9e9c7 MK |
81 | #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) |
82 | ||
8011f5df MK |
83 | #define INADDR_ANY (u_long)0x00000000 |
84 | #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ | |
b410e761 MK |
85 | #ifndef KERNEL |
86 | #define INADDR_NONE 0xffffffff /* -1 return */ | |
87 | #endif | |
3adde5ac | 88 | |
d6fa15c2 KS |
89 | #define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ |
90 | #define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ | |
91 | #define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ | |
92 | ||
b4f9e9c7 MK |
93 | #define IN_LOOPBACKNET 127 /* official! */ |
94 | ||
2b4b57cd BJ |
95 | /* |
96 | * Socket address, internet style. | |
97 | */ | |
98 | struct sockaddr_in { | |
b4dc7708 KS |
99 | u_char sin_len; |
100 | u_char sin_family; | |
2b4b57cd BJ |
101 | u_short sin_port; |
102 | struct in_addr sin_addr; | |
103 | char sin_zero[8]; | |
104 | }; | |
eb2e4af9 | 105 | |
bab61b5b MK |
106 | /* |
107 | * Structure used to describe IP options. | |
108 | * Used to store options internally, to pass them to a process, | |
109 | * or to restore options retrieved earlier. | |
110 | * The ip_dst is used for the first-hop gateway when using a source route | |
111 | * (this gets put into the header proper). | |
112 | */ | |
113 | struct ip_opts { | |
114 | struct in_addr ip_dst; /* first hop, 0 w/o src rt */ | |
115 | char ip_opts[40]; /* actually variable in size */ | |
116 | }; | |
117 | ||
55f549b4 MK |
118 | /* |
119 | * Options for use with [gs]etsockopt at the IP level. | |
bab61b5b | 120 | * First word of comment is data type; bool is stored in int. |
55f549b4 | 121 | */ |
bab61b5b | 122 | #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */ |
d6fa15c2 | 123 | |
e0d32d4f AC |
124 | #define IP_MULTICAST_IF 2 /* in_addr; set/get IP multicast interface */ |
125 | #define IP_MULTICAST_TTL 3 /* u_char; set/get IP multicast timetolive */ | |
126 | #define IP_MULTICAST_LOOP 4 /* u_char; set/get IP multicast loopback */ | |
127 | #define IP_ADD_MEMBERSHIP 5 /* ip_mreq; add an IP group membership */ | |
128 | #define IP_DROP_MEMBERSHIP 6 /* ip_mreq; drop an IP group membership */ | |
129 | ||
d6fa15c2 KS |
130 | |
131 | #define IP_HDRINCL 7 /* int; header is included with data (raw) */ | |
132 | #define IP_TOS 8 /* int; IP type of service and precedence */ | |
133 | #define IP_TTL 9 /* int; IP time to live */ | |
134 | #define IP_RECVOPTS 10 /* bool; receive all IP options w/datagram */ | |
135 | #define IP_RECVRETOPTS 11 /* bool; receive IP options for response */ | |
136 | #define IP_RECVDSTADDR 12 /* bool; receive IP dst addr w/datagram */ | |
137 | #define IP_RETOPTS 13 /* ip_opts; set/get IP per-packet options */ | |
138 | ||
139 | #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ | |
140 | #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ | |
141 | #define IP_MAX_MEMBERSHIPS 20 /* per socket */ | |
142 | ||
143 | /* | |
144 | * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. | |
145 | */ | |
146 | struct ip_mreq { | |
147 | struct in_addr imr_multiaddr; /* IP multicast address of group */ | |
148 | struct in_addr imr_interface; /* local IP address of interface */ | |
149 | }; | |
55f549b4 | 150 | |
51c74ceb KM |
151 | /* |
152 | * Definitions for inet sysctl operations. | |
153 | * | |
154 | * Third level is protocol number. | |
155 | * Fourth level is desired variable within that protocol. | |
156 | */ | |
157 | #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ | |
158 | ||
159 | #define CTL_IPPROTO_NAMES { \ | |
160 | { "ip", CTLTYPE_NODE }, \ | |
161 | { "icmp", CTLTYPE_NODE }, \ | |
162 | { "igmp", CTLTYPE_NODE }, \ | |
163 | { "ggp", CTLTYPE_NODE }, \ | |
164 | { 0, 0 }, \ | |
165 | { 0, 0 }, \ | |
166 | { "tcp", CTLTYPE_NODE }, \ | |
167 | { 0, 0 }, \ | |
168 | { "egp", CTLTYPE_NODE }, \ | |
169 | { 0, 0 }, \ | |
170 | { 0, 0 }, \ | |
171 | { 0, 0 }, \ | |
172 | { "pup", CTLTYPE_NODE }, \ | |
173 | { 0, 0 }, \ | |
174 | { 0, 0 }, \ | |
175 | { 0, 0 }, \ | |
176 | { 0, 0 }, \ | |
177 | { "udp", CTLTYPE_NODE }, \ | |
178 | { 0, 0 }, \ | |
179 | { 0, 0 }, \ | |
180 | { 0, 0 }, \ | |
181 | { 0, 0 }, \ | |
182 | { "idp", CTLTYPE_NODE }, \ | |
183 | } | |
184 | ||
185 | /* | |
186 | * Names for IP sysctl objects | |
187 | */ | |
188 | #define IPCTL_FORWARDING 1 /* act as router */ | |
189 | #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ | |
190 | #define IPCTL_DEFTTL 3 /* default TTL */ | |
191 | #ifdef notyet | |
192 | #define IPCTL_DEFMTU 4 /* default MTU */ | |
193 | #endif | |
194 | #define IPCTL_MAXID 5 | |
195 | ||
196 | #define IPCTL_NAMES { \ | |
197 | { 0, 0 }, \ | |
198 | { "forwarding", CTLTYPE_INT }, \ | |
199 | { "redirect", CTLTYPE_INT }, \ | |
200 | { "ttl", CTLTYPE_INT }, \ | |
201 | { "mtu", CTLTYPE_INT }, \ | |
202 | } | |
203 | ||
204 | ||
59965020 | 205 | #ifdef KERNEL |
e4dfb782 | 206 | struct in_addr in_makeaddr(); |
8011f5df | 207 | u_long in_netof(), in_lnaof(); |
59965020 | 208 | #endif |