Przeglądaj źródła

whitespace cleanup

Jindrich Makovicka 16 lat temu
rodzic
commit
755376b06c
2 zmienionych plików z 555 dodań i 555 usunięć
  1. 207 207
      multiping.c
  2. 348 348
      pinger.c

+ 207 - 207
multiping.c

@@ -1,5 +1,5 @@
 /*____________________________________________________________________________
-        
+
         gkrellm multiping plugin
 
         Copyright (C) 2002 Jindrich Makovicka
@@ -27,8 +27,8 @@ ____________________________________________________________________________*/
 
 #include "decal_multiping_status.xpm"
 
-#define	CONFIG_NAME	"Multiping"
-#define	STYLE_NAME	"multiping"
+#define         CONFIG_NAME     "Multiping"
+#define         STYLE_NAME      "multiping"
 
 #define COMMAND HELPERDIR"/pinger"
 
@@ -52,7 +52,7 @@ static GtkWidget *dynamic_checkbutton;
 
 static GtkTreeView *multiping_treeview;
 static GtkTreeRowReference *row_reference;
-static GtkTreeSelection	*selection;
+static GtkTreeSelection         *selection;
 
 static GkrellmPiximage *decal_status_image;
 static GdkPixmap *status_pixmap;
@@ -103,13 +103,13 @@ static host_data *host_malloc()
 static void host_free(host_data * h)
 {
     if (h->name_text) {
-	gkrellm_destroy_decal(h->name_text);
+        gkrellm_destroy_decal(h->name_text);
     }
     if (h->msg_text) {
-	gkrellm_destroy_decal(h->msg_text);
+        gkrellm_destroy_decal(h->msg_text);
     }
     if (h->decal_pix) {
-	gkrellm_destroy_decal(h->decal_pix);
+        gkrellm_destroy_decal(h->decal_pix);
     }
     g_string_free(h->name, TRUE);
     g_string_free(h->ip, TRUE);
@@ -124,7 +124,7 @@ static void host_free(host_data * h)
 static void strip_nl(gchar *buf)
 {
     if (buf[strlen(buf) - 1] == '\n')
-	buf[strlen(buf) - 1] = 0;
+        buf[strlen(buf) - 1] = 0;
 }
 
 
@@ -134,8 +134,8 @@ static void host_read_pipe(host_data * h)
 
     char* res = fgets(buf, 512, pinger_pipe);
     if (res == 0) {
-	helper_err = 1;
-	return;
+        helper_err = 1;
+        return;
     }
     strip_nl(buf);
     g_string_assign(h->percentage, buf);
@@ -156,10 +156,10 @@ static void host_read_pipe(host_data * h)
 static void kill_pinger()
 {
     if (pinger_pipe) {
-	kill(pinger_pid, SIGTERM);
-	waitpid(pinger_pid, NULL, 0);
-	fclose(pinger_pipe);
-	pinger_pipe = NULL;
+        kill(pinger_pid, SIGTERM);
+        waitpid(pinger_pid, NULL, 0);
+        fclose(pinger_pipe);
+        pinger_pipe = NULL;
     }
 }
 
@@ -173,37 +173,37 @@ static void launch_pipe()
     gint mypipe[2];
 
     for (i = 0, list = hosts; list; list = list->next, i++) {
-	char freq[5];
-	h = (host_data *) list->data;
-	g_string_append(s, " ");
-	g_string_append(s, h->ip->str);
-	g_string_append(s, " ");
-	sprintf(freq, "%3d", h->updatefreq);
-	g_string_append(s, freq);
-	g_string_append(s, " ");
-	g_string_append(s, h->dynamic ? "1" : "0");
+        char freq[5];
+        h = (host_data *) list->data;
+        g_string_append(s, " ");
+        g_string_append(s, h->ip->str);
+        g_string_append(s, " ");
+        sprintf(freq, "%3d", h->updatefreq);
+        g_string_append(s, freq);
+        g_string_append(s, " ");
+        g_string_append(s, h->dynamic ? "1" : "0");
     }
 
     if (pipe(mypipe)) {
-	fprintf(stderr, "Pipe failed.\n");
-	return;
+        fprintf(stderr, "Pipe failed.\n");
+        return;
     }
 
     pid = fork();
     if (pid == 0) {
-	/* This is the child process.  Execute the shell command. */
-	close(mypipe[0]);
-	dup2(mypipe[1], 1);
-	execl("/bin/sh", "/bin/sh", "-c", s->str, NULL);
-	_exit(EXIT_FAILURE);
+        /* This is the child process.  Execute the shell command. */
+        close(mypipe[0]);
+        dup2(mypipe[1], 1);
+        execl("/bin/sh", "/bin/sh", "-c", s->str, NULL);
+        _exit(EXIT_FAILURE);
     } else if (pid < 0) {
-	/* The fork failed.  Report failure.  */
-	fprintf(stderr, "failed to fork\n");
+        /* The fork failed.  Report failure.  */
+        fprintf(stderr, "failed to fork\n");
     } else {
-	/* This is the parent process. Prepare the pipe stream. */
-	close(mypipe[1]);
-	pinger_pipe = fdopen(mypipe[0], "r");
-	pinger_pid = pid;
+        /* This is the parent process. Prepare the pipe stream. */
+        close(mypipe[1]);
+        pinger_pipe = fdopen(mypipe[0], "r");
+        pinger_pid = pid;
     }
 
     g_string_free(s, TRUE);
@@ -216,7 +216,7 @@ host_append_info(host_data *h, GString *str)
   GString *s = g_string_new(NULL);
 
   g_string_sprintf(s, "%s: %s, %s\n",
-		   h->name->str, h->percentage->str, h->msg->str);
+                   h->name->str, h->percentage->str, h->msg->str);
   g_string_append(str, s->str);
 
   g_string_free(s, TRUE);
@@ -233,15 +233,15 @@ static void host_draw_msg(host_data * h)
     gint n, p;
 
     if (h->show_trip) {
-	gkrellm_draw_decal_text(panel, h->msg_text, h->shortmsg->str, -1);
+        gkrellm_draw_decal_text(panel, h->msg_text, h->shortmsg->str, -1);
     }
     n = sscanf(h->percentage->str, "%d", &p);
     if (n != 1 || p == 0) {
-	gkrellm_draw_decal_pixmap(panel, h->decal_pix, 0);
+        gkrellm_draw_decal_pixmap(panel, h->decal_pix, 0);
     } else if (p < 100) {
-	gkrellm_draw_decal_pixmap(panel, h->decal_pix, 2);
+        gkrellm_draw_decal_pixmap(panel, h->decal_pix, 2);
     } else {
-	gkrellm_draw_decal_pixmap(panel, h->decal_pix, 1);
+        gkrellm_draw_decal_pixmap(panel, h->decal_pix, 1);
     }
 }
 
