* @brief
* @author Philipp Tölke
*/
-#define _GNU_SOURCE
-#include <arpa/inet.h>
-#include <linux/if.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-
-#include <string.h>
-
-#include <signal.h>
-
-#include <stdio.h>
-#include <unistd.h>
+#include <platform.h>
#include "gnunet-vpn-tun.h"
#include "gnunet_common.h"
struct in6_ifreq {
struct in6_addr ifr6_addr;
- __u32 ifr6_prefixlen;
+ uint32_t ifr6_prefixlen;
unsigned int ifr6_ifindex;
};
/* FIXME */ ioctl(fd, SIOCGIFFLAGS, &ifr);
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
/* FIXME */ ioctl(fd, SIOCSIFFLAGS, &ifr);
+ close(fd);
} /* }}} */
static void set_address4(char* dev, char* address, char* mask) { /* {{{ */
/* FIXME */ ioctl(fd, SIOCGIFFLAGS, &ifr);
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
/* FIXME */ ioctl(fd, SIOCSIFFLAGS, &ifr);
+ close(fd);
} /* }}} */
void setnonblocking(int fd) {/*{{{*/
int fd_tun = init_tun(dev);
if (fd_tun < 0) {
- fprintf(stderr, "Could not initialize tun-interface: %m\n");
+ fprintf(stderr, "Could not initialize tun-interface: %s\n", strerror(errno));
exit(1);
}
- fprintf(stderr, "Initialized the interface %s as %d.\n", dev, fd_tun);
-
{
// TODO: get this out of argv
char address[] = "1234::1";
uid_t uid = getuid ();
if (setresuid (uid, uid, uid) != 0 )
- fprintf (stderr, "Failed to setresuid: %m\n");
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror(errno));
setnonblocking(0);
setnonblocking(1);
wri=0;
goto outer;
}
+ if(pkt->hdr.type != ntohs(GNUNET_MESSAGE_TYPE_VPN_HELPER)) abort();
while (r < ntohs(pkt->hdr.size)) {
int t = read(0, buf + r, ntohs(pkt->hdr.size) - r);
if (r < 0) {
while(r < ntohs(hdr.size)) {
int t = write(1, buf, ntohs(hdr.size) - r);
if (t < 0) {
- fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohs(hdr.size));
+ fprintf(stderr, "write-error 1: %s, written %d/%d\n", strerror(errno), r, ntohs(hdr.size));
shutdown(fd_tun, SHUT_RD);
shutdown(1, SHUT_WR);
rea = 0;
}
}
}
- fprintf(stderr, "Quitting!\n");
+
+ close(fd_tun);
return 0;
}