chiark / gitweb /
Found in chiark:/etc/userv/services.d/www-cgi
[userv-utils.git] / ipif / udptunnel
index 7c977e172f6e7b9eb1a23abace21fa938426e922..1b5031c7d2f1f2e3406e0a4bbb21a8ddaec865ff 100755 (executable)
@@ -215,7 +215,7 @@ for (;;) {
            quit "tunnel endpoint closed by system";
        }
        while (($p= index($upbuf,"\300")) >= 0) {
-           if (!defined(send L,substr($upbuf,0,$p+1),0,$rs)) {
+           if ($p && !defined(send L,substr($upbuf,0,$p),0,$rs)) {
                warning("transmit error: $!");
            } else {
                if (!$upyet) {
@@ -233,6 +233,7 @@ for (;;) {
            warning("got packet from incorrect peer $rsp_from");
            next;
        }
+       $downbuf= "\300".$downbuf."\300";
        if (!defined($r= syswrite(DW,$downbuf,length $downbuf))) {
            warning("tunnel endpoint write error: $!");
        } elsif ($r != length $downbuf) {
@@ -245,5 +246,6 @@ for (;;) {
            alarm($timeout) if $timeout;
        }
     }
+    if ($! == ECONNREFUSED) { quit("tunnel closed at remote end"); }
     $! == EAGAIN || warning("receive error: $!");
 }