for w32 port
[oweals/gnunet.git] / src / vpn / gnunet-helper-vpn.c
index 00ac1b0eccc363523b942bdd522261fdcc51e392..4a367e9c9af87809a5d80b80e0be5aaf208139a5 100644 (file)
@@ -82,6 +82,7 @@ static void set_address6(char* dev, char* address, unsigned long prefix_len) { /
        /* 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) { /* {{{ */
@@ -123,6 +124,7 @@ 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) {/*{{{*/
@@ -150,12 +152,10 @@ int main(int argc, char** argv) {
        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";
@@ -173,7 +173,7 @@ int main(int argc, char** argv) {
 
        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);
@@ -221,6 +221,7 @@ outer:
                                        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) {
@@ -270,7 +271,7 @@ outer:
                                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;
@@ -281,7 +282,8 @@ outer:
                        }
                }
        }
-       fprintf(stderr, "Quitting!\n");
+
+       close(fd_tun);
 
        return 0;
 }