@@ -258,38 +258,38 @@ static GList *append_host(GList * list, gchar * name, gchar * ip, gboolean show_
 
 static gint
 display_host(host_data * h, GkrellmStyle * style, GkrellmTextstyle * ts,
-	     GkrellmTextstyle * ts_alt, gint y)
+             GkrellmTextstyle * ts_alt, gint y)
 {
     if (h->show_trip) {
-	h->msg_text =
-	    gkrellm_create_decal_text(panel, "999", ts_alt, style, 0, y, 0);
+        h->msg_text =
+            gkrellm_create_decal_text(panel, "999", ts_alt, style, 0, y, 0);
 
-	h->msg_text->x = gkrellm_chart_width() - h->msg_text->w + time_xoffset;
+        h->msg_text->x = gkrellm_chart_width() - h->msg_text->w + time_xoffset;
     }
-    
+
     h->decal_pix =
-	gkrellm_create_decal_pixmap(panel, status_pixmap, status_mask, 3,
-				    style, -1, y);
+        gkrellm_create_decal_pixmap(panel, status_pixmap, status_mask, 3,
+                                    style, -1, y);
     h->name_text =
-	gkrellm_create_decal_text(panel, "Ay", ts, style,
-				  h->decal_pix->x+h->decal_pix->w+hspacing, y, -1);
+        gkrellm_create_decal_text(panel, "Ay", ts, style,
+                                  h->decal_pix->x+h->decal_pix->w+hspacing, y, -1);
 
     if (h->name_text->h < h->decal_pix->h) {
-	h->name_text->y += (h->decal_pix->h-h->name_text->h)/2;
-	if (h->show_trip) {
-	    h->msg_text->y = h->name_text->y;
-	}
-	return h->decal_pix->y + h->decal_pix->h + vspacing;
+        h->name_text->y += (h->decal_pix->h-h->name_text->h)/2;
+        if (h->show_trip) {
+            h->msg_text->y = h->name_text->y;
+        }
+        return h->decal_pix->y + h->decal_pix->h + vspacing;
     } else {
-	h->decal_pix->y += (h->name_text->h-h->decal_pix->h)/2;
-	return h->name_text->y + h->name_text->h + vspacing;
+        h->decal_pix->y += (h->name_text->h-h->decal_pix->h)/2;
+        return h->name_text->y + h->name_text->h + vspacing;
     }
 }
 
 static gint panel_click_event(GtkWidget * widget, GdkEventButton * ev)
 {
     if (ev->button == 3)
-	gkrellm_open_config_window(monitor);
+        gkrellm_open_config_window(monitor);
 
     return 1;
 }
@@ -297,9 +297,9 @@ static gint panel_click_event(GtkWidget * widget, GdkEventButton * ev)
 static gint panel_expose_event(GtkWidget * widget, GdkEventExpose * ev)
 {
     gdk_draw_pixmap(widget->window,
-		    widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
-		    panel->pixmap, ev->area.x, ev->area.y, ev->area.x,
-		    ev->area.y, ev->area.width, ev->area.height);
+                    widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+                    panel->pixmap, ev->area.x, ev->area.y, ev->area.x,
+                    ev->area.y, ev->area.width, ev->area.height);
     return FALSE;
 }
 
@@ -318,18 +318,18 @@ static void update_plugin()
     ret = select(fileno(pinger_pipe) + 1, &fds, 0, 0, &tv);
 
     if (ret) {
-	g_list_foreach(hosts, (GFunc) host_read_pipe, NULL);
-	g_list_foreach(hosts, (GFunc) host_draw_msg, NULL);
-	gkrellm_draw_panel_layers(panel);
+        g_list_foreach(hosts, (GFunc) host_read_pipe, NULL);
+        g_list_foreach(hosts, (GFunc) host_draw_msg, NULL);
+        gkrellm_draw_panel_layers(panel);
     }
 
     if (helper_err) {
-	kill_pinger();
-	launch_pipe();
-	helper_err = 0;
+        kill_pinger();
+        launch_pipe();
+        helper_err = 0;
     }
-    
-    /*  
+
+    /*
        if (GK.minute_tick && tooltip) {
        //    if (tooltip->tip_window == NULL || !GTK_WIDGET_VISIBLE(tooltip->tip_window)) {
        g_list_foreach(hosts, (GFunc)host_append_info, str);
@@ -353,7 +353,7 @@ setup_display(gboolean first_create)
     host_data *h;
 
     if (first_create) {
-	panel = gkrellm_panel_new0();
+        panel = gkrellm_panel_new0();
     }
 
     style = gkrellm_panel_style(style_id);
@@ -362,21 +362,21 @@ setup_display(gboolean first_create)
 
     y = 3;
 //    y = style->top_margin;
-    
+
     for (i = 0, list = hosts; list; list = list->next, i++) {
-	h = (host_data *) list->data;
-	y = display_host(h, style, ts, ts_alt, y);
+        h = (host_data *) list->data;
+        y = display_host(h, style, ts, ts_alt, y);
     }
 
     gkrellm_panel_configure(panel, NULL, style);
     gkrellm_panel_create(plugin_vbox, monitor, panel);
 
     if (first_create) {
-	g_signal_connect(GTK_OBJECT(panel->drawing_area), "expose_event",
-			 (GtkSignalFunc) panel_expose_event, NULL);
-	g_signal_connect(GTK_OBJECT(panel->drawing_area),
-			 "button_release_event",
-			 (GtkSignalFunc) panel_click_event, NULL);
+        g_signal_connect(GTK_OBJECT(panel->drawing_area), "expose_event",
+                         (GtkSignalFunc) panel_expose_event, NULL);
+        g_signal_connect(GTK_OBJECT(panel->drawing_area),
+                         "button_release_event",
+                         (GtkSignalFunc) panel_click_event, NULL);
     }
 
     g_list_foreach(hosts, (GFunc) host_draw_name, NULL);
@@ -391,17 +391,17 @@ create_plugin(GtkWidget * vbox, gint first_create)
     plugin_vbox = vbox;
 
     gkrellm_load_piximage("decal_multiping_status", decal_multiping_status_xpm,
-			  &decal_status_image, STYLE_NAME);
+                          &decal_status_image, STYLE_NAME);
 
     gkrellm_scale_piximage_to_pixmap(decal_status_image, &status_pixmap,
-				     &status_mask, 0, 0);
+                                     &status_mask, 0, 0);
 
     if (!gkrellm_get_gkrellmrc_integer("multiping_vspacing", &vspacing))
-	vspacing = 2;
+        vspacing = 2;
     if (!gkrellm_get_gkrellmrc_integer("multiping_hspacing", &hspacing))
-	hspacing = 2;
+        hspacing = 2;
     if (!gkrellm_get_gkrellmrc_integer("multiping_time_xoffset", &time_xoffset))
-	time_xoffset = 0;
+        time_xoffset = 0;
 
     kill_pinger();
     launch_pipe();
@@ -414,9 +414,9 @@ change_row_reference(GtkTreeModel *model, GtkTreePath *path)
 {
     gtk_tree_row_reference_free(row_reference);
     if (model && path)
-	row_reference = gtk_tree_row_reference_new(model, path);
+        row_reference = gtk_tree_row_reference_new(model, path);
     else
-	row_reference = NULL;
+        row_reference = NULL;
 }
 
 
@@ -444,12 +444,12 @@ host_new_from_model(GtkTreeModel *model, GtkTreeIter *iter)
 
     h = host_malloc();
     gtk_tree_model_get(model, iter,
-		       LABEL_COLUMN, &label,
-		       HOST_COLUMN, &host,
-		       TRIP_COLUMN, &h->show_trip,
-		       DYNAMIC_COLUMN, &h->dynamic,
-		       INTERVAL_COLUMN, &h->updatefreq,
-		       -1);
+                       LABEL_COLUMN, &label,
+                       HOST_COLUMN, &host,
+                       TRIP_COLUMN, &h->show_trip,
+                       DYNAMIC_COLUMN, &h->dynamic,
+                       INTERVAL_COLUMN, &h->updatefreq,
+                       -1);
 
     h->name = g_string_new(label);
     h->ip = g_string_new(host);
@@ -462,13 +462,13 @@ static void
 set_list_store_model_data(GtkListStore *store, GtkTreeIter *iter, host_data *h)
 {
     gtk_list_store_set(store, iter,
-		       LABEL_COLUMN, h->name->str,
-		       HOST_COLUMN, h->ip->str,
-		       TRIP_COLUMN, h->show_trip,
-		       DYNAMIC_COLUMN, h->dynamic,
-		       INTERVAL_COLUMN, h->updatefreq,
-		       DUMMY_COLUMN, "",
-		       -1);
+                       LABEL_COLUMN, h->name->str,
+                       HOST_COLUMN, h->ip->str,
+                       TRIP_COLUMN, h->show_trip,
+                       DYNAMIC_COLUMN, h->dynamic,
+                       INTERVAL_COLUMN, h->updatefreq,
+                       DUMMY_COLUMN, "",
+                       -1);
 }
 
 static GtkTreeModel *
@@ -480,12 +480,12 @@ create_model(void)
     host_data *h;
 
     store = gtk_list_store_new(N_COLUMNS,
-			       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
-			       G_TYPE_INT, G_TYPE_STRING);
+                               G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
+                               G_TYPE_INT, G_TYPE_STRING);
     for (list = hosts; list; list = list->next) {
-	h = (host_data *) list->data;
-	gtk_list_store_append(store, &iter);
-	set_list_store_model_data(store, &iter, h);
+        h = (host_data *) list->data;
+        gtk_list_store_append(store, &iter);
+        set_list_store_model_data(store, &iter, h);
     }
     return GTK_TREE_MODEL(store);
 }
@@ -493,7 +493,7 @@ create_model(void)
 
 static void
 cb_selected(GtkWidget * clist, gint row, gint column,
-	    GdkEventButton * bevent, gpointer data)
+            GdkEventButton * bevent, gpointer data)
 {
     GtkTreeIter iter;
     GtkTreeModel *model;
@@ -502,8 +502,8 @@ cb_selected(GtkWidget * clist, gint row, gint column,
 
     if (!gtk_tree_selection_get_selected(selection, &model, &iter))
     {
-	reset_entries();
-	return;
+        reset_entries();
+        return;
     }
     path = gtk_tree_model_get_path(model, &iter);
     change_row_reference(model, path);
@@ -518,7 +518,7 @@ cb_selected(GtkWidget * clist, gint row, gint column,
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(updatefreq_spin), h->updatefreq);
 
     host_free(h);
-    
+
     return;
 }
 
@@ -541,8 +541,8 @@ cb_enter(GtkWidget * widget, gpointer data)
     buf[2] = gkrellm_gtk_entry_get_text(&updatefreq_spin);
 
     if ((strlen(buf[0]) == 0) || (strlen(buf[1]) == 0)) {
-	host_free(h);
-	return;
+        host_free(h);
+        return;
     }
 
     h->name = g_string_new(buf[0]);
@@ -552,12 +552,12 @@ cb_enter(GtkWidget * widget, gpointer data)
     model = gtk_tree_view_get_model(multiping_treeview);
     if (row_reference)
     {
-	path = gtk_tree_row_reference_get_path(row_reference);
-	gtk_tree_model_get_iter(model, &iter, path);
+        path = gtk_tree_row_reference_get_path(row_reference);
+        gtk_tree_model_get_iter(model, &iter, path);
     }
     else
     {
-	gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
     }
 
     set_list_store_model_data(GTK_LIST_STORE(model), &iter, h);
@@ -571,12 +571,12 @@ cb_enter(GtkWidget * widget, gpointer data)
 static void
 cb_delete(GtkWidget * widget, gpointer data)
 {
-    GtkTreeModel	*model;
-    GtkTreePath		*path;
-    GtkTreeIter		iter;
+    GtkTreeModel        *model;
+    GtkTreePath                 *path;
+    GtkTreeIter                 iter;
 
     if (!row_reference)
-	return;
+        return;
     model = gtk_tree_view_get_model(multiping_treeview);
     path = gtk_tree_row_reference_get_path(row_reference);
     gtk_tree_model_get_iter(model, &iter, path);
@@ -663,18 +663,18 @@ static void create_plugin_config(GtkWidget * tab_vbox)
 
     button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
     g_signal_connect(GTK_OBJECT(button), "clicked",
-		     (GtkSignalFunc) cb_delete, NULL);
+                     (GtkSignalFunc) cb_delete, NULL);
     gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
 
     button = gtk_button_new_from_stock(GTK_STOCK_ADD);;
     g_signal_connect(GTK_OBJECT(button), "clicked",
-		     (GtkSignalFunc) cb_enter, NULL);
+                     (GtkSignalFunc) cb_enter, NULL);
     gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
 
     scrolled = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
-				   GTK_POLICY_AUTOMATIC,
-				   GTK_POLICY_AUTOMATIC);
+                                   GTK_POLICY_AUTOMATIC,
+                                   GTK_POLICY_AUTOMATIC);
     gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0);
 
     /* Treeview */
