]> The Tcpdump Group git mirrors - tcpdump/commitdiff
This commit makes ipnet_if_print the first NDO aware top-level
authorMichael Richardson <[email protected]>
Sun, 10 Jan 2010 19:36:07 +0000 (14:36 -0500)
committerMichael Richardson <[email protected]>
Sun, 10 Jan 2010 19:36:07 +0000 (14:36 -0500)
printer.
Merge commit 'origin/master'

Conflicts:
netdissect.h

netdissect.h
print-ipnet.c
tcpdump.c
tests/TESTLIST
tests/TESTonce
tests/e1000g.out [new file with mode: 0644]
tests/e1000g.pcap [new file with mode: 0644]

index dd9f4b966bfd87ff12cd80558f1dabafa6e41308..7e87555cb3aee796f3977b8bde97b0f0f353734a 100644 (file)
@@ -437,6 +437,8 @@ extern void lwres_print(netdissect_options *,const u_char *, u_int);
 extern void pptp_print(netdissect_options *,const u_char *, u_int);
 #endif
 
+extern u_int ipnet_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *);
+
 #if 0
 #ifdef INET6
 extern void ip6_print(netdissect_options *,const u_char *, u_int);
index 3a5b5a1aa18390d89b9045d12336a0840014d3e1..957bd4f52341ea74f0a6d4f0cde3d5d63fcd9b31 100644 (file)
@@ -91,9 +91,10 @@ ipnet_print(struct netdissect_options *ndo, const u_char *p, u_int length, u_int
  * is the number of bytes actually captured.
  */
 u_int
-ipnet_if_print(const struct pcap_pkthdr *h, const u_char *p)
+ipnet_if_print(struct netdissect_options *ndo,
+               const struct pcap_pkthdr *h, const u_char *p)
 {
-       ipnet_print(gndo, p, h->len, h->caplen);
+       ipnet_print(ndo, p, h->len, h->caplen);
 
        return (sizeof(ipnet_hdr_t));
 }
index d50feb0896940ca2f040909d8ab506708d01fe1b..c60cb6b4f5990b302c1c983def59445faa6fc218 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -131,12 +131,21 @@ static void info(int);
 static u_int packets_captured;
 
 typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *);
+typedef u_int (*if_ndo_printer)(struct netdissect_options *ndo,
+                                const struct pcap_pkthdr *, const u_char *);
 
 struct printer {
-       if_printer f;
+        if_printer f;
        int type;
 };
 
+
+struct ndo_printer {
+        if_ndo_printer f;
+       int type;
+};
+
+
 static struct printer printers[] = {
        { arcnet_if_print,      DLT_ARCNET },
 #ifdef DLT_ARCNET_LINUX
@@ -282,6 +291,10 @@ static struct printer printers[] = {
 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX_MMAPPED)
        { usb_linux_print,      DLT_USB_LINUX_MMAPPED},
 #endif
+       { NULL,                 0 },
+};
+
+static struct ndo_printer ndo_printers[] = {
 #ifdef DLT_IPNET
        { ipnet_if_print,       DLT_IPNET },
 #endif
@@ -307,6 +320,19 @@ lookup_printer(int type)
        /* NOTREACHED */
 }
 
+static if_ndo_printer
+lookup_ndo_printer(int type)
+{
+       struct ndo_printer *p;
+
+       for (p = ndo_printers; p->f; ++p)
+               if (type == p->type)
+                       return p->f;
+
+       return NULL;
+       /* NOTREACHED */
+}
+
 static pcap_t *pd;
 
 static int supports_monitor_mode;
@@ -316,7 +342,12 @@ extern int opterr;
 extern char *optarg;
 
 struct print_info {
-       if_printer printer;
+        netdissect_options *ndo;
+        union {
+                if_printer     printer;
+                if_ndo_printer ndo_printer;
+        } p;
+        int ndo_type;
 };
 
 struct dump_info {
@@ -364,7 +395,8 @@ show_dlts_and_exit(const char *device, pcap_t *pd)
                        /*
                         * OK, does tcpdump handle that type?
                         */
-                       if (lookup_printer(dlts[n_dlts]) == NULL)
+                       if (lookup_printer(dlts[n_dlts]) == NULL
+                            && lookup_ndo_printer(dlts[n_dlts]) == NULL)
                                (void) fprintf(stderr, " (printing not supported)");
                        putchar('\n');
                } else {
@@ -1172,15 +1204,21 @@ main(int argc, char **argv)
                }
        } else {
                type = pcap_datalink(pd);
-               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);
-               }
+                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);
+                        }
+                }
                callback = print_packet;
                pcap_userdata = (u_char *)&printinfo;
        }
@@ -1564,7 +1602,12 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
         */
        snapend = sp + h->caplen;
 
-       hdrlen = (*print_info->printer)(h, sp);
+        if(print_info->ndo_type) {
+                hdrlen = (*print_info->p.ndo_printer)(print_info->ndo, h, sp);
+        } else {
+                hdrlen = (*print_info->p.printer)(h, sp);
+        }
+                
        if (Xflag) {
                /*
                 * Print the raw packet data in hex and ASCII.
index 68a018f166297f5eee7be9acee91ba8cfd083949..da54699cd1645fcd773dedb70be50569907f48af 100644 (file)
@@ -37,3 +37,7 @@ ikev2pI2      ikev2pI2.pcap           ikev2pI2.out    -t -E "file ikev2pI2-secrets.txt" -v -v -v
 
 # IETF ROLL RPL packets
 dio01           dio.pcap                dio.out         -t -v
+
+# IPNET encapsulated site
+e1000g         e1000g.pcap             e1000g.out      -t
+
index 987dacb92fa443547171a18c580cb23e379c4944..40d544b04f4408d162a9b83b21242befb40a87ca 100755 (executable)
@@ -41,3 +41,6 @@ if (! -f $input) {
 
 print "    ";
 exec("../tcpdump -n -r $input $options | tee NEW/$output | diff -w - $output >DIFF/$output.diff");
+@cores = glob("core*");
+exit 10 if (@cores > 0);
+exit 0;
diff --git a/tests/e1000g.out b/tests/e1000g.out
new file mode 100644 (file)
index 0000000..0cc3b9e
--- /dev/null
@@ -0,0 +1,20 @@
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 0, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 0, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 1, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 1, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 2, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 2, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 3, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 3, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 4, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 4, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 5, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 5, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 6, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 6, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 7, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 7, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 8, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 8, length 64
+IP 129.146.106.55 > 10.5.233.117: ICMP echo request, id 6901, seq 9, length 64
+IP 10.5.233.117 > 129.146.106.55: ICMP echo reply, id 6901, seq 9, length 64
diff --git a/tests/e1000g.pcap b/tests/e1000g.pcap
new file mode 100644 (file)
index 0000000..11b0174
Binary files /dev/null and b/tests/e1000g.pcap differ