Jindrich Makovicka 22 лет назад
Родитель
Сommit
d836b93963
3 измененных файлов с 28 добавлено и 4 удалено
  1. 3 0
      ChangeLog
  2. 1 1
      Makefile
  3. 24 3
      pinger.c

+ 3 - 0
ChangeLog

@@ -1,3 +1,6 @@
+2.0.8
+	* pinger produced bogus results when fed with a non-existent
+	host - fixed
 2.0.7
 	* fixes
 2.0.6

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 INSTALLDIR = /usr/local/lib/gkrellm2/plugins
-VERSION = 2.0.7
+VERSION = 2.0.8
 PKGNAME = gkrellm-multiping
 #OPT = -march=athlon -O2
 #CC = gcc-3.0

+ 24 - 3
pinger.c

@@ -73,6 +73,7 @@ int has_pinged;
 typedef struct _host_data {
     int nhost;			// cislo poce
     GString *percentage, *sent_str, *recv_str, *msg, *shortmsg;
+    int dummy;
     struct sockaddr addr;
     int sent, recv, rep;
     int tmp_sent, tmp_recv, tmp_rep;
@@ -502,6 +503,18 @@ void ping_host(host_data * h)
 {
     gchar *msg;
 
+    if (h->dummy) {
+	if (h->counter == 0) {
+	    update_host_stats(h);
+	    clear_tmp_flags(h);
+	    h->delay = 0;
+	    h->counter = -1;
+	    h->phase = STANDBY_PHASE;
+	    update_host_packinfo(h);
+	}
+	return;
+    }
+    
     if (h->error_flag) {
 	msg = pr_icmph(&h->icp);
 	write_result(h, msg, "Err");
@@ -653,6 +666,11 @@ void update_host_stats(host_data * h)
     g_string_free(s, TRUE);
     g_string_free(s2, TRUE);
 
+    if (h->dummy) {
+	write_result(h, "Dummy host", "##");
+	return;
+    }
+
     if (!h->error_flag) {
 	if (h->tmp_recv == 0)
 	    write_result(h, "Request timed out", "TO");
@@ -661,13 +679,15 @@ void update_host_stats(host_data * h)
 }
 
 
-void append_host(struct in_addr ip, char * updatefreq)
+void append_host(struct in_addr ip, char * updatefreq, int dummy)
 {
     host_data *h = host_malloc();
 
     ((struct sockaddr_in *) &h->addr)->sin_addr = ip;
     ((struct sockaddr_in *) &h->addr)->sin_family = AF_INET;
 
+    h->dummy = dummy;
+
     h->nhost = hostcnt++;
 
     h->sent = 0;
@@ -753,11 +773,12 @@ int main(int argc, char **argv)
 	if (h && h->h_addr_list[0]) {
 	    i++;
 	    if (i <= argc) {
-		append_host(*(struct in_addr*)h->h_addr_list[0],argv[i]);
+		append_host(*(struct in_addr*)h->h_addr_list[0],argv[i],0);
 	    }
 	} else {
 	    memset(&ip, 0, sizeof(ip));
-	    append_host((struct in_addr)ip, 0);
+	    append_host((struct in_addr)ip, 0, 1); // dummy host
+	    i++;
 	}
     }