@@ -685,42 +685,42 @@ static void create_plugin_config(GtkWidget * tab_vbox)
     gtk_tree_view_set_rules_hint(multiping_treeview, TRUE);
     gtk_tree_view_set_reorderable(multiping_treeview, TRUE);
     g_signal_connect(G_OBJECT(multiping_treeview), "drag_end",
-		     G_CALLBACK(cb_drag_end), NULL);
+                     G_CALLBACK(cb_drag_end), NULL);
 
     renderer = gtk_cell_renderer_text_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "Label",
-						renderer,
-						"text", LABEL_COLUMN, NULL);
+                                                renderer,
+                                                "text", LABEL_COLUMN, NULL);
     renderer = gtk_cell_renderer_text_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "Hostname / IP Address",
-						renderer,
-						"text", HOST_COLUMN, NULL);
+                                                renderer,
+                                                "text", HOST_COLUMN, NULL);
     renderer = gtk_cell_renderer_toggle_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "Trip",
-						renderer,
-						"active", TRIP_COLUMN, NULL);
+                                                renderer,
+                                                "active", TRIP_COLUMN, NULL);
 
     renderer = gtk_cell_renderer_toggle_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "Dynamic",
-						renderer,
-						"active", DYNAMIC_COLUMN, NULL);
+                                                renderer,
+                                                "active", DYNAMIC_COLUMN, NULL);
 
     renderer = gtk_cell_renderer_text_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "Ping int.",
-						renderer,
-						"text", INTERVAL_COLUMN, NULL);
+                                                renderer,
+                                                "text", INTERVAL_COLUMN, NULL);
 
     renderer = gtk_cell_renderer_text_new();
     gtk_tree_view_insert_column_with_attributes(multiping_treeview, -1, "    ",
-						renderer,
-						"text", DUMMY_COLUMN, NULL);
+                                                renderer,
+                                                "text", DUMMY_COLUMN, NULL);
 
 
     gtk_container_add(GTK_CONTAINER(scrolled), GTK_WIDGET(multiping_treeview));
     selection = gtk_tree_view_get_selection(multiping_treeview);
     gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
     g_signal_connect(G_OBJECT(selection), "changed",
-		     G_CALLBACK(cb_selected), NULL);
+                     G_CALLBACK(cb_selected), NULL);
 
 /* About tab */
     info_label = gtk_label_new(plugin_about_text);
@@ -731,35 +731,35 @@ static void create_plugin_config(GtkWidget * tab_vbox)
 static void apply_plugin_config()
 {
     if (list_modified) {
-	GList *new_hosts;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	
-	kill_pinger();
-
-	new_hosts = NULL;
-
-	model = gtk_tree_view_get_model(multiping_treeview);
-	if (gtk_tree_model_get_iter_first(model, &iter)) {
-	    do {
-		host_data *h;
-		h = host_new_from_model(model, &iter);
-		new_hosts = g_list_append(new_hosts, h);
-	    }
-	    while (gtk_tree_model_iter_next(model, &iter));
-	}
-
-	g_list_foreach(hosts, (GFunc) host_free, NULL);
-	g_list_free(hosts);
-	gkrellm_panel_destroy(panel);
-	panel = gkrellm_panel_new0();
-
-	hosts = new_hosts;
-	setup_display(1);
-
-	list_modified = FALSE;
-
-	launch_pipe();
+        GList *new_hosts;
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+
+        kill_pinger();
+
+        new_hosts = NULL;
+
+        model = gtk_tree_view_get_model(multiping_treeview);
+        if (gtk_tree_model_get_iter_first(model, &iter)) {
+            do {
+                host_data *h;
+                h = host_new_from_model(model, &iter);
+                new_hosts = g_list_append(new_hosts, h);
+            }
+            while (gtk_tree_model_iter_next(model, &iter));
+        }
+
+        g_list_foreach(hosts, (GFunc) host_free, NULL);
+        g_list_free(hosts);
+        gkrellm_panel_destroy(panel);
+        panel = gkrellm_panel_new0();
+
+        hosts = new_hosts;
+        setup_display(1);
+
+        list_modified = FALSE;
+
+        launch_pipe();
     }
 }
 
