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