From: Roger Wolff Date: Sat, 31 Oct 1998 00:00:00 +0000 (+0000) Subject: mtr v0.26 X-Git-Tag: v0.26^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a5c77ca115b3ea76aa6e9595e0d6e8c220a7e9b;p=thirdparty%2Fmtr.git mtr v0.26 - Added "-n" flag for numeric output. - Fixed IP numbers displaying backwards. - GTK mainloop now runs at 10 packets per second. -- That's too much if there are only 3 hosts -- that's too little if there are 20 hosts. -- Someone tell me how to change the "ping-timeout" callback time in gtk. Can't find it in the docs. - The default for "hostname" is now "localhost" so that you can start mtr without any arguments and later fill in the host you want to trace to. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.26.tar.gz --- diff --git a/AUTHORS b/AUTHORS index a52bb4c..d8dd1ea 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,9 +9,10 @@ Thanks to everyone who has provided feedback on mtr. - Thanks especially to those of you who have sent me code: + Thanks especially to those of you who have sent code: Brian Casey, Mircea Damian, Christophe Kalt, Simon Kirby, - Anand Kumria, Charles Levert, Russell Nelson, - Aaron Scarisbrick, Andrew Stesin, Juha Takala, Rogier Wolff + Anand Kumria, Bertrand Leconte, Charles Levert, Alexander + V. Lukyanov, Russell Nelson, Aaron Scarisbrick, Andrew + Stesin, Juha Takala. and anyone who has slipped through the cracks of my mail file. diff --git a/NEWS b/NEWS index 8d938db..f28612b 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,16 @@ WHAT'S NEW? + v0.26 + Added "-n" flag for numeric output. + fixed IP numbers displaying backwards. + GTK mainloop now runs at 10 packets per second. + - That's too much if there are only 3 hosts + - that's too little if there are 20 hosts. + -> Someone tell me how to change the "ping-timeout" + callback time in gtk. Can't find it in the docs. + The default for "hostname" is now "localhost" so that + you can start mtr without any arguments and later + fill in the host you want to trace to. v0.25 Included two "raw" formats. One for separating GUI from diff --git a/TODO b/TODO index 1277e76..0d40681 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,8 @@ - Stuff to implement: - Allow mtr to log the return packets, for later analysis. + Done: 0.25 . Todo: allow the userinterface(s) to work while + still logging to a file. - Request timestamping at the remote site. Andreas Fasbender has an algorithm that will allow us to diff --git a/configure.in b/configure.in index 8f9c701..1fcb9b3 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.25) +AM_INIT_AUTOMAKE(mtr, 0.26) AC_SUBST(GTK_OBJ) AC_SUBST(CURSES_OBJ) diff --git a/dns.c b/dns.c index e41ad4a..11143c4 100644 --- a/dns.c +++ b/dns.c @@ -51,6 +51,9 @@ extern char *sys_errlist[]; /* Hmm, it seems Irix requires this */ extern int errno; +/* Defined in mtr.c */ +extern int dns; + /* Defines */ #undef Debug @@ -387,7 +390,7 @@ void clearset(fd_set *set){ char *strlongip(ip_t ip){ struct in_addr a; - a.s_addr = ip; + a.s_addr = htonl(ip); return inet_ntoa(a); } @@ -1174,6 +1177,7 @@ char *dns_lookup2(ip_t ip){ char *dns_lookup(ip_t ip){ char *t; + if (!dns) return strlongip (ip); t = dns_lookup2 (ip); return t?t:strlongip(ip); } diff --git a/dns.h b/dns.h index 3af73e4..6322840 100644 --- a/dns.h +++ b/dns.h @@ -26,3 +26,4 @@ void dns_events(double *sinterval); char *dns_lookup(int address); char *dns_lookup2(int address); int dns_forward(char *name); +char *strlongip (int address); diff --git a/gtk.c b/gtk.c index 8fd7fed..ea26672 100644 --- a/gtk.c +++ b/gtk.c @@ -1,6 +1,7 @@ /* mtr -- a network diagnostic tool Copyright (C) 1997,1998 Matt Kimball + Changes/additions Copyright (C) 1998 R.E.Wolff@BitWizard.nl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,6 +19,7 @@ */ #include +#include #ifndef NO_GTK #include @@ -32,6 +34,7 @@ extern char *Hostname; extern float WaitTime; +extern float DeltaTime; void gtk_do_init(int *argc, char ***argv) { static int done = 0; @@ -127,9 +130,9 @@ GtkWidget *GetRow(int index) { if(addr != 0) { name = dns_lookup(addr); if(!name) { - sprintf(str, "%d.%d.%d.%d", (addr >> 24) & 0xff, (addr >> 16) & 0xff, - (addr >> 8) & 0xff, addr & 0xff); - name = str; + /* Actually this is not neccesary: + dns_lookup always returns a printable string */ + name = strlongip (addr); } } @@ -245,7 +248,7 @@ void Window_fill(GtkWidget *Window) { GtkWidget *Toolbar; GtkWidget *List; - gtk_window_set_title(GTK_WINDOW(Window), "Matt's traceroute [v" VERSION "]"); + gtk_window_set_title(GTK_WINDOW(Window), "My traceroute [v" VERSION "]"); gtk_widget_set_usize(Window, 540, 400); gtk_container_border_width(GTK_CONTAINER(Window), 10); VBox = gtk_vbox_new(FALSE, 10); @@ -302,7 +305,6 @@ int gtk_keyaction() { gint gtk_ping(gpointer data) { gtk_redraw(); net_send_batch(); - return TRUE; } @@ -316,8 +318,10 @@ void gtk_dns_data(gpointer data, gint fd, GdkInputCondition cond) { gtk_redraw(); } + void gtk_loop() { - gtk_timeout_add((int)(1000.0 * WaitTime), gtk_ping, NULL); + DeltaTime = WaitTime/10; + gtk_timeout_add(DeltaTime*1000, gtk_ping, NULL); gdk_input_add(net_waitfd(), GDK_INPUT_READ, gtk_net_data, NULL); gdk_input_add(dns_waitfd(), GDK_INPUT_READ, gtk_dns_data, NULL); diff --git a/mtr.8 b/mtr.8 index 0261293..4f01de6 100644 --- a/mtr.8 +++ b/mtr.8 @@ -32,6 +32,9 @@ mtr \- a network diagnostic tool .B \-\-raw\c ] [\c +.B \-\-no-dns\c +] +[\c .B \-\-gtk\c ] [\c @@ -123,6 +126,16 @@ Use this option to force to use the curses based terminal interface (if available). +.TP +.B \-n +.TP +.B \-\-no-dns +.br +Use this option to force +.B mtr +to display numeric IP numbers and not try to resolve the +host names. + .TP .B \-g .TP diff --git a/mtr.c b/mtr.c index 1315f8e..8c1bb9f 100644 --- a/mtr.c +++ b/mtr.c @@ -37,6 +37,7 @@ int PrintHelp = 0; int MaxPing = 16; float WaitTime = 1.0; char *Hostname = NULL; +int dns = 1; void parse_arg(int argc, char **argv) { int opt; @@ -48,6 +49,7 @@ void parse_arg(int argc, char **argv) { { "curses", 0, 0, 't' }, { "gtk", 0, 0, 'g' }, { "interval", 1, 0, 'i' }, + { "no-dns", 0, 0, 'n' }, { "split", 0, 0, 's' }, /* BL */ { "raw", 0, 0, 'l' }, { 0, 0, 0, 0 } @@ -55,7 +57,7 @@ void parse_arg(int argc, char **argv) { opt = 0; while(1) { - opt = getopt_long(argc, argv, "hvrc:tklsi:", long_options, NULL); + opt = getopt_long(argc, argv, "hvrc:tklnsi:", long_options, NULL); if(opt == -1) break; @@ -84,11 +86,14 @@ void parse_arg(int argc, char **argv) { case 'l': DisplayMode = DisplayRaw; break; + case 'n': + dns = 0; + break; case 'i': WaitTime = atof(optarg); if (WaitTime <= 0.0) { fprintf (stderr, "mtr: wait time must be positive\n"); - exit (-1); + exit (1); } break; } @@ -107,23 +112,22 @@ void parse_arg(int argc, char **argv) { int main(int argc, char **argv) { int traddr; struct hostent *host; + int net_preopen_result; /* Get the raw sockets first thing, so we can drop to user euid immediately */ - if(net_preopen() != 0) { - printf("mtr: Unable to get raw socket. (Executable not suid?)\n"); - exit(0); - } + + net_preopen_result = net_preopen (); /* Now drop to user permissions */ if(seteuid(getuid())) { printf("mtr: Unable to drop permissions.\n"); - exit(0); + exit(1); } /* Double check, just in case */ if(geteuid() != getuid()) { printf("mtr: Unable to drop permissions.\n"); - exit(0); + exit(1); } display_detect(&argc, &argv); @@ -134,13 +138,20 @@ int main(int argc, char **argv) { exit(0); } - if(Hostname == NULL || PrintHelp) { + if(PrintHelp) { printf("usage: %s [-hvrctlis] [--help] [--version] [--report]\n" "\t\t[--report-cycles=COUNT] [--curses] [--gtk]\n" "\t\t[--raw] [--split]\n" /* BL */ "\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]); exit(0); } + if (Hostname == NULL) Hostname = "localhost"; + + if(net_preopen_result != 0) { + printf("mtr: Unable to get raw socket. (Executable not suid?)\n"); + exit(1); + } + host = gethostbyname(Hostname); if(host == NULL) { @@ -149,14 +160,14 @@ int main(int argc, char **argv) { #else printf("mtr: error looking up \"%s\"\n", Hostname); #endif - exit(0); + exit(1); } traddr = *(int *)host->h_addr; if(net_open(traddr) != 0) { printf("mtr: Unable to get raw socket. (Executable not suid?)\n"); - exit(0); + exit(1); } display_open(); diff --git a/net.c b/net.c index 3d4c252..fb4d80d 100644 --- a/net.c +++ b/net.c @@ -29,9 +29,14 @@ #include #include #include +#include +#include #include "net.h" + +extern float WaitTime, DeltaTime; + #define MaxTransit 4 /* We can't rely on header files to provide this information, because @@ -341,10 +346,6 @@ void net_end_transit() { } -extern float WaitTime; -extern struct timeval intervaltime; -#include -#include int net_send_batch() { static int n_unknown = 10; @@ -359,10 +360,7 @@ int net_send_batch() { if ((host[at].addr == remoteaddress.sin_addr.s_addr) || (n_unknown == 0)) { - float wt = WaitTime / (float) at; - - intervaltime.tv_sec = (int)(wt); - intervaltime.tv_usec = 1000000.0 * (wt - floor(wt)); + DeltaTime = WaitTime / (float) (at+1); at = 0; n_unknown = 10; return 1; @@ -377,7 +375,7 @@ int net_preopen() { int trueopt = 1; sendsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); - if(sendsock == -1) + if(sendsock < 0) return -1; #ifdef IP_HDRINCL @@ -391,8 +389,8 @@ int net_preopen() { #endif recvsock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); - if(recvsock == -1) - return -1; + if(recvsock < 0) + return -1; return 0; } @@ -416,6 +414,7 @@ void net_reopen(int addr) { remoteaddress.sin_family = AF_INET; remoteaddress.sin_addr.s_addr = addr; + net_reset (); net_send_batch(); } diff --git a/select.c b/select.c index b79cfe6..193ecd6 100644 --- a/select.c +++ b/select.c @@ -32,9 +32,10 @@ extern int Interactive; extern int MaxPing; extern float WaitTime; +float DeltaTime; double dnsinterval; -struct timeval intervaltime; +static struct timeval intervaltime; void select_loop() { fd_set readfd; @@ -48,11 +49,12 @@ void select_loop() { NumPing = 0; anyset = 0; gettimeofday(&lasttime, NULL); - wt = WaitTime/10; - intervaltime.tv_sec = (int)wt; - intervaltime.tv_usec = 1000000.0 * (wt - floor(wt)); + DeltaTime = WaitTime/10; while(1) { + intervaltime.tv_sec = DeltaTime; + intervaltime.tv_usec = 1000000 *( DeltaTime - floor (DeltaTime)); + FD_ZERO(&readfd); maxfd = 0;