@@ -771,17 +771,17 @@ static void save_plugin_config(FILE * f)
     host_data *h;
 
     for (list = hosts; list; list = list->next) {
-	h = (host_data *) list->data;
+        h = (host_data *) list->data;
 
-	//when saving, we convert spaces in labels to underscores
-	label = g_strdup(h->name->str);
-	for (pt = label; *pt; pt++)
-	    if (*pt == ' ')
-		*pt = '_';
+        //when saving, we convert spaces in labels to underscores
+        label = g_strdup(h->name->str);
+        for (pt = label; *pt; pt++)
+            if (*pt == ' ')
+                *pt = '_';
 
-	fprintf(f, "multiping host %s %s %d %d %d\n", label, h->ip->str, h->show_trip,
-		h->updatefreq, h->dynamic);
-	g_free(label);
+        fprintf(f, "multiping host %s %s %d %d %d\n", label, h->ip->str, h->show_trip,
+                h->updatefreq, h->dynamic);
+        g_free(label);
     }
 }
 
@@ -800,51 +800,51 @@ static void load_plugin_config(gchar * arg)
     n = sscanf(arg, "%s %[^\n]", plugin_config, item);
 
     if (n == 2) {
-	if (!strcmp(plugin_config, "host")) {
-	    if (delete_list) {
-		g_list_foreach(hosts, (GFunc) host_free, NULL);
-		g_list_free(hosts);
-		delete_list = FALSE;
-	    }
-
-	    label[0] = '\0';
-	    ip[0] = '\0';
-	    show_trip = TRUE;
-	    dynamic = FALSE;
-	    sscanf(item, "%25s %75s %d %d %d", label, ip, &show_trip, &updatefreq, &dynamic);
-
-	    //when loading, we convert underscores in labels to spaces
-	    for (pt = label; *pt; pt++)
-		if (*pt == '_')
-		    *pt = ' ';
-
-	    hosts = append_host(hosts, label, ip, show_trip, dynamic, updatefreq);
-	}
+        if (!strcmp(plugin_config, "host")) {
+            if (delete_list) {
+                g_list_foreach(hosts, (GFunc) host_free, NULL);
+                g_list_free(hosts);
+                delete_list = FALSE;
+            }
+
+            label[0] = '\0';
+            ip[0] = '\0';
+            show_trip = TRUE;
+            dynamic = FALSE;
+            sscanf(item, "%25s %75s %d %d %d", label, ip, &show_trip, &updatefreq, &dynamic);
+
+            //when loading, we convert underscores in labels to spaces
+            for (pt = label; *pt; pt++)
+                if (*pt == '_')
+                    *pt = ' ';
+
+            hosts = append_host(hosts, label, ip, show_trip, dynamic, updatefreq);
+        }
     }
 }
 
 /* The monitor structure tells GKrellM how to call the plugin routines.
 */
 static GkrellmMonitor plugin_mon = {
-    CONFIG_NAME,		/* Name, for config tab.    */
-    0,				/* Id,  0 if a plugin       */
-    create_plugin,		/* The create function      */
-    update_plugin,		/* The update function      */
-    create_plugin_config,	/* The config tab create function   */
-    apply_plugin_config,	/* Apply the config function        */
+    CONFIG_NAME,                /* Name, for config tab.    */
+    0,                          /* Id,  0 if a plugin       */
+    create_plugin,              /* The create function      */
+    update_plugin,              /* The update function      */
+    create_plugin_config,       /* The config tab create function   */
+    apply_plugin_config,        /* Apply the config function        */
 
-    save_plugin_config,		/* Save user config */
-    load_plugin_config,		/* Load user config */
-    "multiping",		/* config keyword                       */
+    save_plugin_config,                 /* Save user config */
+    load_plugin_config,                 /* Load user config */
+    "multiping",                /* config keyword                       */
 
-    NULL,			/* Undefined 2  */
-    NULL,			/* Undefined 1  */
-    NULL,			/* private              */
+    NULL,                       /* Undefined 2  */
+    NULL,                       /* Undefined 1  */
+    NULL,                       /* private              */
 
-    MON_MAIL,			/* Insert plugin before this monitor                    */
+    MON_MAIL,                   /* Insert plugin before this monitor                    */
 
-    NULL,			/* Handle if a plugin, filled in by GKrellM     */
-    NULL			/* path if a plugin, filled in by GKrellM       */
+    NULL,                       /* Handle if a plugin, filled in by GKrellM     */
+    NULL                        /* path if a plugin, filled in by GKrellM       */
 };
 
 GkrellmMonitor *gkrellm_init_plugin()

+ 348 - 348
pinger.c

@@ -1,5 +1,5 @@
 /*____________________________________________________________________________
-        
+
         pinger - gkrellm multiping helper app
 
         Copyright (C) 2002 Jindrich Makovicka
@@ -45,23 +45,23 @@ ____________________________________________________________________________*/
 #define STORM_PHASE 0
 #define STANDBY_PHASE 1
 
-#define	DEFDATALEN	(64 - 8)	/* default data length */
-#define	MAXIPLEN	60
-#define	MAXICMPLEN	76
-#define	MAXPACKET	(65536 - 60 - 8)	/* max packet size */
+#define         DEFDATALEN      (64 - 8)        /* default data length */
+#define         MAXIPLEN        60
+#define         MAXICMPLEN      76
+#define         MAXPACKET       (65536 - 60 - 8)        /* max packet size */
 
-#define	MAX_DUP_CHK	(8 * 128)
+#define         MAX_DUP_CHK     (8 * 128)
 
-#define	A(bit)		h->rcvd_tbl[(bit)>>3]	/* identify byte in array */
-#define	B(bit)		(1 << ((bit) & 0x07))	/* identify bit in byte */
-#define	SET(bit)	(A(bit) |= B(bit))
-#define	CLR(bit)	(A(bit) &= (~B(bit)))
-#define	TST(bit)	(A(bit) & B(bit))
+#define         A(bit)          h->rcvd_tbl[(bit)>>3]   /* identify byte in array */
+#define         B(bit)          (1 << ((bit) & 0x07))   /* identify bit in byte */
+#define         SET(bit)        (A(bit) |= B(bit))
+#define         CLR(bit)        (A(bit) &= (~B(bit)))
+#define         TST(bit)        (A(bit) & B(bit))
 
 int icmp_socket;
-static int ident;		/* process id to identify our packets */
+static int ident;               /* process id to identify our packets */
 static int datalen = DEFDATALEN;
-static long ntransmitted = 0;	/* sequence # for outbound packets = #sent */
+static long ntransmitted = 0;   /* sequence # for outbound packets = #sent */
 u_char outpack[MAXPACKET];
 u_char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
 int packlen = DEFDATALEN + MAXIPLEN + MAXICMPLEN;
