add a packet timeout option to traceroute. I use this when doing hundreds of traceroutes to map our corperate network (with a little help from graphviz). Setting a small timeout, where I know the network is fast, speeds up the mapping as some hosts are inevitably unavailable. -Steve Reference: /n/sources/patch/maybe/trcrt-tmout Date: Wed Mar 3 13:59:55 CET 2010 Signed-off-by: steve@quintile.net --- /sys/src/cmd/ip/traceroute.c Wed Mar 3 13:55:26 2010 +++ /sys/src/cmd/ip/traceroute.c Wed Mar 3 13:55:24 2010 @@ -29,7 +29,7 @@ usage(void) { fprint(2, -"usage: %s [-n][-a tries][-h buckets][-t ttl][-x net] [protocol!]destination\n", +"usage: %s [-a tries][-h buckets][-l port][-n][-t ttl][-x net][-T tout] [[proto!]destination!port]\n", argv0); exits("usage"); } @@ -118,7 +118,7 @@ * to try dialing. resending is up to it. */ static int -tcpilprobe(int cfd, int dfd, char *dest, int interval) +tcpilprobe(int cfd, int dfd, int local, char *dest, int interval) { int n; char msg[Maxstring]; @@ -126,6 +126,8 @@ USED(dfd); n = snprint(msg, sizeof msg, "connect %s", dest); + if(local) + n += snprint(msg+n, sizeof(msg)-n, " %d", local); alarm(interval); n = write(cfd, msg, n); alarm(0); @@ -137,7 +139,7 @@ * till we timeout or someone complains */ static int -udpprobe(int cfd, int dfd, char *dest, int interval) +udpprobe(int cfd, int dfd, int local, char *dest, int interval) { int n, i, rv; char msg[Maxstring]; @@ -145,6 +147,9 @@ seek(cfd, 0, 0); n = snprint(msg, sizeof msg, "connect %s", dest); + if(local) + n += snprint(msg+n, sizeof(msg)-n, " %d", local); +print("%s\n", msg); if(write(cfd, msg, n)< 0) return -1; @@ -242,7 +247,7 @@ } static int -call(DS *ds, char *clone, char *dest, int ttl, long *interval) +call(DS *ds, char *clone, int local, char *dest, int ttl, long *interval, int tout) { int cfd, dfd, rv, n; char msg[Maxstring]; @@ -280,11 +285,11 @@ /* probe */ if(strcmp(ds->proto, "udp") == 0) - rv = udpprobe(cfd, dfd, dest, 3000); + rv = udpprobe(cfd, dfd, local, dest, tout); else if(strcmp(ds->proto, "icmp") == 0) - rv = icmpprobe(cfd, dfd, dest, 3000); + rv = icmpprobe(cfd, dfd, dest, tout); else /* il and tcp */ - rv = tcpilprobe(cfd, dfd, dest, 3000); + rv = tcpilprobe(cfd, dfd, local, dest, tout); out: /* turn off alarms */ alarm(0); @@ -332,7 +337,7 @@ void main(int argc, char **argv) { - int buckets, ttl, j, done, tries, notranslate; + int tout, local, buckets, ttl, j, done, tries, notranslate; long lo, hi, sum, x; long *t; char *net, *p; @@ -340,12 +345,17 @@ char err[Maxstring]; DS ds; + local = 0; buckets = 0; tries = 3; notranslate = 0; net = "/net"; ttl = 1; + tout = 3000; ARGBEGIN{ + case 'l': + local = atoi(EARGF(usage())); + break; case 'a': tries = atoi(EARGF(usage())); break; @@ -361,6 +371,9 @@ case 't': ttl = atoi(EARGF(usage())); break; + case 'T': + tout = atoi(EARGF(usage())); + break; case 'x': net = EARGF(usage()); break; @@ -389,7 +402,7 @@ done = 0; for(; ttl < 32; ttl++){ for(j = 0; j < tries; j++){ - if(call(&ds, clone, dest, ttl, &t[j]) >= 0){ + if(call(&ds, clone, local, dest, ttl, &t[j], tout) >= 0){ if(debug) print("%ld %s\n", t[j], dest); strcpy(hop, dest); --- /sys/man/8/ping Wed Mar 3 13:55:29 2010 +++ /sys/man/8/ping Wed Mar 3 13:55:27 2010 @@ -46,6 +46,9 @@ ][ .B -t .I sttl +][ +.B -T +.I tout ] .I dest .PP @@ -181,6 +184,11 @@ contains .I nbuck buckets. +.TP +.B T +set the timeout for packets to +.I tout +(default 3000 milliseconds). .PD .PP .I Hogports