ip6.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef _NETINET_IP6_H
  2. #define _NETINET_IP6_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdint.h>
  7. #include <netinet/in.h>
  8. #include <endian.h>
  9. struct ip6_hdr {
  10. union {
  11. struct ip6_hdrctl {
  12. uint32_t ip6_un1_flow;
  13. uint16_t ip6_un1_plen;
  14. uint8_t ip6_un1_nxt;
  15. uint8_t ip6_un1_hlim;
  16. } ip6_un1;
  17. uint8_t ip6_un2_vfc;
  18. } ip6_ctlun;
  19. struct in6_addr ip6_src;
  20. struct in6_addr ip6_dst;
  21. };
  22. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  23. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  24. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  25. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  26. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  27. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  28. struct ip6_ext {
  29. uint8_t ip6e_nxt;
  30. uint8_t ip6e_len;
  31. };
  32. struct ip6_hbh {
  33. uint8_t ip6h_nxt;
  34. uint8_t ip6h_len;
  35. };
  36. struct ip6_dest {
  37. uint8_t ip6d_nxt;
  38. uint8_t ip6d_len;
  39. };
  40. struct ip6_rthdr {
  41. uint8_t ip6r_nxt;
  42. uint8_t ip6r_len;
  43. uint8_t ip6r_type;
  44. uint8_t ip6r_segleft;
  45. };
  46. struct ip6_rthdr0 {
  47. uint8_t ip6r0_nxt;
  48. uint8_t ip6r0_len;
  49. uint8_t ip6r0_type;
  50. uint8_t ip6r0_segleft;
  51. uint8_t ip6r0_reserved;
  52. uint8_t ip6r0_slmap[3];
  53. struct in6_addr ip6r0_addr[];
  54. };
  55. struct ip6_frag {
  56. uint8_t ip6f_nxt;
  57. uint8_t ip6f_reserved;
  58. uint16_t ip6f_offlg;
  59. uint32_t ip6f_ident;
  60. };
  61. #if __BYTE_ORDER == __BIG_ENDIAN
  62. #define IP6F_OFF_MASK 0xfff8
  63. #define IP6F_RESERVED_MASK 0x0006
  64. #define IP6F_MORE_FRAG 0x0001
  65. #else
  66. #define IP6F_OFF_MASK 0xf8ff
  67. #define IP6F_RESERVED_MASK 0x0600
  68. #define IP6F_MORE_FRAG 0x0100
  69. #endif
  70. struct ip6_opt {
  71. uint8_t ip6o_type;
  72. uint8_t ip6o_len;
  73. };
  74. #define IP6OPT_TYPE(o) ((o) & 0xc0)
  75. #define IP6OPT_TYPE_SKIP 0x00
  76. #define IP6OPT_TYPE_DISCARD 0x40
  77. #define IP6OPT_TYPE_FORCEICMP 0x80
  78. #define IP6OPT_TYPE_ICMP 0xc0
  79. #define IP6OPT_TYPE_MUTABLE 0x20
  80. #define IP6OPT_PAD1 0
  81. #define IP6OPT_PADN 1
  82. #define IP6OPT_JUMBO 0xc2
  83. #define IP6OPT_NSAP_ADDR 0xc3
  84. #define IP6OPT_TUNNEL_LIMIT 0x04
  85. #define IP6OPT_ROUTER_ALERT 0x05
  86. struct ip6_opt_jumbo {
  87. uint8_t ip6oj_type;
  88. uint8_t ip6oj_len;
  89. uint8_t ip6oj_jumbo_len[4];
  90. };
  91. #define IP6OPT_JUMBO_LEN 6
  92. struct ip6_opt_nsap {
  93. uint8_t ip6on_type;
  94. uint8_t ip6on_len;
  95. uint8_t ip6on_src_nsap_len;
  96. uint8_t ip6on_dst_nsap_len;
  97. };
  98. struct ip6_opt_tunnel {
  99. uint8_t ip6ot_type;
  100. uint8_t ip6ot_len;
  101. uint8_t ip6ot_encap_limit;
  102. };
  103. struct ip6_opt_router {
  104. uint8_t ip6or_type;
  105. uint8_t ip6or_len;
  106. uint8_t ip6or_value[2];
  107. };
  108. #if __BYTE_ORDER == __BIG_ENDIAN
  109. #define IP6_ALERT_MLD 0x0000
  110. #define IP6_ALERT_RSVP 0x0001
  111. #define IP6_ALERT_AN 0x0002
  112. #else
  113. #define IP6_ALERT_MLD 0x0000
  114. #define IP6_ALERT_RSVP 0x0100
  115. #define IP6_ALERT_AN 0x0200
  116. #endif
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. #endif