@@ -72,7 +72,7 @@ int has_pinged;
 int terminated = 0;
 
 typedef struct _host_data {
-    int nhost;			// cislo poce
+    int nhost;                  // cislo poce
     GString *hostname, *percentage, *sent_str, *recv_str, *msg, *shortmsg;
     int dynamic;
     int dummy;
@@ -139,7 +139,7 @@ static gint compare_delay(gconstpointer a, gconstpointer b)
 
 /*
  * in_cksum --
- *	Checksum routine for Internet Protocol family headers (C Version)
+ *      Checksum routine for Internet Protocol family headers (C Version)
  */
 static int in_cksum(u_short * addr, int len)
 {
@@ -154,20 +154,20 @@ static int in_cksum(u_short * addr, int len)
      * carry bits from the top 16 bits into the lower 16 bits.
      */
     while (nleft > 1) {
-	sum += *w++;
-	nleft -= 2;
+        sum += *w++;
+        nleft -= 2;
     }
 
     /* mop up an odd byte, if necessary */
     if (nleft == 1) {
-	*(u_char *) (&answer) = *(u_char *) w;
-	sum += answer;
+        *(u_char *) (&answer) = *(u_char *) w;
+        sum += answer;
     }
 
     /* add back carry outs from top 16 bits to low 16 bits */
-    sum = (sum >> 16) + (sum & 0xffff);	/* add hi 16 to low 16 */
-    sum += (sum >> 16);		/* add carry */
-    answer = ~sum;		/* truncate to 16 bits */
+    sum = (sum >> 16) + (sum & 0xffff);         /* add hi 16 to low 16 */
+    sum += (sum >> 16);                 /* add carry */
+    answer = ~sum;              /* truncate to 16 bits */
     return (answer);
 }
 
@@ -179,7 +179,7 @@ static void write_result(host_data * h, gchar * msg, gchar * shortmsg)
 
 /*
  * pinger --
- * 	Compose and transmit an ICMP ECHO REQUEST packet.  The IP packet
+ *      Compose and transmit an ICMP ECHO REQUEST packet.  The IP packet
  * will be added on by the kernel.  The ID field is our UNIX process ID,
  * and the sequence number is an ascending integer.  The first 8 bytes
  * of the data portion are used to hold a UNIX "timeval" struct in VAX
@@ -202,7 +202,7 @@ static void pinger(host_data * h)
     icp->icmp_code = 0;
     icp->icmp_cksum = 0;
     icp->icmp_seq = ntransmitted++;
-    icp->icmp_id = ident;	/* ID */
+    icp->icmp_id = ident;       /* ID */
 
     h->sent++;
     h->tmp_sent++;
@@ -210,26 +210,26 @@ static void pinger(host_data * h)
     CLR(icp->icmp_seq % MAX_DUP_CHK);
 
     (void) gettimeofday((struct timeval *) &outpack[8],
-			(struct timezone *) NULL);
+                        (struct timezone *) NULL);
 
     *(int *) &outpack[8 + sizeof(struct timeval)] = h->nhost;
 
