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