ec3c511561431fbb9e11b2d76d20b86aab9892bb
[oweals/tinc.git] / lib / ipv4.h
1 /*
2     ipv4.h -- missing IPv4 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: ipv4.h,v 1.1.2.1 2003/07/18 12:16:23 guus Exp $
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_NET_UNKNOWN
39 #define ICMP_NET_UNKNOWN 6
40 #endif
41
42 #ifndef ICMP_NET_UNREACH
43 #define ICMP_NET_UNREACH 0
44 #endif
45
46 #ifndef IP_MSS
47 #define       IP_MSS          576
48 #endif
49
50 #ifndef HAVE_NETINET_IP_H
51
52 struct ip {
53 #if __BYTE_ORDER == __LITTLE_ENDIAN
54         unsigned int ip_hl:4;
55         unsigned int ip_v:4;
56 #else
57         unsigned int ip_v:4;
58         unsigned int ip_hl:4;
59 #endif
60         uint8_t ip_tos;
61         u_short ip_len;
62         u_short ip_id; 
63         u_short ip_off;
64 #define IP_RF 0x8000
65 #define IP_DF 0x4000
66 #define IP_MF 0x2000
67 #define IP_OFFMASK 0x1fff
68         uint8_t ip_ttl;
69         uint8_t ip_p;
70         u_short ip_sum;
71         struct in_addr ip_src, ip_dst;
72 };
73
74 #endif
75
76 #ifndef HAVE_NETINET_IP_ICMP_H
77
78 struct icmp {
79         uint8_t icmp_type;
80         uint8_t icmp_code;
81         uint16_t icmp_cksum;
82         union {
83                 u_char ih_pptr;
84                 struct in_addr ih_gwaddr;
85                 struct ih_idseq {
86                         uint16_t icd_id;
87                         uint16_t icd_seq;
88                 } ih_idseq;
89                 uint32_t ih_void;
90
91
92                 struct ih_pmtu {
93                         uint16_t ipm_void;
94                         uint16_t ipm_nextmtu;
95                 } ih_pmtu;
96
97                 struct ih_rtradv {
98                         uint8_t irt_num_addrs;
99                         uint8_t irt_wpa;
100                         uint16_t irt_lifetime;
101                 } ih_rtradv;
102         } icmp_hun;
103 #define icmp_pptr icmp_hun.ih_pptr
104 #define icmp_gwaddr icmp_hun.ih_gwaddr
105 #define icmp_id icmp_hun.ih_idseq.icd_id
106 #define icmp_seq icmp_hun.ih_idseq.icd_seq
107 #define icmp_void icmp_hun.ih_void
108 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
109 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
110 #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
111 #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
112 #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
113         union {
114                 struct {
115                         uint32_t its_otime;
116                         uint32_t its_rtime;
117                         uint32_t its_ttime;
118                 } id_ts;
119                 struct {
120                         struct ip idi_ip;
121                 } id_ip;
122                 uint32_t id_mask;
123                 uint8_t id_data[1];
124         } icmp_dun;
125 #define icmp_otime icmp_dun.id_ts.its_otime
126 #define icmp_rtime icmp_dun.id_ts.its_rtime
127 #define icmp_ttime icmp_dun.id_ts.its_ttime
128 #define icmp_ip icmp_dun.id_ip.idi_ip
129 #define icmp_radv icmp_dun.id_radv
130 #define icmp_mask icmp_dun.id_mask
131 #define icmp_data icmp_dun.id_data
132 };
133
134 #endif
135
136 #endif /* __TINC_IPV4_H__ */