]> The Tcpdump Group git mirrors - libpcap/commitdiff
Make findalldevstest exit with an exit status of 2 on an error.
authorGuy Harris <[email protected]>
Thu, 12 Feb 2015 22:25:30 +0000 (14:25 -0800)
committerGuy Harris <[email protected]>
Thu, 12 Feb 2015 22:25:30 +0000 (14:25 -0800)
That'll let us make Travis builds fail if the test fails.

tests/findalldevstest.c

index a8e4d1e93fa7373e3c5461c8a097d141deb67589..6d452f8feb14f554141312ad9d119f95228e66aa 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <pcap.h>
 
-static void ifprint(pcap_if_t *d);
+static int ifprint(pcap_if_t *d);
 static char *iptos(bpf_u_int32 in);
 
 int main(int argc, char **argv)
@@ -20,6 +20,7 @@ int main(int argc, char **argv)
   pcap_if_t *d;
   char *s;
   bpf_u_int32 net, mask;
+  int exit_status = 0;
 
   char errbuf[PCAP_ERRBUF_SIZE+1];
   if (pcap_findalldevs(&alldevs, errbuf) == -1)
@@ -29,12 +30,14 @@ int main(int argc, char **argv)
   }
   for(d=alldevs;d;d=d->next)
   {
-    ifprint(d);
+    if (!ifprint(d))
+      exit_status = 2;
   }
 
   if ( (s = pcap_lookupdev(errbuf)) == NULL)
   {
     fprintf(stderr,"Error in pcap_lookupdev: %s\n",errbuf);
+    exit_status = 2;
   }
   else
   {
@@ -44,21 +47,23 @@ int main(int argc, char **argv)
   if (pcap_lookupnet(s, &net, &mask, errbuf) < 0)
   {
     fprintf(stderr,"Error in pcap_lookupnet: %s\n",errbuf);
+    exit_status = 2;
   }
   else
   {
     printf("Preferred device is on network: %s/%s\n",iptos(net), iptos(mask));
   }
 
-  exit(0);
+  exit(exit_status);
 }
 
-static void ifprint(pcap_if_t *d)
+static int ifprint(pcap_if_t *d)
 {
   pcap_addr_t *a;
 #ifdef INET6
   char ntop_buf[INET6_ADDRSTRLEN];
 #endif
+  int status = 1; /* success */
 
   printf("%s\n",d->name);
   if (d->description)
@@ -113,9 +118,13 @@ static void ifprint(pcap_if_t *d)
         break;
       }
     else
+    {
       fprintf(stderr, "\tWarning: a->addr is NULL, skipping this address.\n");
+      status = 0;
+    }
   }
   printf("\n");
+  return status;
 }
 
 /* From tcptraceroute */