win32-ipicmp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Author: Daniel Lenski <dlenski@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * version 2.1, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. */
  15. #ifndef __OPENCONNECT_WIN32_IPICMP_H__
  16. #define __OPENCONNECT_WIN32_IPICMP_H__
  17. #include <ws2tcpip.h>
  18. #include <stdint.h>
  19. /* IPv4 header and flags used in gpst.c */
  20. #define IP_DF 0x4000 /* don't fragment flag */
  21. #define IP_MF 0x2000 /* more fragments flag */
  22. struct ip {
  23. u_char ip_hl:4; /* header length */
  24. u_char ip_v:4; /* version */
  25. u_char ip_tos; /* type of service */
  26. short ip_len; /* total length */
  27. u_short ip_id; /* identification */
  28. short ip_off; /* fragment offset field */
  29. u_char ip_ttl; /* time to live */
  30. u_char ip_p; /* protocol */
  31. u_short ip_sum; /* checksum */
  32. struct in_addr ip_src,ip_dst; /* source and dest address */
  33. };
  34. /* IPv6 header used in gpst.c */
  35. struct ip6_hdr {
  36. union {
  37. struct ip6_hdrctl {
  38. uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC,
  39. 20 bits flow-ID */
  40. uint16_t ip6_un1_plen; /* payload length */
  41. uint8_t ip6_un1_nxt; /* next header */
  42. uint8_t ip6_un1_hlim; /* hop limit */
  43. } ip6_un1;
  44. uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits tclass */
  45. } ip6_ctlun;
  46. struct in6_addr ip6_src; /* source address */
  47. struct in6_addr ip6_dst; /* destination address */
  48. };
  49. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  50. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  51. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  52. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  53. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  54. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  55. /* ICMP header and flags used in gpst.c */
  56. #define IPPROTO_ICMP 1
  57. #define ICMP_MINLEN 8 /* abs minimum */
  58. #define ICMP_ECHO 8 /* Echo Request */
  59. #define ICMP_ECHOREPLY 0 /* Echo Reply */
  60. #define icmp_pptr icmp_hun.ih_pptr
  61. #define icmp_gwaddr icmp_hun.ih_gwaddr
  62. #define icmp_id icmp_hun.ih_idseq.icd_id
  63. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  64. #define icmp_void icmp_hun.ih_void
  65. #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
  66. #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
  67. #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
  68. #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
  69. #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
  70. #define icmp_otime icmp_dun.id_ts.its_otime
  71. #define icmp_rtime icmp_dun.id_ts.its_rtime
  72. #define icmp_ttime icmp_dun.id_ts.its_ttime
  73. #define icmp_ip icmp_dun.id_ip.idi_ip
  74. #define icmp_radv icmp_dun.id_radv
  75. #define icmp_mask icmp_dun.id_mask
  76. #define icmp_data icmp_dun.id_data
  77. struct icmp_ra_addr {
  78. uint32_t ira_addr;
  79. uint32_t ira_preference;
  80. };
  81. struct icmp {
  82. uint8_t icmp_type; /* type of message, see below */
  83. uint8_t icmp_code; /* type sub code */
  84. uint16_t icmp_cksum; /* ones complement checksum of struct */
  85. union {
  86. u_char ih_pptr; /* ICMP_PARAMPROB */
  87. struct in_addr ih_gwaddr; /* gateway address */
  88. struct ih_idseq { /* echo datagram */
  89. uint16_t icd_id;
  90. uint16_t icd_seq;
  91. } ih_idseq;
  92. uint32_t ih_void;
  93. /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
  94. struct ih_pmtu {
  95. uint16_t ipm_void;
  96. uint16_t ipm_nextmtu;
  97. } ih_pmtu;
  98. struct ih_rtradv {
  99. uint8_t irt_num_addrs;
  100. uint8_t irt_wpa;
  101. uint16_t irt_lifetime;
  102. } ih_rtradv;
  103. } icmp_hun;
  104. union {
  105. struct {
  106. uint32_t its_otime;
  107. uint32_t its_rtime;
  108. uint32_t its_ttime;
  109. } id_ts;
  110. struct {
  111. struct ip idi_ip;
  112. /* options and then 64 bits of data */
  113. } id_ip;
  114. struct icmp_ra_addr id_radv;
  115. uint32_t id_mask;
  116. uint8_t id_data[1];
  117. } icmp_dun;
  118. };
  119. /* ICMPv6 header and flags used in gpst.c */
  120. #define IPPROTO_ICMPV6 58
  121. #define ICMP6_ECHO_REQUEST 128
  122. #define ICMP6_ECHO_REPLY 129
  123. struct icmp6_hdr {
  124. uint8_t icmp6_type; /* type field */
  125. uint8_t icmp6_code; /* code field */
  126. uint16_t icmp6_cksum; /* checksum field */
  127. union {
  128. uint32_t icmp6_un_data32[1]; /* type-specific field */
  129. uint16_t icmp6_un_data16[2]; /* type-specific field */
  130. uint8_t icmp6_un_data8[4]; /* type-specific field */
  131. } icmp6_dataun;
  132. };
  133. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  134. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  135. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  136. #define icmp6_pptr icmp6_data32[0] /* parameter prob */
  137. #define icmp6_mtu icmp6_data32[0] /* packet too big */
  138. #define icmp6_id icmp6_data16[0] /* echo request/reply */
  139. #define icmp6_seq icmp6_data16[1] /* echo request/reply */
  140. #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
  141. #endif /* __OPENCONNECT_WIN32_IPICMP_H__ */