-    cc = datalen + 8;		/* skips ICMP portion */
+    cc = datalen + 8;           /* skips ICMP portion */
 
     /* compute ICMP checksum here */
     icp->icmp_cksum = in_cksum((u_short *) icp, cc);
 
     i = sendto(icmp_socket, (char *) outpack, cc, 0, &h->addr,
-	       sizeof(struct sockaddr));
+               sizeof(struct sockaddr));
 
     if (i < 0 || i != cc) {
-	write_result(h, "Error sending packet", "Err");
+        write_result(h, "Error sending packet", "Err");
     }
 }
 
 /*
  * pr_icmph --
- *	Print a descriptive string about an ICMP header.
+ *      Print a descriptive string about an ICMP header.
  */
 static gchar *pr_icmph(struct icmp *icp)
 {
@@ -238,140 +238,140 @@ static gchar *pr_icmph(struct icmp *icp)
 
     switch (icp->icmp_type) {
     case ICMP_ECHOREPLY:
-	g_string_assign(s, "Echo Reply");
-	/* XXX ID + Seq + Data */
-	break;
+        g_string_assign(s, "Echo Reply");
+        /* XXX ID + Seq + Data */
+        break;
     case ICMP_DEST_UNREACH:
-	switch (icp->icmp_code) {
-	case ICMP_NET_UNREACH:
-	    g_string_assign(s, "Destination Net Unreachable");
-	    break;
-	case ICMP_HOST_UNREACH:
-	    g_string_assign(s, "Destination Host Unreachable");
-	    break;
-	case ICMP_PROT_UNREACH:
-	    g_string_assign(s, "Destination Protocol Unreachable");
-	    break;
-	case ICMP_PORT_UNREACH:
-	    g_string_assign(s, "Destination Port Unreachable");
-	    break;
-	case ICMP_FRAG_NEEDED:
-	    g_string_assign(s, "Frag needed and DF set");
-	    break;
-	case ICMP_SR_FAILED:
-	    g_string_assign(s, "Source Route Failed");
-	    break;
-	case ICMP_NET_UNKNOWN:
-	    g_string_assign(s, "Network Unknown");
-	    break;
-	case ICMP_HOST_UNKNOWN:
-	    g_string_assign(s, "Host Unknown");
-	    break;
-	case ICMP_HOST_ISOLATED:
-	    g_string_assign(s, "Host Isolated");
-	    break;
-	case ICMP_NET_UNR_TOS:
-	    g_string_assign(s,
-			    "Destination Network Unreachable At This TOS");
-	    break;
-	case ICMP_HOST_UNR_TOS:
-	    g_string_assign(s, "Destination Host Unreachable At This TOS");
-	    break;
+        switch (icp->icmp_code) {
+        case ICMP_NET_UNREACH:
+            g_string_assign(s, "Destination Net Unreachable");
+            break;
+        case ICMP_HOST_UNREACH:
+            g_string_assign(s, "Destination Host Unreachable");
+            break;
+        case ICMP_PROT_UNREACH:
+            g_string_assign(s, "Destination Protocol Unreachable");
+            break;
+        case ICMP_PORT_UNREACH:
+            g_string_assign(s, "Destination Port Unreachable");
+            break;
+        case ICMP_FRAG_NEEDED:
+            g_string_assign(s, "Frag needed and DF set");
+            break;
+        case ICMP_SR_FAILED:
+            g_string_assign(s, "Source Route Failed");
+            break;
+        case ICMP_NET_UNKNOWN:
+            g_string_assign(s, "Network Unknown");
+            break;
+        case ICMP_HOST_UNKNOWN:
+            g_string_assign(s, "Host Unknown");
+            break;
+        case ICMP_HOST_ISOLATED:
+            g_string_assign(s, "Host Isolated");
+            break;
+        case ICMP_NET_UNR_TOS:
+            g_string_assign(s,
+                            "Destination Network Unreachable At This TOS");
+            break;
+        case ICMP_HOST_UNR_TOS:
+            g_string_assign(s, "Destination Host Unreachable At This TOS");
+            break;
 #ifdef ICMP_PKT_FILTERED
-	case ICMP_PKT_FILTERED:
-	    g_string_assign(s, "Packet Filtered");
-	    break;
+        case ICMP_PKT_FILTERED:
+            g_string_assign(s, "Packet Filtered");
+            break;
 #endif
 #ifdef ICMP_PREC_VIOLATION
-	case ICMP_PREC_VIOLATION:
-	    g_string_assign(s, "Precedence Violation");
-	    break;
+        case ICMP_PREC_VIOLATION:
+            g_string_assign(s, "Precedence Violation");
+            break;
 #endif
 #ifdef ICMP_PREC_CUTOFF
-	case ICMP_PREC_CUTOFF:
-	    g_string_assign(s, "Precedence Cutoff");
-	    break;
+        case ICMP_PREC_CUTOFF:
+            g_string_assign(s, "Precedence Cutoff");
+            break;
 #endif
-	default:
-	    g_string_sprintf(s, "Dest Unreachable, Unknown Code: %d",
-			     icp->icmp_code);
-	    break;
-	}
-	break;
+        default:
+            g_string_sprintf(s, "Dest Unreachable, Unknown Code: %d",
+                             icp->icmp_code);
+            break;
+        }
+        break;
     case ICMP_SOURCE_QUENCH:
-	g_string_assign(s, "Source Quench");
-	break;
+        g_string_assign(s, "Source Quench");
+        break;
     case ICMP_REDIRECT:
-	switch (icp->icmp_code) {
-	case ICMP_REDIR_NET:
-	    g_string_assign(s, "Redirect Network");
-	    break;
-	case ICMP_REDIR_HOST:
-	    g_string_assign(s, "Redirect Host");
-	    break;
-	case ICMP_REDIR_NETTOS:
-	    g_string_assign(s, "Redirect Type of Service and Network");
-	    break;
-	case ICMP_REDIR_HOSTTOS:
-	    g_string_assign(s, "Redirect Type of Service and Host");
-	    break;
-	default:
-	    g_string_sprintf(s, "Redirect, Bad Code: %d", icp->icmp_code);
-	    break;
-	}
-	g_string_sprintfa(s, " (New addr: %s)",
-			  inet_ntoa(icp->icmp_gwaddr));
-	break;
+        switch (icp->icmp_code) {
+        case ICMP_REDIR_NET:
+            g_string_assign(s, "Redirect Network");
+            break;
+        case ICMP_REDIR_HOST:
+            g_string_assign(s, "Redirect Host");
+            break;
+        case ICMP_REDIR_NETTOS:
+            g_string_assign(s, "Redirect Type of Service and Network");
+            break;
+        case ICMP_REDIR_HOSTTOS:
+            g_string_assign(s, "Redirect Type of Service and Host");
+            break;
+        default:
+            g_string_sprintf(s, "Redirect, Bad Code: %d", icp->icmp_code);
+            break;
+        }
+        g_string_sprintfa(s, " (New addr: %s)",
+                          inet_ntoa(icp->icmp_gwaddr));
+        break;
     case ICMP_ECHO:
-	g_string_assign(s, "Echo Request");
-	/* XXX ID + Seq + Data */
-	break;
+        g_string_assign(s, "Echo Request");
+        /* XXX ID + Seq + Data */
+        break;
     case ICMP_TIME_EXCEEDED:
-	switch (icp->icmp_code) {
-	case ICMP_EXC_TTL:
-	    g_string_assign(s, "Time to live exceeded");
-	    break;
-	case ICMP_EXC_FRAGTIME:
-	    g_string_assign(s, "Frag reassembly time exceeded");
-	    break;
-	default:
-	    g_string_sprintf(s, "Time exceeded, Bad Code: %d",
-			     icp->icmp_code);
-	    break;
-	}
-	break;
+        switch (icp->icmp_code) {
+        case ICMP_EXC_TTL:
+            g_string_assign(s, "Time to live exceeded");
+            break;
+        case ICMP_EXC_FRAGTIME:
+            g_string_assign(s, "Frag reassembly time exceeded");
+            break;
+        default:
+            g_string_sprintf(s, "Time exceeded, Bad Code: %d",
+                             icp->icmp_code);
+            break;
+        }
+        break;
     case ICMP_PARAMETERPROB:
-	g_string_sprintf(s, "Parameter problem: IP address = %s",
-			 inet_ntoa(icp->icmp_gwaddr));
-	break;
+        g_string_sprintf(s, "Parameter problem: IP address = %s",
+                         inet_ntoa(icp->icmp_gwaddr));
+        break;
     case ICMP_TIMESTAMP:
-	g_string_assign(s, "Timestamp");
-	/* XXX ID + Seq + 3 timestamps */
-	break;
+        g_string_assign(s, "Timestamp");
+        /* XXX ID + Seq + 3 timestamps */
+        break;
     case ICMP_TIMESTAMPREPLY:
-	g_string_assign(s, "Timestamp Reply");
-	/* XXX ID + Seq + 3 timestamps */
-	break;
+        g_string_assign(s, "Timestamp Reply");
+        /* XXX ID + Seq + 3 timestamps */
+        break;
     case ICMP_INFO_REQUEST:
-	g_string_assign(s, "Information Request");
-	/* XXX ID + Seq */
-	break;
+        g_string_assign(s, "Information Request");
+        /* XXX ID + Seq */
+        break;
     case ICMP_INFO_REPLY:
-	g_string_assign(s, "Information Reply");
-	/* XXX ID + Seq */
-	break;
+        g_string_assign(s, "Information Reply");
+        /* XXX ID + Seq */
+        break;
 #ifdef ICMP_MASKREQ
     case ICMP_MASKREQ:
-	g_string_assign(s, "Address Mask Request");
-	break;
+        g_string_assign(s, "Address Mask Request");
+        break;
 #endif
 #ifdef ICMP_MASKREPLY
     case ICMP_MASKREPLY:
-	g_string_assign(s, "Address Mask Reply");
-	break;
+        g_string_assign(s, "Address Mask Reply");
+        break;
 #endif
     default:
-	g_string_sprintf(s, "Bad ICMP type: %d", icp->icmp_type);
+        g_string_sprintf(s, "Bad ICMP type: %d", icp->icmp_type);
     }
 
     c = s->str;
@@ -381,14 +381,14 @@ static gchar *pr_icmph(struct icmp *icp)
 
 /*
  * tvsub --
- *	Subtract 2 timeval structs:  out = out - in.  Out is assumed to
+ *      Subtract 2 timeval structs:  out = out - in.  Out is assumed to
  * be >= in.
  */
 static void tvsub(struct timeval *out, struct timeval *in)
 {
     if ((out->tv_usec -= in->tv_usec) < 0) {
-	--out->tv_sec;
-	out->tv_usec += 1000000;
+        --out->tv_sec;
+        out->tv_usec += 1000000;
     }
     out->tv_sec -= in->tv_sec;
 }
@@ -406,7 +406,7 @@ void pr_pack(char *buf, int cc, struct sockaddr_in *from)
     (void) gettimeofday(&tv, (struct timezone *) NULL);
 
     if (cc < datalen + ICMP_MINLEN)
-	return;
+        return;
 
     /* Check the IP header */
     ip = (struct ip *) buf;
@@ -417,71 +417,71 @@ void pr_pack(char *buf, int cc, struct sockaddr_in *from)
     icp = (struct icmp *) (buf + hlen);
 
     if (icp->icmp_type == ICMP_ECHOREPLY) {
-	if (icp->icmp_id != ident)
-	    return;		/* 'Twas not our ECHO */
-
-	h = (host_data *) g_list_find_custom(hosts,
-					     (int *) &icp->
-					     icmp_data[sizeof
-						       (struct timeval)],
-					     compare_nhost)->data;
-	if (h == NULL) return; /* host not found */
-
-	++h->recv;
-	++h->tmp_recv;
-
-	tp = (struct timeval *) icp->icmp_data;
-	tvsub(&tv, tp);
-	triptime = tv.tv_sec * 1000000 + tv.tv_usec;
-	h->tsum += triptime;
-	h->tmp_tsum += triptime;
-
-	if (TST(icp->icmp_seq % MAX_DUP_CHK)) {
-	    ++h->rep;
-	    ++h->tmp_rep;
-	    --h->recv;
-	    --h->tmp_recv;
-	    h->dupflag = 1;
-	} else {
-	    SET(icp->icmp_seq % MAX_DUP_CHK);
-	    h->dupflag = 0;
-	}
+        if (icp->icmp_id != ident)
+            return;             /* 'Twas not our ECHO */
+
+        h = (host_data *) g_list_find_custom(hosts,
+                                             (int *) &icp->
+                                             icmp_data[sizeof
+                                                       (struct timeval)],
+                                             compare_nhost)->data;
+        if (h == NULL) return; /* host not found */
+
+        ++h->recv;
+        ++h->tmp_recv;
+
+        tp = (struct timeval *) icp->icmp_data;
+        tvsub(&tv, tp);
+        triptime = tv.tv_sec * 1000000 + tv.tv_usec;
+        h->tsum += triptime;
+        h->tmp_tsum += triptime;
+
+        if (TST(icp->icmp_seq % MAX_DUP_CHK)) {
+            ++h->rep;
+            ++h->tmp_rep;
+            --h->recv;
+            --h->tmp_recv;
+            h->dupflag = 1;
+        } else {
+            SET(icp->icmp_seq % MAX_DUP_CHK);
+            h->dupflag = 0;
+        }
     } else {
-	switch (icp->icmp_type) {
-	case ICMP_ECHO:
-	    return;
-	case ICMP_SOURCE_QUENCH:
-	case ICMP_REDIRECT:
-	case ICMP_DEST_UNREACH:
-	case ICMP_TIME_EXCEEDED:
-	case ICMP_PARAMETERPROB:
-	    {
-		struct ip *iph = (struct ip *) (&icp->icmp_data);
-		struct icmp *icp1 =
-		    (struct icmp *) ((unsigned char *) iph +
-				     iph->ip_hl * 4);
-		int error_pkt;
-
-		if (icp1->icmp_type != ICMP_ECHO ||
-		    iph->ip_src.s_addr != ip->ip_dst.s_addr ||
-		    icp1->icmp_id != ident)
-		    return;
-		error_pkt = (icp->icmp_type != ICMP_REDIRECT &&
-			     icp->icmp_type != ICMP_SOURCE_QUENCH);
-
-		h = (host_data *) g_list_find_custom(hosts,
-						     (int *) &icp1->
-						     icmp_data[sizeof
-							       (struct
-								timeval)],
-						     compare_nhost)->data;
-		if (h) {
-		    h->icp = *icp;
-		    h->error_flag = 1;
-		}
-
-	    }
-	}
+        switch (icp->icmp_type) {
+        case ICMP_ECHO:
+            return;
+        case ICMP_SOURCE_QUENCH:
+        case ICMP_REDIRECT:
+        case ICMP_DEST_UNREACH:
+        case ICMP_TIME_EXCEEDED:
+        case ICMP_PARAMETERPROB:
+            {
+                struct ip *iph = (struct ip *) (&icp->icmp_data);
+                struct icmp *icp1 =
+                    (struct icmp *) ((unsigned char *) iph +
+                                     iph->ip_hl * 4);
+                int error_pkt;
+
+                if (icp1->icmp_type != ICMP_ECHO ||
+                    iph->ip_src.s_addr != ip->ip_dst.s_addr ||
+                    icp1->icmp_id != ident)
+                    return;
+                error_pkt = (icp->icmp_type != ICMP_REDIRECT &&
+                             icp->icmp_type != ICMP_SOURCE_QUENCH);
+
+                h = (host_data *) g_list_find_custom(hosts,
+                                                     (int *) &icp1->
+                                                     icmp_data[sizeof
+                                                               (struct
+                                                                timeval)],
+                                                     compare_nhost)->data;
+                if (h) {
+                    h->icp = *icp;
+                    h->error_flag = 1;
+                }
+
+            }
+        }
     }
 }
 
@@ -522,16 +522,16 @@ int hostname_to_addr(const char *hostname, struct sockaddr *addr)
 
     s = getaddrinfo(hostname, NULL, &hints, &result);
     if (s != 0) {
-	fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
-	return -1;
+        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
+        return -1;
     }
 
     for (rp = result; rp != NULL; rp = rp->ai_next) {
-	if (rp->ai_addr->sa_family == AF_INET) {
-	    *addr = *rp->ai_addr;
-	    ret = 0;
-	    break;
-	}
+        if (rp->ai_addr->sa_family == AF_INET) {
+            *addr = *rp->ai_addr;
+            ret = 0;
+            break;
+        }
     }
 
     freeaddrinfo(result);
@@ -540,15 +540,15 @@ int hostname_to_addr(const char *hostname, struct sockaddr *addr)
 }
 
 // recheck the dns (needed for dialup users or dynamic DNS)
-int update_dns(host_data *h) 
+int update_dns(host_data *h)
 {
     int res;
     struct sockaddr addr;
 
     res = hostname_to_addr(h->hostname->str, &addr);
     if (res == 0) {
-	h->addr  = addr;
-	return 0;
+        h->addr  = addr;
+        return 0;
     }
 
     return 1;
@@ -560,75 +560,75 @@ void ping_host(host_data * h)
     gchar *msg;
 
     if (h->dummy) {
-	if (h->counter == 120) {
-	    if (update_dns(h) == 0) {
-		h->dummy = 0;
-		update_host_stats(h);
-		clear_tmp_flags(h);
-		update_host_packinfo(h);
-		h->phase = STORM_PHASE;
-	    } else {
-		h->phase = STANDBY_PHASE;
-	    }
-	    h->delay = 0;
-	    h->counter = -1;
-	}
-	h->counter++;
-	return;
-    } 
+        if (h->counter == 120) {
+            if (update_dns(h) == 0) {
+                h->dummy = 0;
+                update_host_stats(h);
+                clear_tmp_flags(h);
+                update_host_packinfo(h);
+                h->phase = STORM_PHASE;
+            } else {
+                h->phase = STANDBY_PHASE;
+            }
+            h->delay = 0;
+            h->counter = -1;
+        }
+        h->counter++;
+        return;
+    }
 
     if (!h->dummy && h->dynamic && h->counter == 0) {
-	update_dns(h);
+        update_dns(h);
     }
 
     if (h->error_flag) {
-	msg = pr_icmph(&h->icp);
-	write_result(h, msg, "Err");
-	g_free(msg);
+        msg = pr_icmph(&h->icp);
+        write_result(h, msg, "Err");
+        g_free(msg);
     }
 
 //    fprintf(stderr, "pinger: ping_host, No. %d, delay = %d\n", h->nhost, h->delay);
 
     switch (h->phase) {
     case STORM_PHASE:
-	if (h->counter == 7 || h->counter == 15 || h->counter == 23) {
-	    update_host_stats(h);
-	    clear_tmp_flags(h);
-	}
-	if ((h->counter >= 0 && h->counter < 4)
-	    || (h->counter >= 8 && h->counter < 12)
-	    || (h->counter >= 16 && h->counter < 20)) {
-	    if (has_pinged) {
-		h->delay++;
-		goto dontpingyet;
-	    }
-	    pinger(h);
-	    h->delay = 0;
-	}
-	
-	if (h->counter == 59) {
-	    h->counter = -1;
-	    h->phase = STANDBY_PHASE;
-	}
-	break;
+        if (h->counter == 7 || h->counter == 15 || h->counter == 23) {
+            update_host_stats(h);
+            clear_tmp_flags(h);
+        }
+        if ((h->counter >= 0 && h->counter < 4)
+            || (h->counter >= 8 && h->counter < 12)
+            || (h->counter >= 16 && h->counter < 20)) {
+            if (has_pinged) {
+                h->delay++;
+                goto dontpingyet;
+            }
+            pinger(h);
+            h->delay = 0;
+        }
+
+        if (h->counter == 59) {
+            h->counter = -1;
+            h->phase = STANDBY_PHASE;
+        }
+        break;
     case STANDBY_PHASE:
-	if (h->counter == 7) {
-	    update_host_stats(h);
-	    clear_tmp_flags(h);
-	}
-	if (h->counter >= 0 && h->counter < 4) {
-	    if (has_pinged) {
-		h->delay++;
-		goto dontpingyet;
-	    }
-	    pinger(h);
-	    h->delay = 0;
-	}
-	if (h->counter == h->updatefreq) {
-	    h->counter = -1;
-	    h->phase = STANDBY_PHASE;
-	}
-	break;
+        if (h->counter == 7) {
+            update_host_stats(h);
+            clear_tmp_flags(h);
+        }
+        if (h->counter >= 0 && h->counter < 4) {
+            if (has_pinged) {
+                h->delay++;
+                goto dontpingyet;
+            }
+            pinger(h);
+            h->delay = 0;
+        }
+        if (h->counter == h->updatefreq) {
+            h->counter = -1;
+            h->phase = STANDBY_PHASE;
+        }
+        break;
     }
 
     h->counter++;
