ip_icmp.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _NETINET_IP_ICMP_H
  2. #define _NETINET_IP_ICMP_H
  3. #include <stdint.h>
  4. #include <netinet/in.h>
  5. #include <netinet/ip.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. struct icmphdr {
  10. uint8_t type;
  11. uint8_t code;
  12. uint16_t checksum;
  13. union {
  14. struct {
  15. uint16_t id;
  16. uint16_t sequence;
  17. } echo;
  18. uint32_t gateway;
  19. struct {
  20. uint16_t __unused;
  21. uint16_t mtu;
  22. } frag;
  23. uint8_t reserved[4];
  24. } un;
  25. };
  26. #define ICMP_ECHOREPLY 0
  27. #define ICMP_DEST_UNREACH 3
  28. #define ICMP_SOURCE_QUENCH 4
  29. #define ICMP_REDIRECT 5
  30. #define ICMP_ECHO 8
  31. #define ICMP_TIME_EXCEEDED 11
  32. #define ICMP_PARAMETERPROB 12
  33. #define ICMP_TIMESTAMP 13
  34. #define ICMP_TIMESTAMPREPLY 14
  35. #define ICMP_INFO_REQUEST 15
  36. #define ICMP_INFO_REPLY 16
  37. #define ICMP_ADDRESS 17
  38. #define ICMP_ADDRESSREPLY 18
  39. #define NR_ICMP_TYPES 18
  40. #define ICMP_NET_UNREACH 0
  41. #define ICMP_HOST_UNREACH 1
  42. #define ICMP_PROT_UNREACH 2
  43. #define ICMP_PORT_UNREACH 3
  44. #define ICMP_FRAG_NEEDED 4
  45. #define ICMP_SR_FAILED 5
  46. #define ICMP_NET_UNKNOWN 6
  47. #define ICMP_HOST_UNKNOWN 7
  48. #define ICMP_HOST_ISOLATED 8
  49. #define ICMP_NET_ANO 9
  50. #define ICMP_HOST_ANO 10
  51. #define ICMP_NET_UNR_TOS 11
  52. #define ICMP_HOST_UNR_TOS 12
  53. #define ICMP_PKT_FILTERED 13
  54. #define ICMP_PREC_VIOLATION 14
  55. #define ICMP_PREC_CUTOFF 15
  56. #define NR_ICMP_UNREACH 15
  57. #define ICMP_REDIR_NET 0
  58. #define ICMP_REDIR_HOST 1
  59. #define ICMP_REDIR_NETTOS 2
  60. #define ICMP_REDIR_HOSTTOS 3
  61. #define ICMP_EXC_TTL 0
  62. #define ICMP_EXC_FRAGTIME 1
  63. struct icmp_ra_addr {
  64. uint32_t ira_addr;
  65. uint32_t ira_preference;
  66. };
  67. struct icmp {
  68. uint8_t icmp_type;
  69. uint8_t icmp_code;
  70. uint16_t icmp_cksum;
  71. union {
  72. uint8_t ih_pptr;
  73. struct in_addr ih_gwaddr;
  74. struct ih_idseq {
  75. uint16_t icd_id;
  76. uint16_t icd_seq;
  77. } ih_idseq;
  78. uint32_t ih_void;
  79. struct ih_pmtu {
  80. uint16_t ipm_void;
  81. uint16_t ipm_nextmtu;
  82. } ih_pmtu;
  83. struct ih_rtradv {
  84. uint8_t irt_num_addrs;
  85. uint8_t irt_wpa;
  86. uint16_t irt_lifetime;
  87. } ih_rtradv;
  88. } icmp_hun;
  89. union {
  90. struct {
  91. uint32_t its_otime;
  92. uint32_t its_rtime;
  93. uint32_t its_ttime;
  94. } id_ts;
  95. struct {
  96. struct ip idi_ip;
  97. } id_ip;
  98. struct icmp_ra_addr id_radv;
  99. uint32_t id_mask;
  100. uint8_t id_data[1];
  101. } icmp_dun;
  102. };
  103. #define icmp_pptr icmp_hun.ih_pptr
  104. #define icmp_gwaddr icmp_hun.ih_gwaddr
  105. #define icmp_id icmp_hun.ih_idseq.icd_id
  106. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  107. #define icmp_void icmp_hun.ih_void
  108. #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
  109. #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
  110. #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
  111. #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
  112. #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
  113. #define icmp_otime icmp_dun.id_ts.its_otime
  114. #define icmp_rtime icmp_dun.id_ts.its_rtime
  115. #define icmp_ttime icmp_dun.id_ts.its_ttime
  116. #define icmp_ip icmp_dun.id_ip.idi_ip
  117. #define icmp_radv icmp_dun.id_radv
  118. #define icmp_mask icmp_dun.id_mask
  119. #define icmp_data icmp_dun.id_data
  120. #define ICMP_MINLEN 8
  121. #define ICMP_TSLEN (8 + 3 * sizeof (n_time))
  122. #define ICMP_MASKLEN 12
  123. #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8)
  124. #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
  125. #define ICMP_UNREACH 3
  126. #define ICMP_SOURCEQUENCH 4
  127. #define ICMP_ROUTERADVERT 9
  128. #define ICMP_ROUTERSOLICIT 10
  129. #define ICMP_TIMXCEED 11
  130. #define ICMP_PARAMPROB 12
  131. #define ICMP_TSTAMP 13
  132. #define ICMP_TSTAMPREPLY 14
  133. #define ICMP_IREQ 15
  134. #define ICMP_IREQREPLY 16
  135. #define ICMP_MASKREQ 17
  136. #define ICMP_MASKREPLY 18
  137. #define ICMP_MAXTYPE 18
  138. #define ICMP_UNREACH_NET 0
  139. #define ICMP_UNREACH_HOST 1
  140. #define ICMP_UNREACH_PROTOCOL 2
  141. #define ICMP_UNREACH_PORT 3
  142. #define ICMP_UNREACH_NEEDFRAG 4
  143. #define ICMP_UNREACH_SRCFAIL 5
  144. #define ICMP_UNREACH_NET_UNKNOWN 6
  145. #define ICMP_UNREACH_HOST_UNKNOWN 7
  146. #define ICMP_UNREACH_ISOLATED 8
  147. #define ICMP_UNREACH_NET_PROHIB 9
  148. #define ICMP_UNREACH_HOST_PROHIB 10
  149. #define ICMP_UNREACH_TOSNET 11
  150. #define ICMP_UNREACH_TOSHOST 12
  151. #define ICMP_UNREACH_FILTER_PROHIB 13
  152. #define ICMP_UNREACH_HOST_PRECEDENCE 14
  153. #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
  154. #define ICMP_REDIRECT_NET 0
  155. #define ICMP_REDIRECT_HOST 1
  156. #define ICMP_REDIRECT_TOSNET 2
  157. #define ICMP_REDIRECT_TOSHOST 3
  158. #define ICMP_TIMXCEED_INTRANS 0
  159. #define ICMP_TIMXCEED_REASS 1
  160. #define ICMP_PARAMPROB_OPTABSENT 1
  161. #define ICMP_INFOTYPE(type) \
  162. ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
  163. (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
  164. (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
  165. (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
  166. (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif