Replace obsolete getpass()
[vpnc.git] / sysdep.h
blob137bf6dc25c58d2fa739cb14f791b8bee0be16bc
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_UNSETENV 1
47 #define HAVE_SETENV 1
48 #endif
50 /***************************************************************************/
51 #if defined(__NetBSD__)
52 #define HAVE_SA_LEN 1
54 #define HAVE_VASPRINTF 1
55 #define HAVE_ASPRINTF 1
56 #define HAVE_UNSETENV 1
57 #define HAVE_SETENV 1
58 #endif
60 /***************************************************************************/
61 #if defined(__OpenBSD__)
62 #define HAVE_SA_LEN 1
63 #define NEED_IPLEN_FIX 1
64 #define NEW_TUN 1
66 #define HAVE_VASPRINTF 1
67 #define HAVE_ASPRINTF 1
68 #define HAVE_UNSETENV 1
69 #define HAVE_SETENV 1
70 #endif
72 /***************************************************************************/
73 #if defined(__FreeBSD_kernel__)
74 #define HAVE_SA_LEN 1
75 #endif
77 /***************************************************************************/
78 #if defined(__FreeBSD__)
79 #define HAVE_SA_LEN 1
81 #define HAVE_VASPRINTF 1
82 #define HAVE_ASPRINTF 1
83 #define HAVE_UNSETENV 1
84 #define HAVE_SETENV 1
85 #endif
87 /***************************************************************************/
88 #if defined(__DragonFly__)
89 #define HAVE_SA_LEN 1
91 #define HAVE_VASPRINTF 1
92 #define HAVE_ASPRINTF 1
93 #define HAVE_UNSETENV 1
94 #define HAVE_SETENV 1
95 #endif
97 /***************************************************************************/
98 #if defined(__APPLE__)
99 #define HAVE_SA_LEN 1
100 #define NEED_IPLEN_FIX 1
102 #define HAVE_VASPRINTF 1
103 #define HAVE_ASPRINTF 1
104 #define HAVE_UNSETENV 1
105 #define HAVE_SETENV 1
106 #if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1070
107 #endif
108 #endif
110 /***************************************************************************/
111 #if defined(__sun__)
112 #define NEED_IPLEN_FIX 1
114 #ifndef IPPROTO_ESP
115 #define IPPROTO_ESP 50
116 #endif
118 /* where is this defined? */
119 #include <sys/socket.h>
120 const char *inet_ntop(int af, const void *src, char *dst, size_t cnt);
121 #endif
122 /***************************************************************************/
123 #if defined (__SKYOS__)
124 #define HAVE_UNSETENV 1
126 #ifndef IPPROTO_ENCAP
127 #define IPPROTO_ENCAP 4
128 #endif
130 #ifndef IPPROTO_ESP
131 #define IPPROTO_ESP 50
132 #endif
133 #endif
134 /***************************************************************************/
135 #if defined (__CYGWIN__)
136 #define HAVE_VASPRINTF 1
137 #define HAVE_ASPRINTF 1
138 #define HAVE_UNSETENV 1
139 #define HAVE_SETENV 1
141 #ifndef IPPROTO_ESP
142 #define IPPROTO_ESP 50
143 #endif
145 #ifndef IPPROTO_ENCAP
146 #define IPPROTO_ENCAP 4
147 #endif
149 #ifdef IFNAMSIZ
150 #undef IFNAMSIZ
151 #endif
152 #define IFNAMSIZ 256
155 * At the moment the Cygwin environment does not have header files
156 * for raw ethernet access, hence we need to define here what
157 * is usually found in net/ethernet.h and netinet/if_ether.h
160 #define ETH_ALEN 6
162 /* Ethernet header */
163 struct ether_header
165 unsigned char ether_dhost[ETH_ALEN]; /* destination eth addr */
166 unsigned char ether_shost[ETH_ALEN]; /* source ether addr */
167 unsigned short ether_type; /* packet type ID field */
168 } __attribute__ ((__packed__));
170 #define ETHERTYPE_IP 0x0800 /* IP */
171 #define ETHERTYPE_ARP 0x0806 /* ARP */
173 /* Common ARP header */
174 struct arphdr {
175 unsigned short ar_hrd; /* format of hardware address */
176 unsigned short ar_pro; /* format of protocol address */
177 unsigned char ar_hln; /* length of hardware address */
178 unsigned char ar_pln; /* length of protocol address */
179 unsigned short ar_op; /* ARP opcode (command) */
182 /* Ethernet ARP header */
183 struct ether_arp {
184 struct arphdr ea_hdr; /* fixed-size header */
185 unsigned char arp_sha[ETH_ALEN]; /* sender hardware address */
186 unsigned char arp_spa[4]; /* sender protocol address */
187 unsigned char arp_tha[ETH_ALEN]; /* target hardware address */
188 unsigned char arp_tpa[4]; /* target protocol address */
190 #define arp_hrd ea_hdr.ar_hrd
191 #define arp_pro ea_hdr.ar_pro
192 #define arp_hln ea_hdr.ar_hln
193 #define arp_pln ea_hdr.ar_pln
194 #define arp_op ea_hdr.ar_op
196 #define ARPHRD_ETHER 1 /* Ethernet */
198 #define ARPOP_REQUEST 1 /* ARP request */
199 #define ARPOP_REPLY 2 /* ARP reply */
201 #endif
202 /***************************************************************************/
205 #ifndef IPDEFTTL
206 #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
207 #endif
209 #ifndef IPPROTO_IPIP
210 #define IPPROTO_IPIP IPPROTO_ENCAP
211 #endif
213 #ifndef ETH_HLEN
214 #define ETH_HLEN (sizeof(struct ether_header))
215 #endif
217 #ifndef ETH_ALEN
218 #define ETH_ALEN (sizeof(struct ether_addr))
219 #endif
221 #ifndef HAVE_ERROR
222 extern void error(int fd, int errorno, const char *fmt, ...);
223 #endif
224 #ifndef HAVE_VASPRINTF
225 #include <stdarg.h>
226 extern int vasprintf(char **strp, const char *fmt, va_list ap);
227 #endif
228 #ifndef HAVE_ASPRINTF
229 extern int asprintf(char **strp, const char *fmt, ...);
230 #endif
231 #ifndef HAVE_SETENV
232 extern int setenv(const char *name, const char *value, int overwrite);
233 #endif
234 #ifndef HAVE_UNSETENV
235 extern int unsetenv(const char *name);
236 #endif
239 #endif