if (-1 == (fd = open ("/dev/net/tun", O_RDWR)))
{
- fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun",
+ fprintf (stderr,
+ "Error opening `%s': %s\n",
+ "/dev/net/tun",
strerror (errno));
return -1;
}
if (fd >= FD_SETSIZE)
{
- fprintf (stderr, "File descriptor to large: %d", fd);
+ fprintf (stderr,
+ "File descriptor to large: %d",
+ fd);
(void) close (fd);
return -1;
}
ifr.ifr_flags = IFF_TUN;
if ('\0' != *dev)
- strncpy (ifr.ifr_name, dev, IFNAMSIZ);
+ strncpy (ifr.ifr_name,
+ dev,
+ IFNAMSIZ);
- if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
+ if (-1 == ioctl (fd,
+ TUNSETIFF,
+ (void *) &ifr))
{
fprintf (stderr,
"Error with ioctl on `%s': %s\n",
* @param prefix_len the length of the network-prefix
*/
static void
-set_address6 (const char *dev, const char *address, unsigned long prefix_len)
+set_address6 (const char *dev,
+ const char *address,
+ unsigned long prefix_len)
{
struct ifreq ifr;
struct in6_ifreq ifr6;
/*
* Get the index of the if
*/
- strncpy (ifr.ifr_name, dev, IFNAMSIZ);
- if (-1 == ioctl (fd, SIOGIFINDEX, &ifr))
+ strncpy (ifr.ifr_name,
+ dev,
+ IFNAMSIZ);
+ if (-1 == ioctl (fd,
+ SIOGIFINDEX,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno));
+ fprintf (stderr,
+ "ioctl failed at %d: %s\n",
+ __LINE__,
+ strerror (errno));
(void) close (fd);
exit (1);
}
/*
* Set the address
*/
- if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6))
+ if (-1 == ioctl (fd,
+ SIOCSIFADDR,
+ &ifr6))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
/*
* Get the flags
*/
- if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
+ if (-1 == ioctl (fd,
+ SIOCGIFFLAGS,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
* Add the UP and RUNNING flags
*/
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
- if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
+ if (-1 == ioctl (fd,
+ SIOCSIFFLAGS,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
if (0 != close (fd))
{
- fprintf (stderr, "close failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "close failed: %s\n",
+ strerror (errno));
exit (1);
}
}
* @param mask the netmask
*/
static void
-set_address4 (const char *dev, const char *address, const char *mask)
+set_address4 (const char *dev,
+ const char *address,
+ const char *mask)
{
int fd;
struct sockaddr_in *addr;
/*
* Parse the address
*/
- if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr))
+ if (1 != inet_pton (AF_INET,
+ address,
+ &addr->sin_addr.s_addr))
{
fprintf (stderr,
"Failed to parse IPv4 address `%s'\n",
* Parse the netmask
*/
addr = (struct sockaddr_in *) &(ifr.ifr_netmask);
- if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr))
+ if (1 != inet_pton (AF_INET,
+ mask,
+ &addr->sin_addr.s_addr))
{
fprintf (stderr,
"Failed to parse IPv4 address mask `%s'\n",
*/
if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
if (0 != close (fd))
{
- fprintf (stderr, "close failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "close failed: %s\n",
+ strerror (errno));
(void) close (fd);
exit (1);
}
{
if (EINTR == errno)
continue;
- fprintf (stderr, "select failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "select failed: %s\n",
+ strerror (errno));
exit (1);
}
}
else if (FD_ISSET (1, &fds_w))
{
- ssize_t written = write (1, buftun_read, buftun_size);
+ ssize_t written = write (1,
+ buftun_read,
+ buftun_size);
if (-1 == written)
{
}
else if (0 == written)
{
- fprintf (stderr, "write returned 0!?\n");
+ fprintf (stderr,
+ "write returned 0!?\n");
exit (1);
}
else
hdr = (struct GNUNET_MessageHeader *) bufin;
if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER)
{
- fprintf (stderr, "protocol violation!\n");
+ fprintf (stderr,
+ "protocol violation!\n");
exit (1);
}
if (ntohs (hdr->size) > bufin_rpos)
}
else if (FD_ISSET (fd_tun, &fds_w))
{
- ssize_t written = write (fd_tun, bufin_read, bufin_size);
+ ssize_t written = write (fd_tun,
+ bufin_read,
+ bufin_size);
if (-1 == written)
{
- fprintf (stderr, "write-error to tun: %s\n", strerror (errno));
+ fprintf (stderr,
+ "write-error to tun: %s\n",
+ strerror (errno));
shutdown (0, SHUT_RD);
shutdown (fd_tun, SHUT_WR);
write_open = 0;
return 1;
}
- strncpy (dev, argv[1], IFNAMSIZ);
+ strncpy (dev,
+ argv[1],
+ IFNAMSIZ);
dev[IFNAMSIZ - 1] = '\0';
if (-1 == (fd_tun = init_tun (dev)))
{
- fprintf (stderr, "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n",
+ fprintf (stderr,
+ "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n",
dev,
argv[2],
argv[3],
if ((prefix_len < 1) || (prefix_len > 127))
{
- fprintf (stderr, "Fatal: prefix_len out of range\n");
+ fprintf (stderr,
+ "Fatal: prefix_len out of range\n");
return 1;
}
- set_address6 (dev, address, prefix_len);
+ set_address6 (dev,
+ address,
+ prefix_len);
}
if (0 != strcmp (argv[4], "-"))
#ifdef HAVE_SETRESUID
if (0 != setresuid (uid, uid, uid))
{
- fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ fprintf (stderr,
+ "Failed to setresuid: %s\n",
+ strerror (errno));
global_ret = 2;
goto cleanup;
}
#else
if (0 != (setuid (uid) | seteuid (uid)))
{
- fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ fprintf (stderr,
+ "Failed to setuid: %s\n",
+ strerror (errno));
global_ret = 2;
goto cleanup;
}
if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
{
- fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
+ fprintf (stderr,
+ "Failed to protect against SIGPIPE: %s\n",
strerror (errno));
/* no exit, we might as well die with SIGPIPE should it ever happen */
}