00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef _NETINET_IN_H_
00043 #define _NETINET_IN_H_
00044
00045 extern uint32_t htonl(uint32_t hostlong);
00046
00047 extern uint16_t htons(uint16_t hostshort);
00048
00049 extern uint32_t ntohl(uint32_t netlong);
00050
00051 extern uint16_t ntohs(uint16_t netshort);
00052
00053
00054
00055
00056 #define IPPROTO_IP 0
00057 #define IPPROTO_ICMP 1
00058 #define IPPROTO_IGMP 2
00059 #define IPPROTO_GGP 3
00060 #define IPPROTO_IPIP 4
00061 #define IPPROTO_TCP 6
00062 #define IPPROTO_EGP 8
00063 #define IPPROTO_PUP 12
00064 #define IPPROTO_UDP 17
00065 #define IPPROTO_IDP 22
00066 #define IPPROTO_TP 29
00067 #define IPPROTO_ESP 50
00068 #define IPPROTO_AH 51
00069 #define IPPROTO_EON 80
00070 #define IPPROTO_ENCAP 98
00071
00072 #define IPPROTO_RAW 255
00073 #define IPPROTO_MAX 256
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #define IPPORT_RESERVED 1024
00105 #define IPPORT_ANONMIN 49152
00106 #define IPPORT_ANONMAX 65535
00107 #define IPPORT_RESERVEDMIN 600
00108 #define IPPORT_RESERVEDMAX (IPPORT_RESERVED-1)
00109
00110
00111
00112
00113 typedef uint32_t in_addr_t;
00114 struct in_addr {
00115 in_addr_t s_addr;
00116 };
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 #ifdef _KERNEL
00128 #define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x)))
00129 #else
00130 #define __IPADDR(x) ((u_int32_t)(x))
00131 #endif
00132
00133 #define IN_CLASSA(i) (((u_int32_t)(i) & __IPADDR(0x80000000)) == \
00134 __IPADDR(0x00000000))
00135 #define IN_CLASSA_NET __IPADDR(0xff000000)
00136 #define IN_CLASSA_NSHIFT 24
00137 #define IN_CLASSA_HOST __IPADDR(0x00ffffff)
00138 #define IN_CLASSA_MAX 128
00139
00140 #define IN_CLASSB(i) (((u_int32_t)(i) & __IPADDR(0xc0000000)) == \
00141 __IPADDR(0x80000000))
00142 #define IN_CLASSB_NET __IPADDR(0xffff0000)
00143 #define IN_CLASSB_NSHIFT 16
00144 #define IN_CLASSB_HOST __IPADDR(0x0000ffff)
00145 #define IN_CLASSB_MAX 65536
00146
00147 #define IN_CLASSC(i) (((u_int32_t)(i) & __IPADDR(0xe0000000)) == \
00148 __IPADDR(0xc0000000))
00149 #define IN_CLASSC_NET __IPADDR(0xffffff00)
00150 #define IN_CLASSC_NSHIFT 8
00151 #define IN_CLASSC_HOST __IPADDR(0x000000ff)
00152
00153 #define IN_CLASSD(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \
00154 __IPADDR(0xe0000000))
00155
00156 #define IN_CLASSD_NET __IPADDR(0xf0000000)
00157 #define IN_CLASSD_NSHIFT 28
00158 #define IN_CLASSD_HOST __IPADDR(0x0fffffff)
00159 #define IN_MULTICAST(i) IN_CLASSD(i)
00160
00161 #define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \
00162 __IPADDR(0xf0000000))
00163 #define IN_BADCLASS(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \
00164 __IPADDR(0xf0000000))
00165
00166 #define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & __IPADDR(0xffffff00)) == \
00167 __IPADDR(0xe0000000))
00168
00169 #define INADDR_ANY __IPADDR(0x00000000)
00170 #define INADDR_LOOPBACK __IPADDR(0x7f000001)
00171 #define INADDR_BROADCAST __IPADDR(0xffffffff)
00172 #ifndef _KERNEL
00173 #define INADDR_NONE __IPADDR(0xffffffff)
00174 #endif
00175
00176 #define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000)
00177 #define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001)
00178 #define INADDR_ALLRTRS_GROUP __IPADDR(0xe0000002)
00179 #define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff)
00180
00181 #define IN_LOOPBACKNET 127
00182
00183
00184
00185
00186 struct sockaddr_in {
00187 u_int8_t sin_len;
00188 u_int8_t sin_family;
00189 u_int16_t sin_port;
00190 struct in_addr sin_addr;
00191 int8_t sin_zero[8];
00192 };
00193
00194
00195
00196
00197
00198
00199
00200
00201 struct ip_opts {
00202 struct in_addr ip_dst;
00203 int8_t ip_opts[40];
00204 };
00205
00206
00207
00208
00209
00210 #define IP_OPTIONS 1
00211 #define IP_HDRINCL 2
00212 #define IP_TOS 3
00213 #define IP_TTL 4
00214 #define IP_RECVOPTS 5
00215 #define IP_RECVRETOPTS 6
00216 #define IP_RECVDSTADDR 7
00217 #define IP_RETOPTS 8
00218 #define IP_MULTICAST_IF 9
00219 #define IP_MULTICAST_TTL 10
00220 #define IP_MULTICAST_LOOP 11
00221 #define IP_ADD_MEMBERSHIP 12
00222 #define IP_DROP_MEMBERSHIP 13
00223 #define IP_PORTRANGE 19
00224 #define IP_RECVIF 20
00225 #define IP_ERRORMTU 21
00226
00227
00228
00229
00230 #define IP_DEFAULT_MULTICAST_TTL 1
00231 #define IP_DEFAULT_MULTICAST_LOOP 1
00232 #define IP_MAX_MEMBERSHIPS 20
00233
00234
00235
00236
00237 struct ip_mreq {
00238 struct in_addr imr_multiaddr;
00239 struct in_addr imr_interface;
00240 };
00241
00242
00243
00244
00245
00246 #define IP_PORTRANGE_DEFAULT 0
00247 #define IP_PORTRANGE_HIGH 1
00248 #define IP_PORTRANGE_LOW 2
00249
00250
00251
00252
00253
00254
00255
00256 #define IPPROTO_MAXID (IPPROTO_IDP + 1)
00257
00258 #define CTL_IPPROTO_NAMES { \
00259 { "ip", CTLTYPE_NODE }, \
00260 { "icmp", CTLTYPE_NODE }, \
00261 { "igmp", CTLTYPE_NODE }, \
00262 { "ggp", CTLTYPE_NODE }, \
00263 { 0, 0 }, \
00264 { 0, 0 }, \
00265 { "tcp", CTLTYPE_NODE }, \
00266 { 0, 0 }, \
00267 { "egp", CTLTYPE_NODE }, \
00268 { 0, 0 }, \
00269 { 0, 0 }, \
00270 { 0, 0 }, \
00271 { "pup", CTLTYPE_NODE }, \
00272 { 0, 0 }, \
00273 { 0, 0 }, \
00274 { 0, 0 }, \
00275 { 0, 0 }, \
00276 { "udp", CTLTYPE_NODE }, \
00277 { 0, 0 }, \
00278 { 0, 0 }, \
00279 { 0, 0 }, \
00280 { 0, 0 }, \
00281 { "idp", CTLTYPE_NODE }, \
00282 }
00283
00284
00285
00286
00287 #define IPCTL_FORWARDING 1
00288 #define IPCTL_SENDREDIRECTS 2
00289 #define IPCTL_DEFTTL 3
00290 #ifdef notyet
00291 #define IPCTL_DEFMTU 4
00292 #endif
00293 #define IPCTL_FORWSRCRT 5
00294 #define IPCTL_DIRECTEDBCAST 6
00295 #define IPCTL_ALLOWSRCRT 7
00296 #define IPCTL_SUBNETSARELOCAL 8
00297 #define IPCTL_MTUDISC 9
00298 #define IPCTL_ANONPORTMIN 10
00299 #define IPCTL_ANONPORTMAX 11
00300 #define IPCTL_MTUDISCTIMEOUT 12
00301 #define IPCTL_MAXFLOWS 13
00302 #define IPCTL_MAXID 14
00303
00304 #define IPCTL_NAMES { \
00305 { 0, 0 }, \
00306 { "forwarding", CTLTYPE_INT }, \
00307 { "redirect", CTLTYPE_INT }, \
00308 { "ttl", CTLTYPE_INT }, \
00309 { "mtu", CTLTYPE_INT }, \
00310 { "forwsrcrt", CTLTYPE_INT }, \
00311 { "directed-broadcast", CTLTYPE_INT }, \
00312 { "allowsrcrt", CTLTYPE_INT }, \
00313 { "subnetsarelocal", CTLTYPE_INT }, \
00314 { "mtudisc", CTLTYPE_INT }, \
00315 { "anonportmin", CTLTYPE_INT }, \
00316 { "anonportmax", CTLTYPE_INT }, \
00317 { "mtudisctimeout", CTLTYPE_INT }, \
00318 { "maxflows", CTLTYPE_INT }, \
00319 }
00320
00321
00322 #ifdef _KERNEL
00323 extern struct in_addr zeroin_addr;
00324
00325 int in_broadcast __P((struct in_addr, struct ifnet *));
00326 int in_canforward __P((struct in_addr));
00327 int in_cksum __P((struct mbuf *, int));
00328 int in_localaddr __P((struct in_addr));
00329 void in_socktrim __P((struct sockaddr_in *));
00330
00331 #define in_hosteq(s,t) ((s).s_addr == (t).s_addr)
00332 #define in_nullhost(x) ((x).s_addr == INADDR_ANY)
00333
00334 #define satosin(sa) ((struct sockaddr_in *)(sa))
00335 #define sintosa(sin) ((struct sockaddr *)(sin))
00336 #define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
00337 #endif
00338
00339 #endif