From: Roger Wolff Date: Sun, 11 Apr 1999 00:00:00 +0000 (+0000) Subject: mtr v0.36 X-Git-Tag: v0.36^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=88c750cbfbed80580f70f7bc487a0f50a27b0200;p=thirdparty%2Fmtr.git mtr v0.36 - Added Craigs change-the-interval-on-the-fly patch. - Added Moritz Barsnick's "do something sensible if host not found" patch. - Some cleanup of both Craigs and Moritz' patches. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.36.tar.gz --- diff --git a/AUTHORS b/AUTHORS index ba73271..f5076ab 100644 --- a/AUTHORS +++ b/AUTHORS @@ -28,6 +28,7 @@ Steve Kann (stevek@spheara.horizonlive.com), Mircea Damian, Brian Casey, + Moritz Barsnick (barsnick@gmx.net) and anyone who has slipped through the cracks of my mail file. diff --git a/NEWS b/NEWS index 9a4e637..873e5c2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ WHAT'S NEW? + v0.36 Added Craigs change-the-interval-on-the-fly patch. + Added Moritz Barsnick's "do something sensible if host not found" + patch. + Some cleanup of both Craigs and Moritz' patches. + v0.35 Added Craig Milo Rogers pause/resume for GTK patch. Added Craig Milo Rogers cleanup of "reset". (restart at the beginning) Net_open used to send a first packet. After that the display-driver diff --git a/configure.in b/configure.in index a7f745d..c68563d 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.35) +AM_INIT_AUTOMAKE(mtr, 0.36) AC_SUBST(GTK_OBJ) AC_SUBST(CURSES_OBJ) diff --git a/gtk.c b/gtk.c index dff4d62..bc9fcd3 100644 --- a/gtk.c +++ b/gtk.c @@ -32,11 +32,24 @@ #include "img/mtr_icon.xpm" #endif + +gint gtk_ping(gpointer data); + + extern char *Hostname; extern float WaitTime; -extern float DeltaTime; - static int tag; +static GtkWidget *Pause_Button; + + +void gtk_add_ping_timeout (void) +{ + int dt; + + dt = calc_deltatime (WaitTime); + tag = gtk_timeout_add(dt / 1000, gtk_ping, NULL); +} + void gtk_do_init(int *argc, char ***argv) { static int done = 0; @@ -53,7 +66,6 @@ int gtk_detect(int *argc, char ***argv) { /* If we do this here, gtk_init exits on an error. This happens BEFORE the user has had a chance to tell us not to use the display... */ - /* gtk_do_init(argc, argv); */ return TRUE; } else { return FALSE; @@ -73,13 +85,12 @@ gint Restart_clicked(GtkWidget *Button, gpointer data) { return FALSE; } -gint gtk_ping(gpointer data); gint Pause_clicked(GtkWidget *Button, gpointer data) { static int paused = 0; if (paused) { - tag = gtk_timeout_add(DeltaTime*1000, gtk_ping, NULL); + gtk_add_ping_timeout (); } else { gtk_timeout_remove (tag); } @@ -89,12 +100,37 @@ gint Pause_clicked(GtkWidget *Button, gpointer data) { return FALSE; } +/* + * There is a small problem with the following code: + * The timeout is canceled and removed in order to ensure that + * it takes effect (consider what happens if you set the timeout to 999, + * then try to undo the change); is a better approach possible? -- CMR + * + * What's the problem with this? (-> "I don't think so) -- REW + */ + +gint WaitTime_changed(GtkAdjustment *Adj, GtkWidget *Button) { + WaitTime = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(Button)); + gtk_timeout_remove (tag); + gtk_add_ping_timeout (); + gtk_redraw(); + + return FALSE; +} + gint Host_activate(GtkWidget *Entry, gpointer data) { int addr; addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(Entry))); - if(addr) + if(addr) { net_reopen(addr); + /* If we are "Paused" at this point it is usually because someone + entered a non-existing host. Therefore do the go-ahead... --REW */ + gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON( Pause_Button ) , 0); + } else { + gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON( Pause_Button ) , 1); + gtk_entry_append_text( GTK_ENTRY(Entry), ": not found" ); + } return FALSE; } @@ -109,6 +145,7 @@ void Toolbar_fill(GtkWidget *Toolbar) { GtkWidget *Button; GtkWidget *Label; GtkWidget *Entry; + GtkAdjustment *Adjustment; Button = gtk_button_new_with_label("Quit"); gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); @@ -122,10 +159,24 @@ void Toolbar_fill(GtkWidget *Toolbar) { GTK_SIGNAL_FUNC(Restart_clicked), NULL); gtk_widget_show(Button); - Button = gtk_check_button_new_with_label("Pause"); - gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); - gtk_signal_connect(GTK_OBJECT(Button), "clicked", + Pause_Button = gtk_toggle_button_new_with_label("Pause"); + gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(Pause_Button), "clicked", GTK_SIGNAL_FUNC(Pause_clicked), NULL); + gtk_widget_show(Pause_Button); + + Adjustment = (GtkAdjustment *)gtk_adjustment_new(WaitTime, + 0.00, 999.99, + 1.0, 10.0, + 0.0); + Button = gtk_spin_button_new(Adjustment, 0.5, 2); + gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE); + /* gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(Button), FALSE); */ + /* gtk_spin_button_set_set_update_policy(GTK_SPIN_BUTTON(Button), + GTK_UPDATE_IF_VALID); */ + gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(Adjustment), "value_changed", + GTK_SIGNAL_FUNC(WaitTime_changed), Button); gtk_widget_show(Button); Label = gtk_label_new("Hostname"); @@ -338,7 +389,7 @@ gint gtk_ping(gpointer data) { gtk_redraw(); net_send_batch(); gtk_timeout_remove (tag); - tag = gtk_timeout_add(DeltaTime*1000, gtk_ping, NULL); + gtk_add_ping_timeout (); return TRUE; } @@ -354,8 +405,7 @@ void gtk_dns_data(gpointer data, gint fd, GdkInputCondition cond) { void gtk_loop() { - DeltaTime = WaitTime/10; - tag = gtk_timeout_add(DeltaTime*1000, gtk_ping, NULL); + gtk_add_ping_timeout (); 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/net.c b/net.c index aebda41..2d6137c 100644 --- a/net.c +++ b/net.c @@ -36,8 +36,6 @@ #include "net.h" -extern float WaitTime, DeltaTime; -int timestamp; #define MaxTransit 4 @@ -107,12 +105,25 @@ static struct nethost host[MaxHost]; static struct sequence sequence[MaxSequence]; static struct timeval reset = { 0, 0 }; +int timestamp; int sendsock; int recvsock; struct sockaddr_in remoteaddress; static int batch_at = 0; + +static int numhosts = 10; + +/* return the number of microseconds to wait before sending the next + ping */ +int calc_deltatime (float waittime) +{ + waittime /= numhosts; + return 1000000 * waittime; +} + + /* This doesn't work for odd sz. I don't know enough about this to say that this is wrong. It doesn't seem to cripple mtr though. -- REW */ int checksum(void *data, int sz) { @@ -358,7 +369,7 @@ int net_send_batch() { if ((host[batch_at].addr == remoteaddress.sin_addr.s_addr) || (n_unknown > MAX_UNKNOWN_HOSTS)) { - DeltaTime = WaitTime / (float) (batch_at+1); + numhosts = batch_at+1; batch_at = 0; return 1; } @@ -420,6 +431,7 @@ void net_reset() { int i; batch_at = 0; + numhosts = 10; for(at = 0; at < MaxHost; at++) { host[at].xmit = 0; diff --git a/net.h b/net.h index 929a7a6..2038ab4 100644 --- a/net.h +++ b/net.h @@ -35,6 +35,9 @@ int net_avg(int at); int net_send_batch(); void net_end_transit(); +int calc_deltatime (float WaitTime); + + /* Added by Brian Casey, December 1997 bcasey@imagiware.com*/ int net_returned(int at); int net_xmit(int at); diff --git a/select.c b/select.c index 39eaa3a..6517cfa 100644 --- a/select.c +++ b/select.c @@ -32,11 +32,11 @@ extern int Interactive; extern int MaxPing; extern float WaitTime; -float DeltaTime; double dnsinterval; static struct timeval intervaltime; + void select_loop() { fd_set readfd; int anyset; @@ -46,16 +46,17 @@ void select_loop() { int paused; struct timeval lasttime, thistime, selecttime; float wt; + int dt; NumPing = 0; anyset = 0; gettimeofday(&lasttime, NULL); - DeltaTime = WaitTime/10; paused=0; while(1) { - intervaltime.tv_sec = DeltaTime; - intervaltime.tv_usec = 1000000 *( DeltaTime - floor (DeltaTime)); + dt = calc_deltatime (WaitTime); + intervaltime.tv_sec = dt / 1000000; + intervaltime.tv_usec = dt % 1000000; FD_ZERO(&readfd);