breaking-indent
authorChristian Grothoff <christian@grothoff.org>
Wed, 19 Jan 2011 08:30:52 +0000 (08:30 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 19 Jan 2011 08:30:52 +0000 (08:30 +0000)
src/vpn/Makefile.am
src/vpn/gnunet-helper-vpn.c
src/vpn/gnunet-vpn-helper-p.h [deleted file]
src/vpn/gnunet-vpn-tun.c [deleted file]
src/vpn/gnunet-vpn-tun.h [deleted file]

index 9100fd900a679e8685ac05af9b291232ab2386c7..f1b0e1df7ee16212ad3fdf4b50cee9f6b4092a02 100644 (file)
@@ -26,9 +26,7 @@ bin_PROGRAMS = \
 
 
 gnunet_helper_vpn_SOURCES = \
- gnunet-helper-vpn.c \
- gnunet-vpn-helper-p.h \
- gnunet-vpn-tun.h gnunet-vpn-tun.c
+ gnunet-helper-vpn.c
 
 gnunet_helper_hijack_dns_SOURCES = \
  gnunet-helper-hijack-dns.c
index c2ebe6c7b649a3679cbf4556284bf7c235cad09e..25a9492eb616567aa7ad1fe7e31a00cf448d09ec 100644 (file)
  * @author Philipp Tölke
  */
 #include <platform.h>
+#include <linux/if_tun.h>
 
-#include "gnunet-vpn-tun.h"
+/**
+ * Need 'struct GNUNET_MessageHeader'.
+ */
 #include "gnunet_common.h"
-#include "gnunet_protocols.h"
-#include "gnunet-vpn-helper-p.h"
 
-#ifndef _LINUX_IN6_H
+/**
+ * Need VPN message types.
+ */
+#include "gnunet_protocols.h"
 
-#define MAX_SIZE (65535 - sizeof(struct GNUNET_MessageHeader))
+/**
+ * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ */
+#define MAX_SIZE 65536
 
-// This is in linux/include/net/ipv6.h.
-struct in6_ifreq
+#ifndef _LINUX_IN6_H
+/**
+ * This is in linux/include/net/ipv6.h, but not always exported...
+ */
+struct in6_ifreq 
 {
   struct in6_addr ifr6_addr;
   uint32_t ifr6_prefixlen;
   unsigned int ifr6_ifindex;
 };
-
 #endif
 
+
+struct suid_packet 
+{
+  struct GNUNET_MessageHeader hdr;
+  unsigned char data[1];
+}
+
 static int running = 1;
 
-static void
-term (int sig)
+static void 
+term (int sig) 
 {
-  fprintf (stderr, "Got SIGTERM...\n");
+  fprintf (stderr, 
+          "Got SIGTERM...\n");
   if (sig == SIGTERM)
     running = 0;
 }
 
+
+/**
+ * Creates a tun-interface called dev;
+ * @param dev is asumed to point to a char[IFNAMSIZ]
+ *        if *dev == '\0', uses the name supplied by the kernel
+ * @return the fd to the tun or -1 on error
+ */
+static int 
+init_tun (char *dev) 
+{
+  struct ifreq ifr;
+  int fd;
+
+  if (NULL == dev) 
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (-1 == (fd = open("/dev/net/tun", O_RDWR))) 
+    {
+      fprintf (stderr, 
+              "Error opening `%s': %s\n", 
+              "/dev/net/tun",
+              strerror(errno));
+      return -1;
+    }
+
+  memset(&ifr, 0, sizeof(ifr));
+  ifr.ifr_flags = IFF_TUN;
+
+  if ('\0' == *dev)
+    strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+
+  if (-1 == ioctl(fd, TUNSETIFF, (void *) &ifr))
+    {
+      fprintf (stderr, 
+              "Error with ioctl on `%s': %s\n", 
+              "/dev/net/tun",
+              strerror(errno));
+      close(fd);
+      return -1;
+    }
+  strcpy(dev, ifr.ifr_name);
+  return fd;
+}
+
 /**
  * @brief Sets the IPv6-Address given in address on the interface dev
  *
@@ -65,7 +129,7 @@ term (int sig)
  */
 static void
 set_address6 (char *dev, char *address, unsigned long prefix_len)
-{                              /* {{{ */
+{                          
   int fd = socket (AF_INET6, SOCK_DGRAM, 0);
 
   if (fd < 0)
@@ -111,9 +175,9 @@ set_address6 (char *dev, char *address, unsigned long prefix_len)
   ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
   (void) ioctl (fd, SIOCSIFFLAGS, &ifr);
   close (fd);
-}                              /* }}} */
+}
+
 
-static void
 /**
  * @brief Sets the IPv4-Address given in address on the interface dev
  *
@@ -121,8 +185,9 @@ static void
  * @param address the IPv4-Address
  * @param mask the netmask
  */
+static void
 set_address4 (char *dev, char *address, char *mask)
-{                              /* {{{ */
+{
   int fd = 0;
   struct sockaddr_in *addr;
   struct ifreq ifr;
@@ -175,7 +240,8 @@ set_address4 (char *dev, char *address, char *mask)
   ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
   (void) ioctl (fd, SIOCSIFFLAGS, &ifr);
   close (fd);
-}                              /* }}} */
+}
+
 
 /**
  * @brief sets the socket to nonblocking
@@ -186,22 +252,20 @@ static void
 setnonblocking (int fd)
 {                              /*{{{ */
   int opts;
+       opts = fcntl(fd,F_GETFL);
+       if (opts < 0) {
+                       perror("fcntl(F_GETFL)");
+       }
+       opts = (opts | O_NONBLOCK);
+       if (fcntl(fd,F_SETFL,opts) < 0) {
+                       perror("fcntl(F_SETFL)");
+       }
+       return;
+}
 
