]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
in some cases we expect tcpdump to fail with an error code
[tcpdump] / tcpdump.c
index b1f88cf37af8118e089781dcfb49d4cadf077d37..07fc62967246d4c4f7d41aca80ddf6966ead2d02 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -193,22 +193,12 @@ static void info(int);
 static u_int packets_captured;
 
 struct printer {
-        if_printer f;
-       int type;
-};
-
-
-struct ndo_printer {
-        if_ndo_printer f;
+       if_printer f;
        int type;
 };
 
 
 static const struct printer printers[] = {
-       { NULL,                 0 },
-};
-
-static const struct ndo_printer ndo_printers[] = {
        { ether_if_print,       DLT_EN10MB },
 #ifdef DLT_IPNET
        { ipnet_if_print,       DLT_IPNET },
@@ -408,19 +398,6 @@ lookup_printer(int type)
                if (type == p->type)
                        return p->f;
 
-       return NULL;
-       /* NOTREACHED */
-}
-
-if_ndo_printer
-lookup_ndo_printer(int type)
-{
-       const struct ndo_printer *p;
-
-       for (p = ndo_printers; p->f; ++p)
-               if (type == p->type)
-                       return p->f;
-
 #if defined(DLT_USER2) && defined(DLT_PKTAP)
        /*
         * Apple incorrectly chose to use DLT_USER2 for their PKTAP
@@ -439,7 +416,7 @@ lookup_ndo_printer(int type)
         * that.
         */
        if (type == DLT_USER2) {
-               for (p = ndo_printers; p->f; ++p)
+               for (p = printers; p->f; ++p)
                        if (DLT_PKTAP == p->type)
                                return p->f;
        }
@@ -459,11 +436,7 @@ extern char *optarg;
 
 struct print_info {
         netdissect_options *ndo;
-        union {
-                if_printer     printer;
-                if_ndo_printer ndo_printer;
-        } p;
-        int ndo_type;
+        if_printer printer;
 };
 
 struct dump_info {
@@ -548,8 +521,7 @@ show_dlts_and_exit(const char *device, pcap_t *pd)
                        /*
                         * OK, does tcpdump handle that type?
                         */
-                       if (lookup_printer(dlts[n_dlts]) == NULL
-                            && lookup_ndo_printer(dlts[n_dlts]) == NULL)
+                       if (lookup_printer(dlts[n_dlts]) == NULL)
                                (void) fprintf(stderr, " (printing not supported)");
                        fprintf(stderr, "\n");
                } else {
@@ -862,20 +834,15 @@ get_print_info(int type)
 {
        struct print_info printinfo;
 
-       printinfo.ndo_type = 1;
        printinfo.ndo = gndo;
-       printinfo.p.ndo_printer = lookup_ndo_printer(type);
-       if (printinfo.p.ndo_printer == NULL) {
-               printinfo.p.printer = lookup_printer(type);
-               printinfo.ndo_type = 0;
-               if (printinfo.p.printer == NULL) {
-                       gndo->ndo_dltname = pcap_datalink_val_to_name(type);
-                       if (gndo->ndo_dltname != NULL)
-                               error("packet printing is not supported for link type %s: use -w",
-                                     gndo->ndo_dltname);
-                       else
-                               error("packet printing is not supported for link type %d: use -w", type);
-               }
+       printinfo.printer = lookup_printer(type);
+       if (printinfo.printer == NULL) {
+               gndo->ndo_dltname = pcap_datalink_val_to_name(type);
+               if (gndo->ndo_dltname != NULL)
+                       error("packet printing is not supported for link type %s: use -w",
+                             gndo->ndo_dltname);
+               else
+                       error("packet printing is not supported for link type %d: use -w", type);
        }
        return (printinfo);
 }
@@ -980,8 +947,9 @@ tstamp_precision_to_string(int precision)
  *        what the standard I/O library happens to require this week.
  */
 static void
-set_dump_fd_capsicum_rights(int fd)
+set_dumper_capsicum_rights(pcap_dumper_t *p)
 {
+       int fd = fileno(pcap_dump_file(p));
        cap_rights_t rights;
 
        cap_rights_init(&rights, CAP_SEEK, CAP_WRITE, CAP_FCNTL);
@@ -1894,7 +1862,7 @@ main(int argc, char **argv)
                if (p == NULL)
                        error("%s", pcap_geterr(pd));
 #ifdef HAVE_CAPSICUM
-               set_dump_fd_capsicum_rights(fileno(pcap_dump_file(p)));
+               set_dumper_capsicum_rights(p);
 #endif
                if (Cflag != 0 || Gflag != 0) {
 #ifdef HAVE_CAPSICUM
@@ -2219,9 +2187,6 @@ static void
 dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
 {
        struct dump_info *dump_info;
-#ifdef HAVE_CAPSICUM
-       cap_rights_t rights;
-#endif
 
        ++packets_captured;
 
@@ -2332,7 +2297,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                        if (dump_info->p == NULL)
                                error("%s", pcap_geterr(pd));
 #ifdef HAVE_CAPSICUM
-                       set_dump_fd_capsicum_rights(pcap_dump_file(dump_info->p)));
+                       set_dumper_capsicum_rights(dump_info->p);
 #endif
                }
        }
@@ -2403,7 +2368,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                        if (dump_info->p == NULL)
                                error("%s", pcap_geterr(pd));
 #ifdef HAVE_CAPSICUM
-                       set_dump_fd_capsicum_rights(fileno(pcap_dump_file(dump_info->p)));
+                       set_dumper_capsicum_rights(dump_info->p);
 #endif
                }
        }
@@ -2464,11 +2429,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
         */
        ndo->ndo_snapend = sp + h->caplen;
 
-        if(print_info->ndo_type) {
-                hdrlen = (*print_info->p.ndo_printer)(print_info->ndo, h, sp);
-        } else {
-                hdrlen = (*print_info->p.printer)(h, sp);
-        }
+        hdrlen = (*print_info->printer)(print_info->ndo, h, sp);
 
        /*
         * Restore the original snapend, as a printer might have