Support tunneling IPv6 on Solaris.
[tinc] / lib / ipv4.h
1 /*
2     ipv4.h -- missing IPv4 related definitions
3     Copyright (C) 2004 Ivo Timmermans <ivo@tinc-vpn.org>
4                   2004 Guus Sliepen <guus@tinc-vpn.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$
21 */
22
23 #ifndef __TINC_IPV4_H__
24 #define __TINC_IPV4_H__
25
26 #ifndef AF_INET
27 #define AF_INET 2
28 #endif
29
30 #ifndef IPPROTO_ICMP
31 #define IPPROTO_ICMP 1
32 #endif
33
34 #ifndef ICMP_DEST_UNREACH
35 #define ICMP_DEST_UNREACH 3
36 #endif
37
38 #ifndef ICMP_FRAG_NEEDED
39 #define ICMP_FRAG_NEEDED 4
40 #endif
41
42 #ifndef ICMP_NET_UNKNOWN
43 #define ICMP_NET_UNKNOWN 6
44 #endif
45
46 #ifndef ICMP_NET_UNREACH
47 #define ICMP_NET_UNREACH 0
48 #endif
49
50 #ifndef IP_MSS
51 #define       IP_MSS          576
52 #endif
53
54 #ifndef HAVE_STRUCT_IP
55 struct ip {
56 #if __BYTE_ORDER == __LITTLE_ENDIAN
57         unsigned int ip_hl:4;
58         unsigned int ip_v:4;
59 #else
60         unsigned int ip_v:4;
61         unsigned int ip_hl:4;
62 #endif
63         uint8_t ip_tos;
64         uint16_t ip_len;
65         uint16_t ip_id; 
66         uint16_t ip_off;
67 #define IP_RF 0x8000
68 #define IP_DF 0x4000
69 #define IP_MF 0x2000
70         uint8_t ip_ttl;
71         uint8_t ip_p;
72         uint16_t ip_sum;
73         struct in_addr ip_src, ip_dst;
74 } __attribute__ ((__packed__));
75 #endif
76
77 #ifndef IP_OFFMASK
78 #define IP_OFFMASK 0x1fff
79 #endif
80
81 #ifndef HAVE_STRUCT_ICMP
82 struct icmp {
83         uint8_t icmp_type;
84         uint8_t icmp_code;
85         uint16_t icmp_cksum;
86         union {
87                 uint8_t ih_pptr;
88                 struct in_addr ih_gwaddr;
89                 struct ih_idseq {
90                         uint16_t icd_id;
91                         uint16_t icd_seq;
92                 } ih_idseq;
93                 uint32_t ih_void;
94
95
96                 struct ih_pmtu {
97                         uint16_t ipm_void;
98                         uint16_t ipm_nextmtu;
99                 } ih_pmtu;
100
101                 struct ih_rtradv {
102                         uint8_t irt_num_addrs;
103                         uint8_t irt_wpa;
104                         uint16_t irt_lifetime;
105                 } ih_rtradv;
106         } icmp_hun;
107 #define icmp_pptr icmp_hun.ih_pptr
108 #define icmp_gwaddr icmp_hun.ih_gwaddr
109 #define icmp_id icmp_hun.ih_idseq.icd_id
110 #define icmp_seq icmp_hun.ih_idseq.icd_seq
111 #define icmp_void icmp_hun.ih_void
112 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
113 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
114 #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
115 #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
116 #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
117         union {
118                 struct {
119                         uint32_t its_otime;
120                         uint32_t its_rtime;
121                         uint32_t its_ttime;
122                 } id_ts;
123                 struct {
124                         struct ip idi_ip;
125                 } id_ip;
126                 uint32_t id_mask;
127                 uint8_t id_data[1];
128         } icmp_dun;
129 #define icmp_otime icmp_dun.id_ts.its_otime
130 #define icmp_rtime icmp_dun.id_ts.its_rtime
131 #define icmp_ttime icmp_dun.id_ts.its_ttime
132 #define icmp_ip icmp_dun.id_ip.idi_ip
133 #define icmp_radv icmp_dun.id_radv
134 #define icmp_mask icmp_dun.id_mask
135 #define icmp_data icmp_dun.id_data
136 } __attribute__ ((__packed__));
137 #endif
138
139 #endif /* __TINC_IPV4_H__ */