* @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;
};
running = 0;
}
-static void set_address(char* dev, char* address, unsigned long prefix_len) { /* {{{ */
+static void set_address6(char* dev, char* address, unsigned long prefix_len) { /* {{{ */
int fd = socket(AF_INET6, SOCK_DGRAM, 0);
struct ifreq ifr;
/* 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) { /* {{{ */
+ int fd=0;
+ struct sockaddr_in* addr;
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(struct ifreq));
+ addr = (struct sockaddr_in *)&(ifr.ifr_addr);
+ memset(addr, 0, sizeof(struct sockaddr_in));
+ addr->sin_family = AF_INET;
+ addr->sin_addr.s_addr = inet_addr(address);
+
+ /* FIXME */ inet_pton(AF_INET, address, &addr->sin_addr.s_addr);
+
+ fd = socket(PF_INET, SOCK_DGRAM, 0);
+ if(fd < 0) {
+ perror("socket()");
+ return;
+ }
+
+ strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+
+ if(ioctl(fd, SIOCSIFADDR, &ifr) != 0 ) {
+ perror("SIOCSIFADDR");
+ close(fd);
+ return;
+ }
+
+ addr = (struct sockaddr_in*)&(ifr.ifr_netmask);
+ /* FIXME */ inet_pton(AF_INET, mask, &addr->sin_addr.s_addr);
+
+ if(ioctl(fd, SIOCSIFNETMASK, &ifr) != 0 ) {
+ perror("SIOCSIFNETMASK");
+ close(fd);
+ return;
+ }
+
+ /* 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";
unsigned long prefix_len = 16;
- set_address(dev, address, prefix_len);
+ set_address6(dev, address, prefix_len);
+ }
+
+ {
+ char address[] = "10.10.10.1";
+ char mask[] = "255.255.255.252";
+
+ set_address4(dev, address, mask);
+ }
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;
}