@@ -665,28 +665,28 @@ void receiver()
     gettimeofday(&tv_old, NULL);
     fromlen = sizeof(from);
     for (;!terminated;) {
-	FD_ZERO(&rfds);
-	FD_SET(icmp_socket, &rfds);
-
-	tv.tv_usec = 100000;
-	tv.tv_sec = 0;
-
-	avail = select(icmp_socket + 1, &rfds, NULL, NULL, &tv);
-
-	if (avail) {
-	    if ((cc = recvfrom(icmp_socket, (char *) packet, packlen, 0,
-			       (struct sockaddr *) &from, &fromlen)) < 0) {
-		perror("ping: recvfrom");
-	    } else {
-		pr_pack((char *) packet, cc, &from);
-	    }
-	}
-	gettimeofday(&tv_new, NULL);
-	tvsub(&tv_new, &tv_old);
-	if (tv_new.tv_sec >= 1) {
-	    gettimeofday(&tv_old, NULL);
-	    timeout_callback();
-	}
+        FD_ZERO(&rfds);
+        FD_SET(icmp_socket, &rfds);
+
+        tv.tv_usec = 100000;
+        tv.tv_sec = 0;
+
+        avail = select(icmp_socket + 1, &rfds, NULL, NULL, &tv);
+
+        if (avail) {
+            if ((cc = recvfrom(icmp_socket, (char *) packet, packlen, 0,
+                               (struct sockaddr *) &from, &fromlen)) < 0) {
+                perror("ping: recvfrom");
+            } else {
+                pr_pack((char *) packet, cc, &from);
+            }
+        }
+        gettimeofday(&tv_new, NULL);
+        tvsub(&tv_new, &tv_old);
+        if (tv_new.tv_sec >= 1) {
+            gettimeofday(&tv_old, NULL);
+            timeout_callback();
+        }
     }
 }
 
@@ -703,43 +703,43 @@ void update_host_stats(host_data * h)
     GString *s2 = g_string_new(NULL);
 
     if (h->tmp_sent > 0) {
-	g_string_sprintf(s, "%d", h->tmp_recv * 100 / h->tmp_sent);
-	g_string_assign(h->percentage, s->str);
+        g_string_sprintf(s, "%d", h->tmp_recv * 100 / h->tmp_sent);
+        g_string_assign(h->percentage, s->str);
     } else {
-	g_string_assign(h->percentage, "");
+        g_string_assign(h->percentage, "");
     }
 
     if (h->tmp_recv > 0) {
-	trip = h->tmp_tsum / (h->tmp_recv + h->tmp_rep);
-	if (trip >= 1000000) {
-	    g_string_sprintf(s, "%ld.%03ld s", trip / 1000000,
-			     (trip % 1000000) / 1000);
-	    g_string_sprintf(s2, ">s");
-	} else if (trip >= 10000) {
-	    g_string_sprintf(s, "%ld.%03ld ms", trip / 1000, trip % 1000);
-	    g_string_sprintf(s2, "%ld", trip / 1000);
-	} else if (trip >= 1000) {
-	    g_string_sprintf(s, "%ld.%03ld ms", trip / 1000, trip % 1000);
-	    g_string_sprintf(s2, "%ld.%01ld", trip / 1000,
-			     (trip % 1000) / 100);
-	} else {
-	    g_string_sprintf(s, "0.%01ld ms", trip / 100);
-	    g_string_sprintf(s2, "0.%01ld", trip / 100);
-	}
-	write_result(h, s->str, s2->str);
+        trip = h->tmp_tsum / (h->tmp_recv + h->tmp_rep);
+        if (trip >= 1000000) {
+            g_string_sprintf(s, "%ld.%03ld s", trip / 1000000,
+                             (trip % 1000000) / 1000);
+            g_string_sprintf(s2, ">s");
+        } else if (trip >= 10000) {
+            g_string_sprintf(s, "%ld.%03ld ms", trip / 1000, trip % 1000);
+            g_string_sprintf(s2, "%ld", trip / 1000);
+        } else if (trip >= 1000) {
+            g_string_sprintf(s, "%ld.%03ld ms", trip / 1000, trip % 1000);
+            g_string_sprintf(s2, "%ld.%01ld", trip / 1000,
+                             (trip % 1000) / 100);
+        } else {
+            g_string_sprintf(s, "0.%01ld ms", trip / 100);
+            g_string_sprintf(s2, "0.%01ld", trip / 100);
+        }
+        write_result(h, s->str, s2->str);
     }
 
     g_string_free(s, TRUE);
     g_string_free(s2, TRUE);
 
     if (h->dummy) {
-	write_result(h, "Dummy host", "##");
-	return;
+        write_result(h, "Dummy host", "##");
+        return;
     }
 
     if (!h->error_flag) {
-	if (h->tmp_sent > 0 && h->tmp_recv == 0)
-	    write_result(h, "Request timed out", "TO");
+        if (h->tmp_sent > 0 && h->tmp_recv == 0)
+            write_result(h, "Request timed out", "TO");
     }
 
 }
@@ -773,15 +773,15 @@ void append_host(struct sockaddr addr, char * hostname, char * updatefreq, char
     h->counter = 0;
     h->delay = 0;
     if (updatefreq) {
-	h->updatefreq = atoi(updatefreq);
-	if (h->updatefreq < 30) {
-	    h->updatefreq = 30;
-	}
-	if (h->updatefreq > 3600) {
-	    h->updatefreq = 3600;
-	}
+        h->updatefreq = atoi(updatefreq);
+        if (h->updatefreq < 30) {
+            h->updatefreq = 30;
+        }
+        if (h->updatefreq > 3600) {
+            h->updatefreq = 3600;
+        }
     } else {
-	h->updatefreq = 59;
+        h->updatefreq = 59;
     }
 
     h->dynamic = atoi(dynamic) ? 1 : 0;
@@ -811,15 +811,15 @@ int main(int argc, char **argv)
 
     struct protoent *proto;
     if (!(proto = getprotobyname("icmp"))) {
-	(void) fprintf(stderr, "pinger: unknown protocol icmp.\n");
-	exit(2);
+        (void) fprintf(stderr, "pinger: unknown protocol icmp.\n");
+        exit(2);
     }
     if ((icmp_socket = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {
-	if (errno == EPERM) {
-	    fprintf(stderr, "pinger: must run as root\n");
-	} else
-	    perror("pinger: socket");
-	exit(2);
+        if (errno == EPERM) {
+            fprintf(stderr, "pinger: must run as root\n");
+        } else
+            perror("pinger: socket");
+        exit(2);
     }
 
     setuid(getuid());
@@ -828,21 +828,21 @@ int main(int argc, char **argv)
     ident = getpid() & 0xFFFF;
 
     for (i = 1; i < argc - 2; i += 3) {
-	struct sockaddr addr;
-	int res;
-
-	res = hostname_to_addr(argv[i], &addr);
-	if (res == 0) {
-	    append_host(addr, argv[i], argv[i+1], argv[i+2], 0);
-	} else if (i <= argc-3) {
-	    memset(&addr, 0, sizeof(addr));
-	    addr.sa_family = AF_INET;
-	    append_host(addr, argv[i], argv[i+1], argv[i+2], 1); // dummy host
-	}
+        struct sockaddr addr;
+        int res;
+
+        res = hostname_to_addr(argv[i], &addr);
+        if (res == 0) {
+            append_host(addr, argv[i], argv[i+1], argv[i+2], 0);
+        } else if (i <= argc-3) {
+            memset(&addr, 0, sizeof(addr));
+            addr.sa_family = AF_INET;
+            append_host(addr, argv[i], argv[i+1], argv[i+2], 1); // dummy host
+        }
     }
 
     sigfillset(&sig.sa_mask);
-    sig.sa_flags = SA_SIGINFO | SA_RESTART;    
+    sig.sa_flags = SA_SIGINFO | SA_RESTART;
     sig.sa_sigaction = term_signal;
 
     sigaction(SIGINT, &sig, 0);