Changed `int isVerbose` global to `bool verbose`.
[icmpmonitor] / icmpmonitor.c
index 04aa91c..365192f 100644 (file)
@@ -52,9 +52,8 @@ struct monitor_host {
 
 /* globals */
 static struct monitor_host ** hosts       = NULL;
 
 /* globals */
 static struct monitor_host ** hosts       = NULL;
-static int                    isVerbose   = 0;
+static bool                   verbose     = false;
 static int                    keepBanging = 0;
 static int                    keepBanging = 0;
-static unsigned short         ident;
 static int                    send_delay  = 1;
 
 /*
 static int                    send_delay  = 1;
 
 /*
@@ -131,7 +130,7 @@ pinger(int ignore)
 
             if (now.tv_sec > (p->max_delay + p->ping_interval)) {
                 if ((p->hostup) || keepBanging) {
 
             if (now.tv_sec > (p->max_delay + p->ping_interval)) {
                 if ((p->hostup) || keepBanging) {
-                    if (isVerbose) printf("INFO: Host %s stopped responding. Executing DOWN command.\n", p->name);
+                    if (verbose) printf("INFO: Host %s stopped responding. Executing DOWN command.\n", p->name);
                     p->hostup = false;
                     if (!fork()) {
                         system(p->downcmd);
                     p->hostup = false;
                     if (!fork()) {
                         system(p->downcmd);
@@ -151,9 +150,9 @@ pinger(int ignore)
                 icp->icmp_code  = 0;
                 icp->icmp_cksum = 0;
                 icp->icmp_seq   = p->socket;
                 icp->icmp_code  = 0;
                 icp->icmp_cksum = 0;
                 icp->icmp_seq   = p->socket;
-                icp->icmp_id    = ident;
+                icp->icmp_id    = getpid() & 0xFFFF;
 
 
-                if (isVerbose) printf("INFO: Sending ICMP packet to %s.\n", p->name);
+                if (verbose) printf("INFO: Sending ICMP packet to %s.\n", p->name);
 
                 gettimeofday((struct timeval *) &outpack[8], (struct timezone *) NULL);
 
 
                 gettimeofday((struct timeval *) &outpack[8], (struct timezone *) NULL);
 
@@ -208,7 +207,7 @@ read_icmp_data(struct monitor_host * p)
         return;
     }
 
         return;
     }
 
-    if (icmp->icmp_type == ICMP_ECHOREPLY && icmp->icmp_id == ident && icmp->icmp_seq == p->socket) {
+    if (icmp->icmp_type == ICMP_ECHOREPLY && icmp->icmp_id == (getpid() & 0xFFFF) && icmp->icmp_seq == p->socket) {
         p->recvdpackets++;
 
         memcpy(&p->last_ping_received, &tv, sizeof(tv));
         p->recvdpackets++;
 
         memcpy(&p->last_ping_received, &tv, sizeof(tv));
@@ -216,9 +215,9 @@ read_icmp_data(struct monitor_host * p)
         tvsub(&tv, (struct timeval *) &icmp->icmp_data[0]);
         delay = tv.tv_sec * 1000 + (tv.tv_usec / 1000);
 
         tvsub(&tv, (struct timeval *) &icmp->icmp_data[0]);
         delay = tv.tv_sec * 1000 + (tv.tv_usec / 1000);
 
-        if (isVerbose) printf("INFO: Got ICMP reply from %s in %d ms.\n", p->name, delay);
+        if (verbose) printf("INFO: Got ICMP reply from %s in %d ms.\n", p->name, delay);
         if (!p->hostup) {
         if (!p->hostup) {
-            if (isVerbose) printf("INFO: Host %s started responding. Executing UP command.\n", p->name);
+            if (verbose) printf("INFO: Host %s started responding. Executing UP command.\n", p->name);
             p->hostup = true;
             if (!fork()) {
                 system(p->upcmd);
             p->hostup = true;
             if (!fork()) {
                 system(p->upcmd);
@@ -398,7 +397,7 @@ main(int argc, char ** argv)
     while ((param = getopt(argc, argv, "rvf:")) != -1) {
         switch(param) {
             case 'v':
     while ((param = getopt(argc, argv, "rvf:")) != -1) {
         switch(param) {
             case 'v':
-                isVerbose = 1;
+                verbose = true;
                 break;
             case 'r':
                 keepBanging = 1;
                 break;
             case 'r':
                 keepBanging = 1;
@@ -421,8 +420,6 @@ main(int argc, char ** argv)
 
     init_hosts();
 
 
     init_hosts();
 
-    ident = getpid() & 0xFFFF;
-
     signal(SIGALRM, pinger);
     alarm(send_delay);
 
     signal(SIGALRM, pinger);
     alarm(send_delay);