ip_icmp.h 4.5 KB

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