Misc minor updates.
[icmpmonitor] / icmpmonitor.c
index bf5ab9b..8b176b9 100644 (file)
@@ -1,10 +1,13 @@
 /*
 /*
- * Monitor hosts using ICMP "echo" and notify when down.
- * TODO: Write a better description.
+ * ICMPmonitor
+ *
+ * Monitors hosts using ICMP 'echo', executing a user-specified command
+ * whenever hosts change state between responsive and unresponsive.
  *
  * © 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
  * © 1999 Vadim Zaliva <lord@crocodile.org>
  * © 1989 The Regents of the University of California & Mike Muuss
  *
  * © 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
  * © 1999 Vadim Zaliva <lord@crocodile.org>
  * © 1989 The Regents of the University of California & Mike Muuss
+ *
  * See LICENSE file for copyright and license details.
  */
 
  * See LICENSE file for copyright and license details.
  */
 
@@ -24,6 +27,7 @@
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h>
 #include <errno.h>
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h>
 #include <errno.h>
+
 #include "iniparser/iniparser.h"
 
 #define VERSION 2
 #include "iniparser/iniparser.h"
 
 #define VERSION 2
@@ -49,8 +53,6 @@ struct monitor_host {
     struct timeval     last_ping_sent;
     bool               host_up;
     struct sockaddr_in dest;
     struct timeval     last_ping_sent;
     bool               host_up;
     struct sockaddr_in dest;
-    unsigned int       sent_packets;
-    unsigned int       recvd_packets;
 
     /* TODO: Why are we using both a linked list AND an array for this data? */
     /* Linked list */
 
     /* TODO: Why are we using both a linked list AND an array for this data? */
     /* Linked list */
@@ -125,7 +127,7 @@ tv_sub(register struct timeval * out, register struct timeval * in)
 static void
 pinger(int ignore)
 {
 static void
 pinger(int ignore)
 {
-    int cc, i;
+    int i;
     struct icmp * icp;
     struct monitor_host * p;
     u_char outpack[MAXPACKETSIZE];
     struct icmp * icp;
     struct monitor_host * p;
     u_char outpack[MAXPACKETSIZE];
@@ -166,7 +168,7 @@ pinger(int ignore)
 
                 gettimeofday((struct timeval *) &outpack[8], (struct timezone *) NULL);
 
 
                 gettimeofday((struct timeval *) &outpack[8], (struct timezone *) NULL);
 
-                cc = DEFAULTDATALEN + 8;  /* skips ICMP portion */
+                int cc = DEFAULTDATALEN + 8;  /* skips ICMP portion */
 
                 /* compute ICMP checksum */
                 icp->icmp_cksum = in_cksum((unsigned short *) icp, cc);
 
                 /* compute ICMP checksum */
                 icp->icmp_cksum = in_cksum((unsigned short *) icp, cc);
@@ -178,7 +180,6 @@ pinger(int ignore)
                 if (i < 0 || i != cc) {
                     if (i<0) fprintf(stderr, "WARN: Failed sending ICMP packet to %s.\n", p->name);
                 }
                 if (i < 0 || i != cc) {
                     if (i<0) fprintf(stderr, "WARN: Failed sending ICMP packet to %s.\n", p->name);
                 }
-                p->sent_packets++;
             }
         }
         p = p->next;
             }
         }
         p = p->next;
@@ -218,7 +219,6 @@ read_icmp_data(struct monitor_host * p)
     }
 
     if (icmp->icmp_type == ICMP_ECHOREPLY && icmp->icmp_id == (getpid() & 0xFFFF) && icmp->icmp_seq == p->socket) {
     }
 
     if (icmp->icmp_type == ICMP_ECHOREPLY && icmp->icmp_id == (getpid() & 0xFFFF) && icmp->icmp_seq == p->socket) {
-        p->recvd_packets++;
 
         memcpy(&p->last_ping_received, &tv, sizeof(tv));
 
 
         memcpy(&p->last_ping_received, &tv, sizeof(tv));
 
@@ -332,8 +332,6 @@ parse_config(const char * conf_file)
             exit(EXIT_FAILURE);
         }
 
             exit(EXIT_FAILURE);
         }
 
-        hosts[i]->sent_packets = 0;
-        hosts[i]->recvd_packets = 0;
         hosts[i]->socket = -1;
         hosts[i]->next = NULL;
         if (i>0) hosts[i-1]->next = hosts[i];
         hosts[i]->socket = -1;
         hosts[i]->next = NULL;
         if (i>0) hosts[i-1]->next = hosts[i];