pathmtu: Reset the timeout on each packet.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 3 Jan 2009 20:35:29 +0000 (20:35 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Jan 2009 20:35:29 +0000 (20:35 +0000)
Linux actually has the correct behaviour and updates the timeout
argument to reflect the time remaining.  Unfortunately we don't actually
want to do that.  So reset it each time.

pathmtu/pathmtu.c

index acc8837..c86397f 100644 (file)
@@ -90,9 +90,9 @@ static int pathmtu(struct sockaddr_in *sin, double to)
   int mtu;
   int i;
   size_t sz;
-  struct timeval tv;
+  struct timeval tv, tvproto;
 
-  tv.tv_sec = to; tv.tv_usec = (to - tv.tv_sec) * 1000000;
+  tvproto.tv_sec = to; tvproto.tv_usec = (to - tvproto.tv_sec) * 1000000;
   if ((sk = socket(PF_INET, SOCK_DGRAM, 0)) < 0) goto fail_0;
   i = IP_PMTUDISC_DO;
   if (setsockopt(sk, SOL_IP, IP_MTU_DISCOVER, &i, sizeof(i)))
@@ -102,7 +102,7 @@ static int pathmtu(struct sockaddr_in *sin, double to)
     sz = sizeof(mtu);
     if (getsockopt(sk, SOL_IP, IP_MTU, &mtu, &sz)) goto fail_1;
     if (write(sk, buf, mtu - 28) < 0) goto fail_1;
-    FD_SET(sk, &fd_in);
+    FD_SET(sk, &fd_in); tv = tvproto;
     if (select(sk + 1, &fd_in, 0, 0, &tv) < 0) goto fail_1;
     if (!FD_ISSET(sk, &fd_in)) break;
     if (read(sk, &i, 1) >= 0 ||