-  opts = fcntl (fd, F_GETFL);
-  if (opts < 0)
-    {
-      perror ("fcntl(F_GETFL)");
-    }
-  opts = (opts | O_NONBLOCK);
-  if (fcntl (fd, F_SETFL, opts) < 0)
-    {
-      perror ("fcntl(F_SETFL)");
-    }
-  return;
-}                              /*}}} */
 
-int
-main (int argc, char **argv)
+int 
+main(int argc, char** argv) 
 {
   unsigned char buf[MAX_SIZE];
 
diff --git a/src/vpn/gnunet-vpn-helper-p.h b/src/vpn/gnunet-vpn-helper-p.h
deleted file mode 100644 (file)
index fa35461..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef GN_VPN_HELPER_P_H
-#define GN_VPN_HELPER_P_H
-
-#include "platform.h"
-#include "gnunet_common.h"
-
-struct suid_packet {
-       struct GNUNET_MessageHeader hdr;
-       unsigned char data[1];
-};
-
-#endif
diff --git a/src/vpn/gnunet-vpn-tun.c b/src/vpn/gnunet-vpn-tun.c
deleted file mode 100644 (file)
index 07def09..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "platform.h"
-#include <linux/if_tun.h>
-
-/**
- * Creates a tun-interface called dev;
- * dev is asumed to point to a char[IFNAMSIZ]
- * if *dev == 0, uses the name supplied by the kernel
- * returns the fd to the tun or -1
- */
-int init_tun(char *dev) {{{
-       if (!dev) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       struct ifreq ifr;
-       int fd, err;
-
-       if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
-               fprintf(stderr, "opening /dev/net/tun: %s\n", strerror(errno));
-               return -1;
-       }
-
-       memset(&ifr, 0, sizeof(ifr));
-
-       ifr.ifr_flags = IFF_TUN;
-
-       if (*dev)
-               strncpy(ifr.ifr_name, dev, IFNAMSIZ);
-
-       if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
-               close(fd);
-               fprintf(stderr, "ioctl'ing /dev/net/tun: %s\n", strerror(errno));
-               return err;
-       }
-
-       strcpy(dev, ifr.ifr_name);
-       return fd;
-}}}
diff --git a/src/vpn/gnunet-vpn-tun.h b/src/vpn/gnunet-vpn-tun.h
deleted file mode 100644 (file)
index 3ba6177..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _GNTUN_TUN_H_
-#define _GNTUN_TUN_H_
-
-/**
- * Creates a tun-interface called dev;
- * if *dev == 0, uses the name supplied by the kernel
- * returns the fd to the tun or -1
- */
-int init_tun(char *dev);
-
-#endif