From: Roger Wolff Date: Fri, 29 Sep 2006 00:00:00 +0000 (+0000) Subject: mtr v0.72 X-Git-Tag: v0.72^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a8c1d0d5978c2fd4f8ec304564956f1d0c3936c9;p=thirdparty%2Fmtr.git mtr v0.72 - Fix signed/unsigned bug in IPV6 part improved random packet size behaviour. --REW source: ftp://ftp.bitwizard.nl/mtr/mtr-0.72.tar.gz --- diff --git a/configure.in b/configure.in index b1563ef..9e3bd52 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.71) +AM_INIT_AUTOMAKE(mtr, 0.72) AC_SUBST(GTK_OBJ) diff --git a/curses.c b/curses.c index a2c9272..03157a2 100644 --- a/curses.c +++ b/curses.c @@ -70,7 +70,7 @@ extern char LocalHostname[]; extern int fstTTL; extern int maxTTL; -extern int packetsize; +extern int cpacketsize; extern int bitpattern; extern int tos; extern float WaitTime; @@ -118,8 +118,8 @@ int mtr_curses_keyaction(void) /* more stuffs added by Min */ if (tolower(c) == 's') { - mvprintw(2, 0, "Change Packet Size: %d\n", packetsize ); - mvprintw(3, 0, "Size Range: %d-%d, <0 random.\n", MINPACKET, MAXPACKET); + mvprintw(2, 0, "Change Packet Size: %d\n", cpacketsize ); + mvprintw(3, 0, "Size Range: %d-%d, < 0:random.\n", MINPACKET, MAXPACKET); move(2,20); refresh(); while ( (c=getch ()) != '\n' && i < MAXFLD ) { @@ -127,15 +127,7 @@ int mtr_curses_keyaction(void) buf[i++] = c; /* need more checking on 'c' */ } buf[i] = '\0'; - packetsize = atoi ( buf ); - if( packetsize >=0 ) { - if ( packetsize < MINPACKET ) packetsize = MINPACKET; - if ( packetsize > MAXPACKET ) packetsize = MAXPACKET; - } else { - packetsize = - - (int)(MINPACKET + (MAXPACKET-MINPACKET)*(rand()/(RAND_MAX+0.1))); - } - + cpacketsize = atoi ( buf ); return ActionNone; } if (tolower(c) == 'b') { @@ -498,12 +490,12 @@ void mtr_curses_redraw(void) mvprintw(1, 0, "%s (%s)", LocalHostname, net_localaddr()); /* printw("(tos=0x%X ", tos); - printw("psize=%d ", abs(packetsize) ); + printw("psize=%d ", packetsize ); printw("bitpattern=0x%02X)", (unsigned char)(abs(bitpattern))); - if( packetsize>0 ){ - printw("psize=%d ", packetsize); + if( cpacketsize > 0 ){ + printw("psize=%d ", cpacketsize); } else { - printw("psize=rand(%d,%d) ",MINPACKET, MAXPACKET); + printw("psize=rand(%d,%d) ",MINPACKET, -cpacketsize); } if( bitpattern>=0 ){ printw("bitpattern=0x%02X)", (unsigned char)(bitpattern)); diff --git a/dns.c b/dns.c index ada3ab2..ef3e518 100644 --- a/dns.c +++ b/dns.c @@ -1357,7 +1357,7 @@ char *dns_lookup(ip_t * ip) #ifdef ENABLE_IPV6 /* Returns an ip6.arpa character string. */ void addr2ip6arpa( ip_t * ip, char * buf ) { - char * p = (char *) ip; + unsigned char * p = (unsigned char *) ip; char * b = buf; int i; diff --git a/mtr.8 b/mtr.8 index af67d7f..d7b297d 100644 --- a/mtr.8 +++ b/mtr.8 @@ -132,6 +132,9 @@ those machines. Each cycle lasts one second. These options or a trailing PACKETSIZE on the commandline sets the packet size used for probing. It is in bytes inclusive IP and ICMP headers + +If set to a negative number, every iteration will use a different, random +packetsize upto that number. .TP .B \-t .TP diff --git a/mtr.c b/mtr.c index 4b32c16..40ae11b 100644 --- a/mtr.c +++ b/mtr.c @@ -61,7 +61,7 @@ char *Hostname = NULL; char *InterfaceAddress = NULL; char LocalHostname[128]; int dns = 1; -int packetsize = 64; /* default packet size */ +int cpacketsize = 64; /* default packet size */ int bitpattern = 0; int tos = 0; int af = DEFAULT_AF; @@ -188,11 +188,7 @@ void parse_arg (int argc, char **argv) ForceMaxPing = 1; break; case 's': - packetsize = atoi (optarg); - if (packetsize >=0) { - if (packetsize < MINPACKET) packetsize = MINPACKET; - if (packetsize > MAXPACKET) packetsize = MAXPACKET; - } + cpacketsize = atoi (optarg); break; case 'a': InterfaceAddress = optarg; @@ -284,11 +280,7 @@ void parse_arg (int argc, char **argv) Hostname = argv[optind++]; if (argc > optind) { - packetsize = atoi (argv[optind]); - if (packetsize >=0 ) { - if (packetsize < MINPACKET) packetsize = MINPACKET; - if (packetsize > MAXPACKET) packetsize = MAXPACKET; - } + cpacketsize = atoi (argv[optind]); } } diff --git a/net.c b/net.c index 2a4b462..327f35d 100644 --- a/net.c +++ b/net.c @@ -170,7 +170,8 @@ static int numhosts = 10; extern int fstTTL; /* initial hub(ttl) to ping byMin */ extern int maxTTL; /* last hub to ping byMin*/ -extern int packetsize; /* packet size used by ping */ +extern int cpacketsize; /* packet size used by ping */ +static int packetsize; /* packet size used by ping */ extern int bitpattern; /* packet bit pattern used by ping */ extern int tos; /* type of service set in ping packet*/ extern int af; /* address family of remote target */ @@ -697,15 +698,27 @@ int net_send_batch(void) bitpattern<0. abs(packetsize) and/or abs(bitpattern) will be used */ if( batch_at < fstTTL ) { - if( packetsize < 0 ) { - packetsize = - - (int)(MINPACKET + (MAXPACKET-MINPACKET)*(rand()/(RAND_MAX+0.1))); + if( cpacketsize < 0 ) { + /* Someone used a formula here that tried to correct for the + "end-error" in "rand()". By "end-error" I mean that if you + have a range for "rand()" that runs to 32768, and the + destination range is 10000, you end up with 4 out of 32768 + 0-2768's and only 3 out of 32768 for results 2769 .. 9999. + As our detination range (in the example 10000) is much + smaller (reasonable packet sizes), and our rand() range much + larger, this effect is insignificant. Oh! That other formula + didn't work. -- REW */ + packetsize = MINPACKET + rand () % (-cpacketsize - MINPACKET); + } else { + packetsize = cpacketsize; } if( bitpattern < 0 ) { bitpattern = - (int)(256 + 255*(rand()/(RAND_MAX+0.1))); } } + /* printf ("cpacketsize = %d, packetsize = %d\n", cpacketsize, packetsize); */ + net_send_query(batch_at); for (i=fstTTL-1;i=0 ){ - printf(" PSIZE=%d", packetsize); + if(cpacketsize >= 0) { + printf(" PSIZE=%d", cpacketsize); } else { - printf(" PSIZE=rand(%d-%d)",MINPACKET, MAXPACKET); + printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern)); @@ -206,10 +206,10 @@ void csv_close(void) /* Caption */ printf("=0 ){ - printf(" PSIZE=%d", packetsize); + if(cpacketsize >= 0) { + printf(" PSIZE=%d", cpacketsize); } else { - printf(" PSIZE=rand(%d-%d)",MINPACKET, MAXPACKET); + printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern));