-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdep.h
239 lines (196 loc) · 5.65 KB
/
sysdep.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef __SYSDEP_H__
#define __SYSDEP_H__
/*
* Different systems define different macros.
* For vpnc, this list should be used as
* reference:
*
* __linux__
* __NetBSD__
* __OpenBSD__
* __FreeBSD__
* __DragonFly__
* __APPLE__ Darwin / MacOS X
* __sun__ SunOS / Solaris
* __CYGWIN__
* __SKYOS__
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#if !defined(__CYGWIN__)
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/if_ether.h>
#endif
#include "config.h"
int tun_open(char *dev, enum if_mode_enum mode);
int tun_close(int fd, char *dev);
int tun_write(int fd, unsigned char *buf, int len);
int tun_read(int fd, unsigned char *buf, int len);
int tun_get_hwaddr(int fd, char *dev, uint8_t *hwaddr);
/***************************************************************************/
#if defined(__linux__) || defined(__GLIBC__)
#include <error.h>
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_ERROR 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#endif
/***************************************************************************/
#if defined(__NetBSD__)
#define HAVE_SA_LEN 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#endif
/***************************************************************************/
#if defined(__OpenBSD__)
#define HAVE_SA_LEN 1
#define NEED_IPLEN_FIX 1
#define NEW_TUN 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#endif
/***************************************************************************/
#if defined(__FreeBSD_kernel__)
#define HAVE_SA_LEN 1
#endif
/***************************************************************************/
#if defined(__FreeBSD__)
#define HAVE_SA_LEN 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#endif
/***************************************************************************/
#if defined(__DragonFly__)
#define HAVE_SA_LEN 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#endif
/***************************************************************************/
#if defined(__APPLE__)
#define HAVE_SA_LEN 1
#define NEED_IPLEN_FIX 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1070
#endif
#endif
/***************************************************************************/
#if defined(__sun__)
#define NEED_IPLEN_FIX 1
#ifndef IPPROTO_ESP
#define IPPROTO_ESP 50
#endif
/* where is this defined? */
#include <sys/socket.h>
const char *inet_ntop(int af, const void *src, char *dst, size_t cnt);
#endif
/***************************************************************************/
#if defined (__SKYOS__)
#define HAVE_UNSETENV 1
#ifndef IPPROTO_ENCAP
#define IPPROTO_ENCAP 4
#endif
#ifndef IPPROTO_ESP
#define IPPROTO_ESP 50
#endif
#endif
/***************************************************************************/
#if defined (__CYGWIN__)
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#define HAVE_UNSETENV 1
#define HAVE_SETENV 1
#ifndef IPPROTO_ESP
#define IPPROTO_ESP 50
#endif
#ifndef IPPROTO_ENCAP
#define IPPROTO_ENCAP 4
#endif
#ifdef IFNAMSIZ
#undef IFNAMSIZ
#endif
#define IFNAMSIZ 256
/*
* At the moment the Cygwin environment does not have header files
* for raw ethernet access, hence we need to define here what
* is usually found in net/ethernet.h and netinet/if_ether.h
*/
#define ETH_ALEN 6
/* Ethernet header */
struct ether_header
{
unsigned char ether_dhost[ETH_ALEN]; /* destination eth addr */
unsigned char ether_shost[ETH_ALEN]; /* source ether addr */
unsigned short ether_type; /* packet type ID field */
} __attribute__ ((__packed__));
#define ETHERTYPE_IP 0x0800 /* IP */
#define ETHERTYPE_ARP 0x0806 /* ARP */
/* Common ARP header */
struct arphdr {
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
unsigned char ar_hln; /* length of hardware address */
unsigned char ar_pln; /* length of protocol address */
unsigned short ar_op; /* ARP opcode (command) */
};
/* Ethernet ARP header */
struct ether_arp {
struct arphdr ea_hdr; /* fixed-size header */
unsigned char arp_sha[ETH_ALEN]; /* sender hardware address */
unsigned char arp_spa[4]; /* sender protocol address */
unsigned char arp_tha[ETH_ALEN]; /* target hardware address */
unsigned char arp_tpa[4]; /* target protocol address */
};
#define arp_hrd ea_hdr.ar_hrd
#define arp_pro ea_hdr.ar_pro
#define arp_hln ea_hdr.ar_hln
#define arp_pln ea_hdr.ar_pln
#define arp_op ea_hdr.ar_op
#define ARPHRD_ETHER 1 /* Ethernet */
#define ARPOP_REQUEST 1 /* ARP request */
#define ARPOP_REPLY 2 /* ARP reply */
#endif
/***************************************************************************/
#ifndef IPDEFTTL
#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
#endif
#ifndef IPPROTO_IPIP
#define IPPROTO_IPIP IPPROTO_ENCAP
#endif
#ifndef ETH_HLEN
#define ETH_HLEN (sizeof(struct ether_header))
#endif
#ifndef ETH_ALEN
#define ETH_ALEN (sizeof(struct ether_addr))
#endif
#ifndef HAVE_ERROR
extern void error(int fd, int errorno, const char *fmt, ...);
#endif
#ifndef HAVE_VASPRINTF
#include <stdarg.h>
extern int vasprintf(char **strp, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF
extern int asprintf(char **strp, const char *fmt, ...);
#endif
#ifndef HAVE_SETENV
extern int setenv(const char *name, const char *value, int overwrite);
#endif
#ifndef HAVE_UNSETENV
extern int unsetenv(const char *name);
#endif
#endif