1 #ifndef _NETINET_IP_H 2 #define _NETINET_IP_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <stdint.h> 9 #include <netinet/in.h> 10 11 struct timestamp { 12 uint8_t len; 13 uint8_t ptr; 14 #if __BYTE_ORDER == __LITTLE_ENDIAN 15 unsigned int flags:4; 16 unsigned int overflow:4; 17 #else 18 unsigned int overflow:4; 19 unsigned int flags:4; 20 #endif 21 uint32_t data[9]; 22 }; 23 24 struct iphdr { 25 #if __BYTE_ORDER == __LITTLE_ENDIAN 26 unsigned int ihl:4; 27 unsigned int version:4; 28 #else 29 unsigned int version:4; 30 unsigned int ihl:4; 31 #endif 32 uint8_t tos; 33 uint16_t tot_len; 34 uint16_t id; 35 uint16_t frag_off; 36 uint8_t ttl; 37 uint8_t protocol; 38 uint16_t check; 39 uint32_t saddr; 40 uint32_t daddr; 41 }; 42 43 struct ip { 44 #if __BYTE_ORDER == __LITTLE_ENDIAN 45 unsigned int ip_hl:4; 46 unsigned int ip_v:4; 47 #else 48 unsigned int ip_v:4; 49 unsigned int ip_hl:4; 50 #endif 51 uint8_t ip_tos; 52 uint16_t ip_len; 53 uint16_t ip_id; 54 uint16_t ip_off; 55 uint8_t ip_ttl; 56 uint8_t ip_p; 57 uint16_t ip_sum; 58 struct in_addr ip_src, ip_dst; 59 }; 60 61 #define IP_RF 0x8000 62 #define IP_DF 0x4000 63 #define IP_MF 0x2000 64 #define IP_OFFMASK 0x1fff 65 66 struct ip_timestamp { 67 uint8_t ipt_code; 68 uint8_t ipt_len; 69 uint8_t ipt_ptr; 70 #if __BYTE_ORDER == __LITTLE_ENDIAN 71 unsigned int ipt_flg:4; 72 unsigned int ipt_oflw:4; 73 #else 74 unsigned int ipt_oflw:4; 75 unsigned int ipt_flg:4; 76 #endif 77 uint32_t data[9]; 78 }; 79 80 #define IPVERSION 4 81 #define IP_MAXPACKET 65535 82 83 #define IPTOS_ECN_MASK 0x03 84 #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) 85 #define IPTOS_ECN_NOT_ECT 0x00 86 #define IPTOS_ECN_ECT1 0x01 87 #define IPTOS_ECN_ECT0 0x02 88 #define IPTOS_ECN_CE 0x03 89 90 #define IPTOS_DSCP_MASK 0xfc 91 #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) 92 #define IPTOS_DSCP_AF11 0x28 93 #define IPTOS_DSCP_AF12 0x30 94 #define IPTOS_DSCP_AF13 0x38 95 #define IPTOS_DSCP_AF21 0x48 96 #define IPTOS_DSCP_AF22 0x50 97 #define IPTOS_DSCP_AF23 0x58 98 #define IPTOS_DSCP_AF31 0x68 99 #define IPTOS_DSCP_AF32 0x70 100 #define IPTOS_DSCP_AF33 0x78 101 #define IPTOS_DSCP_AF41 0x88 102 #define IPTOS_DSCP_AF42 0x90 103 #define IPTOS_DSCP_AF43 0x98 104 #define IPTOS_DSCP_EF 0xb8 105 106 #define IPTOS_CLASS_MASK 0xe0 107 #define IPTOS_CLASS(x) ((x) & IPTOS_CLASS_MASK) 108 #define IPTOS_CLASS_CS0 0x00 109 #define IPTOS_CLASS_CS1 0x20 110 #define IPTOS_CLASS_CS2 0x40 111 #define IPTOS_CLASS_CS3 0x60 112 #define IPTOS_CLASS_CS4 0x80 113 #define IPTOS_CLASS_CS5 0xa0 114 #define IPTOS_CLASS_CS6 0xc0 115 #define IPTOS_CLASS_CS7 0xe0 116 #define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 117 118 #define IPTOS_TOS_MASK 0x1E 119 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) 120 #define IPTOS_LOWDELAY 0x10 121 #define IPTOS_THROUGHPUT 0x08 122 #define IPTOS_RELIABILITY 0x04 123 #define IPTOS_LOWCOST 0x02 124 #define IPTOS_MINCOST IPTOS_LOWCOST 125 126 #define IPTOS_PREC_MASK 0xe0 127 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) 128 #define IPTOS_PREC_NETCONTROL 0xe0 129 #define IPTOS_PREC_INTERNETCONTROL 0xc0 130 #define IPTOS_PREC_CRITIC_ECP 0xa0 131 #define IPTOS_PREC_FLASHOVERRIDE 0x80 132 #define IPTOS_PREC_FLASH 0x60 133 #define IPTOS_PREC_IMMEDIATE 0x40 134 #define IPTOS_PREC_PRIORITY 0x20 135 #define IPTOS_PREC_ROUTINE 0x00 136 137 #define IPOPT_COPY 0x80 138 #define IPOPT_CLASS_MASK 0x60 139 #define IPOPT_NUMBER_MASK 0x1f 140 141 #define IPOPT_COPIED(o) ((o) & IPOPT_COPY) 142 #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) 143 #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) 144 145 #define IPOPT_CONTROL 0x00 146 #define IPOPT_RESERVED1 0x20 147 #define IPOPT_DEBMEAS 0x40 148 #define IPOPT_MEASUREMENT IPOPT_DEBMEAS 149 #define IPOPT_RESERVED2 0x60 150 151 #define IPOPT_EOL 0 152 #define IPOPT_END IPOPT_EOL 153 #define IPOPT_NOP 1 154 #define IPOPT_NOOP IPOPT_NOP 155 156 #define IPOPT_RR 7 157 #define IPOPT_TS 68 158 #define IPOPT_TIMESTAMP IPOPT_TS 159 #define IPOPT_SECURITY 130 160 #define IPOPT_SEC IPOPT_SECURITY 161 #define IPOPT_LSRR 131 162 #define IPOPT_SATID 136 163 #define IPOPT_SID IPOPT_SATID 164 #define IPOPT_SSRR 137 165 #define IPOPT_RA 148 166 167 #define IPOPT_OPTVAL 0 168 #define IPOPT_OLEN 1 169 #define IPOPT_OFFSET 2 170 #define IPOPT_MINOFF 4 171 172 #define MAX_IPOPTLEN 40 173 174 #define IPOPT_TS_TSONLY 0 175 #define IPOPT_TS_TSANDADDR 1 176 #define IPOPT_TS_PRESPEC 3 177 178 #define IPOPT_SECUR_UNCLASS 0x0000 179 #define IPOPT_SECUR_CONFID 0xf135 180 #define IPOPT_SECUR_EFTO 0x789a 181 #define IPOPT_SECUR_MMMM 0xbc4d 182 #define IPOPT_SECUR_RESTR 0xaf13 183 #define IPOPT_SECUR_SECRET 0xd788 184 #define IPOPT_SECUR_TOPSECRET 0x6bc5 185 186 #define MAXTTL 255 187 #define IPDEFTTL 64 188 #define IPFRAGTTL 60 189 #define IPTTLDEC 1 190 191 #define IP_MSS 576 192 193 #define __UAPI_DEF_IPHDR 0 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif 200