ip.h 4.3 KB

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