Paul Wouters 47404fc
diff -up socat-1.7.1.3/xio-tun.c.orig socat-1.7.1.3/xio-tun.c
Paul Wouters 47404fc
--- socat-1.7.1.3/xio-tun.c.orig	2011-05-19 20:25:38.654799000 +0200
Paul Wouters 47404fc
+++ socat-1.7.1.3/xio-tun.c	2011-05-19 20:37:48.675627004 +0200
Paul Wouters 47404fc
@@ -78,8 +78,8 @@ static int xioopen_tun(int argc, const c
Paul Wouters 47404fc
    char *ifaddr;
Paul Wouters 47404fc
    int result;
Paul Wouters 47404fc
 
Paul Wouters 47404fc
-   if (argc != 2) {
Paul Wouters 47404fc
-      Error2("%s: wrong number of parameters (%d instead of 1)",
Paul Wouters 47404fc
+   if (argc > 2 || argc < 0) {
Paul Wouters 47404fc
+      Error2("%s: wrong number of parameters (%d instead of 0 or 1)",
Paul Wouters 47404fc
 	     argv[0], argc-1);
Paul Wouters 47404fc
    }
Paul Wouters 47404fc
 
Paul Wouters 47404fc
@@ -146,30 +146,31 @@ static int xioopen_tun(int argc, const c
Paul Wouters 47404fc
    }
Paul Wouters 47404fc
 
Paul Wouters 47404fc
    /*--------------------- setting interface address and netmask ------------*/
Paul Wouters 47404fc
-   if ((ifaddr = strdup(argv[1])) == NULL) {
Paul Wouters 47404fc
-      Error1("strdup(\"%s\"): out of memory", argv[1]);
Paul Wouters 47404fc
-      return STAT_RETRYLATER;
Paul Wouters 47404fc
+   if (argc == 2) {
Paul Wouters 47404fc
+       if ((ifaddr = strdup(argv[1])) == NULL) {
Paul Wouters 47404fc
+          Error1("strdup(\"%s\"): out of memory", argv[1]);
Paul Wouters 47404fc
+          return STAT_RETRYLATER;
Paul Wouters 47404fc
+       }
Paul Wouters 47404fc
+       if ((result = xioparsenetwork(ifaddr, pf, &network)) != STAT_OK) {
Paul Wouters 47404fc
+          /*! recover */
Paul Wouters 47404fc
+          return result;
Paul Wouters 47404fc
+       }
Paul Wouters 47404fc
+       socket_init(pf, (union sockaddr_union *)&ifr.ifr_addr);
Paul Wouters 47404fc
+       ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr =
Paul Wouters 47404fc
+          network.netaddr.ip4.sin_addr;
Paul Wouters 47404fc
+       if (Ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
Paul Wouters 47404fc
+          Error4("ioctl(%d, SIOCSIFADDR, {\"%s\", \"%s\"}: %s",
Paul Wouters 47404fc
+             sockfd, ifr.ifr_name, ifaddr, strerror(errno));
Paul Wouters 47404fc
+       }
Paul Wouters 47404fc
+       ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr =
Paul Wouters 47404fc
+          network.netmask.ip4.sin_addr;
Paul Wouters 47404fc
+       if (Ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
Paul Wouters 47404fc
+          Error4("ioctl(%d, SIOCSIFNETMASK, {\"0x%08u\", \"%s\"}, %s",
Paul Wouters 47404fc
+             sockfd, ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr,
Paul Wouters 47404fc
+             ifaddr, strerror(errno));
Paul Wouters 47404fc
+       }
Paul Wouters 47404fc
+       free(ifaddr);
Paul Wouters 47404fc
    }
Paul Wouters 47404fc
-   if ((result = xioparsenetwork(ifaddr, pf, &network)) != STAT_OK) {
Paul Wouters 47404fc
-      /*! recover */
Paul Wouters 47404fc
-      return result;
Paul Wouters 47404fc
-   }
Paul Wouters 47404fc
-   socket_init(pf, (union sockaddr_union *)&ifr.ifr_addr);
Paul Wouters 47404fc
-   ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr =
Paul Wouters 47404fc
-      network.netaddr.ip4.sin_addr;
Paul Wouters 47404fc
-   if (Ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
Paul Wouters 47404fc
-      Error4("ioctl(%d, SIOCSIFADDR, {\"%s\", \"%s\"}: %s",
Paul Wouters 47404fc
-	     sockfd, ifr.ifr_name, ifaddr, strerror(errno));
Paul Wouters 47404fc
-   }
Paul Wouters 47404fc
-   ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr =
Paul Wouters 47404fc
-      network.netmask.ip4.sin_addr;
Paul Wouters 47404fc
-   if (Ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
Paul Wouters 47404fc
-      Error4("ioctl(%d, SIOCSIFNETMASK, {\"0x%08u\", \"%s\"}, %s",
Paul Wouters 47404fc
-	     sockfd, ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr,
Paul Wouters 47404fc
-	     ifaddr, strerror(errno));
Paul Wouters 47404fc
-   }
Paul Wouters 47404fc
-   free(ifaddr);
Paul Wouters 47404fc
-
Paul Wouters 47404fc
    /*--------------------- setting interface flags --------------------------*/
Paul Wouters 47404fc
    applyopts_single(&xfd->stream, opts, PH_FD);
Paul Wouters 47404fc