]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ether.c
Make "-x" and "-X" work with PPPoE interfaces; based on code from Darren
[tcpdump] / print-ether.c
index 0bcd82d5f8ae77a1ddf154de3c7337c43bd137dc..e715049f412d0338e3ba54a9dfd44da2026a8211 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.66 2001-11-25 02:01:47 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.68 2002-05-29 10:06:26 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -49,7 +49,7 @@ const u_char *packetp;
 const u_char *snapend;
 
 static inline void
-ether_print(register const u_char *bp, u_int length)
+ether_hdr_print(register const u_char *bp, u_int length)
 {
        register const struct ether_header *ep;
 
@@ -67,31 +67,20 @@ ether_print(register const u_char *bp, u_int length)
                             length);
 }
 
-/*
- * This is the top level routine of the printer.  'p' is the points
- * to the ether header of the packet, 'h->tv' is the timestamp,
- * 'h->length' is the length of the packet off the wire, and 'h->caplen'
- * is the number of bytes actually captured.
- */
 void
-ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
+ether_print(const u_char *p, u_int length, u_int caplen)
 {
-       u_int caplen = h->caplen;
-       u_int length = h->len;
        struct ether_header *ep;
        u_short ether_type;
        u_short extracted_ethertype;
 
-       ++infodelay;
-       ts_print(&h->ts);
-
        if (caplen < ETHER_HDRLEN) {
                printf("[|ether]");
-               goto out;
+               return;
        }
 
        if (eflag)
-               ether_print(p, length);
+               ether_hdr_print(p, length);
 
        /*
         * Some printers want to get back at the ethernet addresses,
@@ -118,7 +107,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
                    &extracted_ethertype) == 0) {
                        /* ether_type not known, print raw packet */
                        if (!eflag)
-                               ether_print((u_char *)ep, length + ETHER_HDRLEN);
+                               ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN);
                        if (extracted_ethertype) {
                                printf("(LLC %s) ",
                               etherproto_string(htons(extracted_ethertype)));
@@ -130,14 +119,38 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
            &extracted_ethertype) == 0) {
                /* ether_type not known, print raw packet */
                if (!eflag)
-                       ether_print((u_char *)ep, length + ETHER_HDRLEN);
+                       ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN);
                if (!xflag && !qflag)
                        default_print(p, caplen);
        }
-       if (xflag)
-               default_print(p, caplen);
- out:
+}
+
+/*
+ * This is the top level routine of the printer.  'p' is the points
+ * to the ether header of the packet, 'h->tv' is the timestamp,
+ * 'h->length' is the length of the packet off the wire, and 'h->caplen'
+ * is the number of bytes actually captured.
+ */
+void
+ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
+{
+       u_int caplen = h->caplen;
+       u_int length = h->len;
+
+       ++infodelay;
+       ts_print(&h->ts);
+
+       ether_print(p, length, caplen);
+
+       /*
+        * If "-x" was specified, print stuff past the Ethernet header,
+        * if there's anything to print.
+        */
+       if (xflag && caplen > ETHER_HDRLEN)
+               default_print(p + ETHER_HDRLEN, caplen - ETHER_HDRLEN);
+
        putchar('\n');
+
        --infodelay;
        if (infoprint)
                info(0);
@@ -216,7 +229,7 @@ ether_encap_print(u_short ethertype, const u_char *p,
                    extracted_ethertype) == 0) {
                        /* ether_type not known, print raw packet */
                        if (!eflag)
-                               ether_print(p - 18, length + 4);
+                               ether_hdr_print(p - 18, length + 4);
                        if (*extracted_ethertype) {
                                printf("(LLC %s) ",
                               etherproto_string(htons(*extracted_ethertype)));