ipv4.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. ipv4.h -- missing IPv4 related definitions
  3. Copyright (C) 2005 Ivo Timmermans
  4. 2006-2012 Guus Sliepen <guus@tinc-vpn.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef __TINC_IPV4_H__
  18. #define __TINC_IPV4_H__
  19. #ifndef AF_INET
  20. #define AF_INET 2
  21. #endif
  22. #ifndef IPPROTO_ICMP
  23. #define IPPROTO_ICMP 1
  24. #endif
  25. #ifndef ICMP_DEST_UNREACH
  26. #define ICMP_DEST_UNREACH 3
  27. #endif
  28. #ifndef ICMP_FRAG_NEEDED
  29. #define ICMP_FRAG_NEEDED 4
  30. #endif
  31. #ifndef ICMP_NET_UNKNOWN
  32. #define ICMP_NET_UNKNOWN 6
  33. #endif
  34. #ifndef ICMP_TIME_EXCEEDED
  35. #define ICMP_TIME_EXCEEDED 11
  36. #endif
  37. #ifndef ICMP_EXC_TTL
  38. #define ICMP_EXC_TTL 0
  39. #endif
  40. #ifndef ICMP_NET_UNREACH
  41. #define ICMP_NET_UNREACH 0
  42. #endif
  43. #ifndef ICMP_NET_ANO
  44. #define ICMP_NET_ANO 9
  45. #endif
  46. #ifndef IP_MSS
  47. #define IP_MSS 576
  48. #endif
  49. #ifndef HAVE_STRUCT_IP
  50. struct ip {
  51. #if __BYTE_ORDER == __LITTLE_ENDIAN
  52. unsigned int ip_hl:4;
  53. unsigned int ip_v:4;
  54. #else
  55. unsigned int ip_v:4;
  56. unsigned int ip_hl:4;
  57. #endif
  58. uint8_t ip_tos;
  59. uint16_t ip_len;
  60. uint16_t ip_id;
  61. uint16_t ip_off;
  62. #define IP_RF 0x8000
  63. #define IP_DF 0x4000
  64. #define IP_MF 0x2000
  65. uint8_t ip_ttl;
  66. uint8_t ip_p;
  67. uint16_t ip_sum;
  68. struct in_addr ip_src, ip_dst;
  69. } __attribute__ ((__packed__));
  70. #endif
  71. #ifndef IP_OFFMASK
  72. #define IP_OFFMASK 0x1fff
  73. #endif
  74. #ifndef HAVE_STRUCT_ICMP
  75. struct icmp {
  76. uint8_t icmp_type;
  77. uint8_t icmp_code;
  78. uint16_t icmp_cksum;
  79. union {
  80. uint8_t ih_pptr;
  81. struct in_addr ih_gwaddr;
  82. struct ih_idseq {
  83. uint16_t icd_id;
  84. uint16_t icd_seq;
  85. } ih_idseq;
  86. uint32_t ih_void;
  87. struct ih_pmtu {
  88. uint16_t ipm_void;
  89. uint16_t ipm_nextmtu;
  90. } ih_pmtu;
  91. struct ih_rtradv {
  92. uint8_t irt_num_addrs;
  93. uint8_t irt_wpa;
  94. uint16_t irt_lifetime;
  95. } ih_rtradv;
  96. } icmp_hun;
  97. #define icmp_pptr icmp_hun.ih_pptr
  98. #define icmp_gwaddr icmp_hun.ih_gwaddr
  99. #define icmp_id icmp_hun.ih_idseq.icd_id
  100. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  101. #define icmp_void icmp_hun.ih_void
  102. #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
  103. #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
  104. #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
  105. #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
  106. #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
  107. union {
  108. struct {
  109. uint32_t its_otime;
  110. uint32_t its_rtime;
  111. uint32_t its_ttime;
  112. } id_ts;
  113. struct {
  114. struct ip idi_ip;
  115. } id_ip;
  116. uint32_t id_mask;
  117. uint8_t id_data[1];
  118. } icmp_dun;
  119. #define icmp_otime icmp_dun.id_ts.its_otime
  120. #define icmp_rtime icmp_dun.id_ts.its_rtime
  121. #define icmp_ttime icmp_dun.id_ts.its_ttime
  122. #define icmp_ip icmp_dun.id_ip.idi_ip
  123. #define icmp_radv icmp_dun.id_radv
  124. #define icmp_mask icmp_dun.id_mask
  125. #define icmp_data icmp_dun.id_data
  126. } __attribute__ ((__packed__));
  127. #endif
  128. #endif /* __TINC_IPV4_H__ */