FreeBSD compat

This commit is contained in:
Erik Ekman 2006-06-24 11:33:57 +00:00
parent 61550d0384
commit 65c39c3b6e
2 changed files with 18 additions and 3 deletions

5
dns.c
View file

@ -32,6 +32,11 @@
#include "structs.h" #include "structs.h"
#include "dns.h" #include "dns.h"
// For FreeBSD
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
static int host2dns(const char *, char *, int); static int host2dns(const char *, char *, int);
static int dns_write(int, int, char *, int, char); static int dns_write(int, int, char *, int, char);

16
tun.c
View file

@ -136,30 +136,39 @@ close_tun(int tun_fd)
int int
write_tun(int tun_fd, char *data, int len) write_tun(int tun_fd, char *data, int len)
{ {
#ifdef FREEBSD
data += 4;
len -= 4;
#else /* !FREEBSD */
#ifdef LINUX #ifdef LINUX
data[0] = 0x00; data[0] = 0x00;
data[1] = 0x00; data[1] = 0x00;
data[2] = 0x08; data[2] = 0x08;
data[3] = 0x00; data[3] = 0x00;
#else /* LINUX */ #else /* OPENBSD */
data[0] = 0x00; data[0] = 0x00;
data[1] = 0x00; data[1] = 0x00;
data[2] = 0x00; data[2] = 0x00;
data[3] = 0x02; data[3] = 0x02;
#endif /* !LINUX */ #endif /* !LINUX */
#endif /* FREEBSD */
if (write(tun_fd, data, len) != len) { if (write(tun_fd, data, len) != len) {
warn("write_tun"); warn("write_tun");
return 1; return 1;
} }
return 0; return 0;
} }
int int
read_tun(int tun_fd, char *buf, int len) read_tun(int tun_fd, char *buf, int len)
{ {
#ifdef FREEBSD
// FreeBSD has no header
return read(tun_fd, buf + 4, len - 4) + 4;
#else /* !FREEBSD */
return read(tun_fd, buf, len); return read(tun_fd, buf, len);
#endif /* !FREEBSD */
} }
int int
@ -169,8 +178,9 @@ tun_setip(const char *ip)
if (inet_addr(ip) != INADDR_NONE) { if (inet_addr(ip) != INADDR_NONE) {
snprintf(cmdline, sizeof(cmdline), snprintf(cmdline, sizeof(cmdline),
"/sbin/ifconfig %s %s netmask 255.255.255.0", "/sbin/ifconfig %s %s %s netmask 255.255.255.0",
if_name, if_name,
ip,
ip); ip);
printf("Setting IP of %s to %s\n", if_name, ip); printf("Setting IP of %s to %s\n", if_name, ip);