xref: /haiku/headers/posix/netinet/ip.h (revision 5adca30a18617cc25bc50a9a12e2fe6539412ccb)
1 /* netinet/ip.h
2  * definitions for ipv4 protocol
3  */
4 
5 #ifndef _NETINET_IP_H
6 #define _NETINET_IP_H
7 
8 #include <netinet/in.h>
9 #include <stdint.h>
10 
11 /* Based on RFC 791 */
12 
13 #define IPVERSION 4
14 
15 struct ip {
16 #if 	BYTE_ORDER == BIG_ENDIAN
17 	uint8_t			ip_v:4;
18 	uint8_t			ip_hl:4;
19 #elif	BYTE_ORDER == LITTLE_ENDIAN
20 	uint8_t			ip_hl:4;
21 	uint8_t			ip_v:4;
22 #endif
23 	uint8_t			ip_tos;
24 	uint16_t		ip_len;
25 	uint16_t		ip_id;
26 	int16_t			ip_off;
27 	uint8_t			ip_ttl;
28 	uint8_t			ip_p;
29 	uint16_t		ip_sum;
30 	struct in_addr	ip_src;
31 	struct in_addr 	ip_dst;
32 } _PACKED;
33 
34 #define IP_MAXPACKET   65535/* Maximum packet size */
35 
36 /* IP Type of Service */
37 #define IPTOS_RELIABILITY   0x04
38 #define IPTOS_THROUGHPUT    0x08
39 #define IPTOS_LOWDELAY      0x10
40 
41 /*
42  * Definitions for options.
43  */
44 #define IPOPT_COPIED(o)((o)&0x80)
45 #define IPOPT_CLASS(o)((o)&0x60)
46 #define IPOPT_NUMBER(o)((o)&0x1f)
47 
48 #define IPOPT_CONTROL            0x00
49 #define IPOPT_RESERVED1          0x20
50 #define IPOPT_DEBMEAS            0x40
51 #define IPOPT_RESERVED2          0x60
52 
53 #define IPOPT_EOL                   0/* end of option list */
54 #define IPOPT_NOP                   1/* no operation */
55 
56 #define IPOPT_RR                    7/* record packet route */
57 #define IPOPT_TS                   68/* timestamp */
58 #define IPOPT_SECURITY            130/* provide s,c,h,tcc */
59 #define IPOPT_LSRR                131/* loose source route */
60 #define IPOPT_SATID               136/* satnet id */
61 #define IPOPT_SSRR                137/* strict source route */
62 
63 /*
64  * Offsets to fields in options other than EOL and NOP.
65  */
66 #define IPOPT_OPTVAL                0/* option ID */
67 #define IPOPT_OLEN                  1/* option length */
68 #define IPOPT_OFFSET                2/* offset within option */
69 #define IPOPT_MINOFF                4/* min value of above */
70 
71 struct  ip_timestamp {
72 	uint8_t	ipt_code;/* IPOPT_TS */
73 	uint8_t	ipt_len;/* size of structure (variable) */
74 	uint8_t	ipt_ptr;/* index of current entry */
75 #if 	BYTE_ORDER == BIG_ENDIAN
76 	uint8_t	ipt_oflw:4,
77 			ipt_flg:4;
78 #elif	BYTE_ORDER == LITTLE_ENDIAN
79 	uint8_t	ipt_flg:4,
80 			ipt_oflw:4;
81 #endif
82 	union ipt_timestamp {
83 		uint32_t ipt_time[1];
84 		struct ipt_ta {
85 			struct in_addr ipt_addr;
86 			uint32_t ipt_time;
87 		} ipt_ta;
88 	} ipt_timestamp;
89 };
90 
91 /* flag bits for ipt_flg */
92 #define IPOPT_TS_TSONLY      0/* timestamps only */
93 #define IPOPT_TS_TSANDADDR   1/* timestamps and addresses */
94 #define IPOPT_TS_PRESPEC     3/* specified modules only */
95 
96 /* bits for security (not byte swapped) */
97 #define IPOPT_SECUR_UNCLASS     0x0000
98 #define IPOPT_SECUR_CONFID      0xf135
99 #define IPOPT_SECUR_EFTO        0x789a
100 #define IPOPT_SECUR_MMMM        0xbc4d
101 #define IPOPT_SECUR_RESTR       0xaf13
102 #define IPOPT_SECUR_SECRET      0xd788
103 #define IPOPT_SECUR_TOPSECRET   0x6bc5
104 
105 #define MAXTTL                  255/* maximum time to live (seconds) */
106 #define IPDEFTTL                64/* default ttl, from RFC 1340 */
107 #define IPFRAGTTL               60/* time to live for frags, slowhz */
108 #define IPTTLDEC                1/* subtracted when forwarding */
109 
110 #define IP_MSS                  576/* default maximum segment size */
111 
112 struct ippseudo {
113 	struct    in_addr ippseudo_src; /* source internet address */
114 	struct    in_addr ippseudo_dst; /* destination internet address */
115 	uint8_t   ippseudo_pad;/* pad, must be zero */
116 	uint8_t   ippseudo_p;/* protocol */
117 	uint16_t  ippseudo_len;/* protocol length */
118 };
119 
120 /* Fragment flags */
121 #define IP_DF 0x4000        /* don't fragment */
122 #define IP_MF 0x2000        /* more fragments */
123 #define IP_OFFMASK 0x1fff
124 
125 #endif /* NETINET_IP_H */
126