From: Christian Grothoff Date: Wed, 19 Jan 2011 08:30:52 +0000 (+0000) Subject: breaking-indent X-Git-Tag: initial-import-from-subversion-38251~19302 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=44c0b27c863ec264661235c881f79d509c138eef;p=oweals%2Fgnunet.git breaking-indent --- diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 9100fd900..f1b0e1df7 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am @@ -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 diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c index c2ebe6c7b..25a9492eb 100644 --- a/src/vpn/gnunet-helper-vpn.c +++ b/src/vpn/gnunet-helper-vpn.c @@ -26,36 +26,100 @@ * @author Philipp Tölke */ #include +#include -#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 index fa3546123..000000000 --- a/src/vpn/gnunet-vpn-helper-p.h +++ /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 index 07def09c7..000000000 --- a/src/vpn/gnunet-vpn-tun.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "platform.h" -#include - -/** - * 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 index 3ba61771a..000000000 --- a/src/vpn/gnunet-vpn-tun.h +++ /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