ip.h 4.3 KB

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