More missing IPv6 definitions and autoconf checks to make sure it compiles
[tinc] / lib / ipv6.h
1 /*
2     ipv6.h -- missing IPv6 related definitions
3     Copyright (C) 2003 Ivo Timmermans <ivo@o2w.nl>
4                   2003 Guus Sliepen <guus@sliepen.eu.org>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: ipv6.h,v 1.1.2.3 2003/07/11 16:12:59 guus Exp $
21 */
22
23 #ifndef __TINC_IPV6_H__
24 #define __TINC_IPV6_H__
25
26 #include "config.h"
27
28 #include <netinet/in.h>
29 #ifdef HAVE_INTTYPES_H
30 #include <inttypes.h>
31 #endif
32
33 #ifndef AF_INET6
34 #define AF_INET6 10
35 #endif
36
37 #ifndef IPPROTO_ICMPV6
38 #define IPPROTO_ICMPV6 58
39 #endif
40
41 #ifndef HAVE_STRUCT_IN6_ADDR
42 struct in6_addr {
43         union {
44                 uint8_t u6_addr8[16];
45                 uint16_t u6_addr16[8];
46                 uint32_t u6_addr32[4];
47         } in6_u;
48 };
49 #define s6_addr in6_u.u6_addr8
50 #define s6_addr16 in6_u.u6_addr16
51 #define s6_addr32 in6_u.u6_addr32
52 #endif
53
54 #ifndef HAVE_STRUCT_SOCKADDR_IN6
55 struct sockaddr_in6 {
56         in_port_t sin6_port;
57         uint32_t sin6_flowinfo;
58         struct in6_addr sin6_addr;
59         uint32_t sin6_scope_id;
60 };
61 #endif
62
63 #ifndef IN6_IS_ADDR_V4MAPPED
64 #define IN6_IS_ADDR_V4MAPPED(a) \
65         ((((__const uint32_t *) (a))[0] == 0) \
66         && (((__const uint32_t *) (a))[1] == 0) \
67         && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
68 #endif
69
70 #ifndef HAVE_NETINET_IP6_H
71 struct ip6_hdr {
72         union {
73                 struct ip6_hdrctl {
74                         uint32_t ip6_un1_flow;
75                         uint16_t ip6_un1_plen;
76                         uint8_t ip6_un1_nxt;
77                         uint8_t ip6_un1_hlim;
78                 } ip6_un1;
79                 uint8_t ip6_un2_vfc;
80         } ip6_ctlun;
81         struct in6_addr ip6_src;
82         struct in6_addr ip6_dst;
83 };
84 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
85 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
86 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
87 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
88 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
89 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
90
91 struct icmp6_hdr {
92         uint8_t icmp6_type;
93         uint8_t icmp6_code;
94         uint16_t icmp6_cksum;
95         union {
96                 uint32_t icmp6_un_data32[1];
97                 uint16_t icmp6_un_data16[2];
98                 uint8_t icmp6_un_data8[4];
99         } icmp6_dataun;
100 };
101 #define ICMP6_DST_UNREACH_NOROUTE 0
102 #define ICMP6_DST_UNREACH 1
103 #define ICMP6_DST_UNREACH_ADDR 3
104 #define ND_NEIGHBOR_SOLICIT 135
105 #define ND_NEIGHBOR_ADVERT 136
106
107 struct nd_neighbor_solicit {
108         struct icmp6_hdr nd_ns_hdr;
109         struct in6_addr nd_ns_target;
110 };
111 #define ND_OPT_SOURCE_LINKADDR 1
112 #define ND_OPT_TARGET_LINKADDR 2
113
114 struct nd_opt_hdr {
115         uint8_t nd_opt_type;
116         uint8_t nd_opt_len;
117 };
118 #endif
119
120 #endif /* __TINC_IPV6_H__ */