qos length bugfix and apple support plus header cleanup
diff --git a/ggsn/tun.c b/ggsn/tun.c
index 3436972..576e32e 100644
--- a/ggsn/tun.c
+++ b/ggsn/tun.c
@@ -1,17 +1,12 @@
/*
* TUN interface functions.
- * Copyright (C) 2002, 2003 Mondru AB.
+ * Copyright (C) 2002, 2003, 2004 Mondru AB.
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
- * The initial developer of the original code is
- * Jens Jakobsen <jj@openggsn.org>
- *
- * Contributor(s):
- *
*/
/*
@@ -55,6 +50,9 @@
#include <net/if.h>
#include <net/if_tun.h>
+#elif defined (__APPLE__)
+#include <net/if.h>
+
#elif defined (__sun__)
#include <stropts.h>
#include <sys/sockio.h>
@@ -336,7 +334,7 @@
this->addrs++;
return 0;
-#elif defined (__FreeBSD__)
+#elif defined (__FreeBSD__) || defined (__APPLE__)
int fd;
struct ifaliasreq areq;
@@ -415,7 +413,7 @@
#if defined(__linux__)
ifr.ifr_netmask.sa_family = AF_INET;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined (__APPLE__)
((struct sockaddr_in *) &ifr.ifr_addr)->sin_len =
sizeof (struct sockaddr_in);
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_len =
@@ -467,7 +465,7 @@
((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr =
netmask->s_addr;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined (__APPLE__)
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr =
netmask->s_addr;
@@ -494,7 +492,7 @@
/* TODO: How does it work on Solaris? */
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined (__APPLE__)
tun_sifflags(this, IFF_UP | IFF_RUNNING); /* TODO */
return tun_addroute(this, addr, addr, netmask);
#else
@@ -543,7 +541,7 @@
close(fd);
return 0;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined (__APPLE__)
struct {
struct rt_msghdr rt;
@@ -610,7 +608,7 @@
#if defined(__linux__)
struct ifreq ifr;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined (__APPLE__)
char devname[IFNAMSIZ+5]; /* "/dev/" + ifname */
int devnum;
struct ifaliasreq areq;
@@ -657,7 +655,7 @@
ioctl((*tun)->fd, TUNSETNOCSUM, 1); /* Disable checksums */
return 0;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined (__APPLE__)
/* Find suitable device */
for (devnum = 0; devnum < 255; devnum++) { /* TODO 255 */
@@ -784,7 +782,7 @@
int tun_decaps(struct tun_t *this)
{
-#if defined(__linux__) || defined (__FreeBSD__)
+#if defined(__linux__) || defined (__FreeBSD__) || defined (__APPLE__)
unsigned char buffer[PACKET_MAX];
int status;
@@ -825,7 +823,7 @@
int tun_encaps(struct tun_t *tun, void *pack, unsigned len)
{
-#if defined(__linux__) || defined (__FreeBSD__)
+#if defined(__linux__) || defined (__FreeBSD__) || defined (__APPLE__)
return write(tun->fd, pack, len);