]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Translate UDP/1700 as RADIUS
[tcpdump] / tcpdump.c
index 8a171c3997b81724a615b8a52e261239f7dd6037..de8f63307d65c640e4ff88fe21d090624ace9f93 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -299,23 +299,21 @@ show_dlts_and_exit(const char *device)
 static void
 show_devices_and_exit (void)
 {
 static void
 show_devices_and_exit (void)
 {
-       pcap_if_t *devpointer;
+       pcap_if_t *dev, *devlist;
        char ebuf[PCAP_ERRBUF_SIZE];
        int i;
 
        char ebuf[PCAP_ERRBUF_SIZE];
        int i;
 
-       if (pcap_findalldevs(&devpointer, ebuf) < 0)
+       if (pcap_findalldevs(&devlist, ebuf) < 0)
                error("%s", ebuf);
                error("%s", ebuf);
-       else {
-               for (i = 0; devpointer != NULL; i++) {
-                       printf("%d.%s", i+1, devpointer->name);
-                       if (devpointer->description != NULL)
-                               printf(" (%s)", devpointer->description);
-                       if (devpointer->flags != 0)
-                               printf(" [%s]", bittok2str(status_flags, "none", devpointer->flags));
-                       printf("\n");
-                       devpointer = devpointer->next;
-               }
+       for (i = 0, dev = devlist; dev != NULL; i++, dev = dev->next) {
+               printf("%d.%s", i+1, dev->name);
+               if (dev->description != NULL)
+                       printf(" (%s)", dev->description);
+               if (dev->flags != 0)
+                       printf(" [%s]", bittok2str(status_flags, "none", dev->flags));
+               printf("\n");
        }
        }
+       pcap_freealldevs(devlist);
        exit(0);
 }
 #endif /* HAVE_PCAP_FINDALLDEVS */
        exit(0);
 }
 #endif /* HAVE_PCAP_FINDALLDEVS */
@@ -716,7 +714,7 @@ main(int argc, char **argv)
        char *ret = NULL;
        char *end;
 #ifdef HAVE_PCAP_FINDALLDEVS
        char *ret = NULL;
        char *end;
 #ifdef HAVE_PCAP_FINDALLDEVS
-       pcap_if_t *devpointer;
+       pcap_if_t *dev, *devlist;
        int devnum;
 #endif
        int status;
        int devnum;
 #endif
        int status;
@@ -883,22 +881,20 @@ main(int argc, char **argv)
                                if (devnum < 0)
                                        error("Invalid adapter index");
 
                                if (devnum < 0)
                                        error("Invalid adapter index");
 
-                               if (pcap_findalldevs(&devpointer, ebuf) < 0)
+                               if (pcap_findalldevs(&devlist, ebuf) < 0)
                                        error("%s", ebuf);
                                        error("%s", ebuf);
-                               else {
-                                       /*
-                                        * Look for the devnum-th entry
-                                        * in the list of devices
-                                        * (1-based).
-                                        */
-                                       for (i = 0;
-                                           i < devnum-1 && devpointer != NULL;
-                                           i++, devpointer = devpointer->next)
-                                               ;
-                                       if (devpointer == NULL)
-                                               error("Invalid adapter index");
-                               }
-                               device = devpointer->name;
+                               /*
+                                * Look for the devnum-th entry in the
+                                * list of devices (1-based).
+                                */
+                               for (i = 0, dev = devlist;
+                                   i < devnum-1 && dev != NULL;
+                                   i++, dev = dev->next)
+                                       ;
+                               if (dev == NULL)
+                                       error("Invalid adapter index");
+                               device = strdup(dev->name);
+                               pcap_freealldevs(devlist);
                                break;
                        }
 #endif /* HAVE_PCAP_FINDALLDEVS */
                                break;
                        }
 #endif /* HAVE_PCAP_FINDALLDEVS */
@@ -1251,7 +1247,7 @@ main(int argc, char **argv)
                                VFile = fopen(VFileName, "r");
 
                        if (VFile == NULL)
                                VFile = fopen(VFileName, "r");
 
                        if (VFile == NULL)
-                               error("Unable to open file: %s\n", strerror(errno));
+                               error("Unable to open file: %s\n", pcap_strerror(errno));
 
                        ret = get_next_file(VFile, VFileLine);
                        if (!ret)
 
                        ret = get_next_file(VFile, VFileLine);
                        if (!ret)
