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 "dns.h"
// For FreeBSD
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
static int host2dns(const char *, char *, int);
static int dns_write(int, int, char *, int, char);

16
tun.c
View File

@ -136,30 +136,39 @@ close_tun(int tun_fd)
int
write_tun(int tun_fd, char *data, int len)
{
#ifdef FREEBSD
data += 4;
len -= 4;
#else /* !FREEBSD */
#ifdef LINUX
data[0] = 0x00;
data[1] = 0x00;
data[2] = 0x08;
data[3] = 0x00;
#else /* LINUX */
#else /* OPENBSD */
data[0] = 0x00;
data[1] = 0x00;
data[2] = 0x00;
data[3] = 0x02;
#endif /* !LINUX */
#endif /* FREEBSD */
if (write(tun_fd, data, len) != len) {
warn("write_tun");
return 1;
}
return 0;
}
int
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);
#endif /* !FREEBSD */
}
int
@ -169,8 +178,9 @@ tun_setip(const char *ip)
if (inet_addr(ip) != INADDR_NONE) {
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,
ip,
ip);
printf("Setting IP of %s to %s\n", if_name, ip);