chiark / gitweb /
Bugfixes - works now.
authorian <ian>
Sat, 25 Sep 1999 01:12:14 +0000 (01:12 +0000)
committerian <ian>
Sat, 25 Sep 1999 01:12:14 +0000 (01:12 +0000)
ipif/udptunnel

index dff18ed..a40dce0 100755 (executable)
@@ -175,17 +175,17 @@ if ($keepalive) { $nextsendka= now(); }
 for (;;) {
     if ($keepalive) {
        $now= now();
-       $timeout= $nextsendka-$now;
-       if ($timeout < 0) {
+       $thistimeout= $nextsendka-$now;
+       if ($thistimeout < 0) {
            defined(send L,"\300",0,$rs)
                or warning("transmit keepalive error: $!");
            $nextsendka= $now+$keepalive;
-           $timeout= $keepalive;
+           $thistimeout= $keepalive;
        }
     } else {
-       $timeout= undef;
+       $thistimeout= undef;
     }
-    select($readfds=$wantreadfds,'','',$timeout);
+    select($readfds=$wantreadfds,'','',$thistimeout);
     for (;;) {
        if (!defined($r= sysread(UR,$upbuf,$mtu*2+3,length($upbuf)))) {
            $! == EAGAIN || warning("tunnel endpoint read error: $!");
@@ -195,13 +195,16 @@ for (;;) {
            quit "tunnel endpoint closed by system";
        }
        while (($p= index($upbuf,"\300")) >= 0) {
-           if (!defined(send L,substr($upbuf,0,$p),0,$rs)) {
+           if (!defined(send L,substr($upbuf,0,$p+1),0,$rs)) {
                warning("transmit error: $!");
-           } elsif (!$upyet) {
-               $upyet= 1;
-               debug($downyet ? "tunnel open at this end" : "transmit channel open");
+           } else {
+               if (!$upyet) {
+                   $upyet= 1;
+                   debug($downyet ? "tunnel open at this end" : "transmitting");
+               }
+               if ($keepalive) { $nextsendka= now()+$keepalive; }
            }
-           $upbuf= substr($upbuf+1,$p);
+           $upbuf= substr($upbuf,$p+1);
        }
     }
     while (defined($rs_from= recv L,$downbuf,$mtu*2+3,0)) {
@@ -217,7 +220,7 @@ for (;;) {
        } else {
            if (!$downyet) {
                $downyet= 1;
-               debug($upyet ? "tunnel open at this end" : "receive channel open");
+               debug($upyet ? "tunnel open at this end" : "receiving");
            }
            alarm($timeout) if $timeout;
        }