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