@@ -1291,7 +1287,15 @@ main(int argc, char **argv)
                 * We're doing a live capture.
                 */
                if (device == NULL) {
                 * We're doing a live capture.
                 */
                if (device == NULL) {
+#ifdef HAVE_PCAP_FINDALLDEVS
+                       if (pcap_findalldevs(&devlist, ebuf) >= 0 &&
+                           devlist != NULL) {
+                               device = strdup(devlist->name);
+                               pcap_freealldevs(devlist);
+                       }
+#else /* HAVE_PCAP_FINDALLDEVS */
                        device = pcap_lookupdev(ebuf);
                        device = pcap_lookupdev(ebuf);
+#endif
                        if (device == NULL)
                                error("%s", ebuf);
                }
                        if (device == NULL)
                                error("%s", ebuf);
                }
@@ -1551,7 +1555,7 @@ main(int argc, char **argv)
                error("%s", pcap_geterr(pd));
 #ifdef HAVE_CAPSICUM
        if (RFileName == NULL && VFileName == NULL) {
                error("%s", pcap_geterr(pd));
 #ifdef HAVE_CAPSICUM
        if (RFileName == NULL && VFileName == NULL) {
-               static const unsigned long cmds[] = { BIOCGSTATS };
+               static const unsigned long cmds[] = { BIOCGSTATS, BIOCROTZBUF };
 
                cap_rights_init(&rights, CAP_IOCTL, CAP_READ);
                if (cap_rights_limit(pcap_fileno(pd), &rights) < 0 &&
 
                cap_rights_init(&rights, CAP_IOCTL, CAP_READ);
                if (cap_rights_limit(pcap_fileno(pd), &rights) < 0 &&
@@ -1880,17 +1884,31 @@ info(register int verbose)
 }
 
 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
 }
 
 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
+#ifdef HAVE_FORK
+#define fork_subprocess() fork()
+#else
+#define fork_subprocess() vfork()
+#endif
 static void
 compress_savefile(const char *filename)
 {
 static void
 compress_savefile(const char *filename)
 {
-# ifdef HAVE_FORK
-       if (fork())
-# else
-       if (vfork())
-# endif
+       pid_t child;
+
+       child = fork_subprocess();
+       if (child == -1) {
+               fprintf(stderr,
+                       "compress_savefile: fork failed: %s\n",
+                       pcap_strerror(errno));
                return;
                return;
+       }
+       if (child != 0) {
+               /* Parent process. */
+               return;
+       }
+
        /*
        /*
-        * Set to lowest priority so that this doesn't disturb the capture
+        * Child process.
+        * Set to lowest priority so that this doesn't disturb the capture.
         */
 #ifdef NZERO
        setpriority(PRIO_PROCESS, 0, NZERO - 1);
         */
 #ifdef NZERO
        setpriority(PRIO_PROCESS, 0, NZERO - 1);
@@ -1899,15 +1917,15 @@ compress_savefile(const char *filename)
 #endif
        if (execlp(zflag, zflag, filename, (char *)NULL) == -1)
                fprintf(stderr,
 #endif
        if (execlp(zflag, zflag, filename, (char *)NULL) == -1)
                fprintf(stderr,
-                       "compress_savefile:execlp(%s, %s): %s\n",
+                       "compress_savefile: execlp(%s, %s) failed: %s\n",
                        zflag,
                        filename,
                        zflag,
                        filename,
-                       strerror(errno));
-# ifdef HAVE_FORK
+                       pcap_strerror(errno));
+#ifdef HAVE_FORK
        exit(1);
        exit(1);
-# else
+#else
        _exit(1);
        _exit(1);
-# endif
+#endif
 }
 #else  /* HAVE_FORK && HAVE_VFORK */
 static void
 }
 #else  /* HAVE_FORK && HAVE_VFORK */
 static void
@@ -2195,17 +2213,13 @@ RETSIGTYPE requestinfo(int signo _U_)
 void CALLBACK verbose_stats_dump (UINT timer_id _U_, UINT msg _U_, DWORD_PTR arg _U_,
                                  DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
 {
 void CALLBACK verbose_stats_dump (UINT timer_id _U_, UINT msg _U_, DWORD_PTR arg _U_,
                                  DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
 {
-       struct pcap_stat stat;
-
-       if (infodelay == 0 && pcap_stats(pd, &stat) >= 0)
+       if (infodelay == 0)
                fprintf(stderr, "Got %u\r", packets_captured);
 }
 #elif defined(HAVE_ALARM)
 static void verbose_stats_dump(int sig _U_)
 {
                fprintf(stderr, "Got %u\r", packets_captured);
 }
 #elif defined(HAVE_ALARM)
 static void verbose_stats_dump(int sig _U_)
 {
-       struct pcap_stat stat;
-
-       if (infodelay == 0 && pcap_stats(pd, &stat) >= 0)
+       if (infodelay == 0)
                fprintf(stderr, "Got %u\r", packets_captured);
        alarm(1);
 }
                fprintf(stderr, "Got %u\r", packets_captured);
        alarm(1);
 }