]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sll.c
CHANGES: Add/move change(s) backported to 4.99
[tcpdump] / print-sll.c
index fe529efa1ed7503a35ea389fe5d6bd7273cd2a6a..de767781e016c4a87bb94ac80853e66341524371 100644 (file)
 
 /* \summary: Linux cooked sockets capture printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #ifdef HAVE_NET_IF_H
+/*
+ * Include diag-control.h before <net/if.h>, which too defines a macro
+ * named ND_UNREACHABLE.
+ */
+#include "diag-control.h"
 #include <net/if.h>
 #endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "ethertype.h"
@@ -162,7 +166,7 @@ sll_print(netdissect_options *ndo, const struct sll_header *sllp, u_int length)
         * For now, we just assume 6 means Ethernet.
         * XXX - print others as strings of hex?
         */
-       if (GET_BE_U_2(sllp->sll_halen) == 6)
+       if (GET_BE_U_2(sllp->sll_halen) == MAC_ADDR_LEN)
                ND_PRINT("%s ", GET_ETHERADDR_STRING(sllp->sll_addr));
 
        if (!ndo->ndo_qflag) {
@@ -211,7 +215,7 @@ sll_print(netdissect_options *ndo, const struct sll_header *sllp, u_int length)
  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  * is the number of bytes actually captured.
  */
-u_int
+void
 sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int caplen = h->caplen;
@@ -222,16 +226,8 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        int llc_hdrlen;
        u_int hdrlen;
 
-       ndo->ndo_protocol = "sll_if";
-       if (caplen < SLL_HDR_LEN) {
-               /*
-                * XXX - this "can't happen" because "pcap-linux.c" always
-                * adds this many bytes of header to every packet in a
-                * cooked socket capture.
-                */
-               nd_print_trunc(ndo);
-               return (caplen);
-       }
+       ndo->ndo_protocol = "sll";
+       ND_TCHECK_LEN(p, SLL_HDR_LEN);
 
        sllp = (const struct sll_header *)p;
 
@@ -254,7 +250,9 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
                 * This is an packet with a radiotap header;
                 * just dissect the payload as such.
                 */
-               return (SLL_HDR_LEN + ieee802_11_radio_print(ndo, p, length, caplen));
+               ndo->ndo_ll_hdr_len += SLL_HDR_LEN;
+               ndo->ndo_ll_hdr_len += ieee802_11_radio_print(ndo, p, length, caplen);
+               return;
        }
        ether_type = GET_BE_U_2(sllp->sll_protocol);
 
@@ -304,7 +302,8 @@ recurse:
                if (caplen < 4) {
                        ndo->ndo_protocol = "vlan";
                        nd_print_trunc(ndo);
-                       return (hdrlen + caplen);
+                       ndo->ndo_ll_hdr_len += hdrlen + caplen;
+                       return;
                }
                if (ndo->ndo_eflag) {
                        uint16_t tag = GET_BE_U_2(p);
@@ -334,7 +333,7 @@ recurse:
                }
        }
 
-       return (hdrlen);
+       ndo->ndo_ll_hdr_len += hdrlen;
 }
 
 static void
@@ -350,7 +349,7 @@ sll2_print(netdissect_options *ndo, const struct sll2_header *sllp, u_int length
         * For now, we just assume 6 means Ethernet.
         * XXX - print others as strings of hex?
         */
-       if (GET_U_1(sllp->sll2_halen) == 6)
+       if (GET_U_1(sllp->sll2_halen) == MAC_ADDR_LEN)
                ND_PRINT("%s ", GET_ETHERADDR_STRING(sllp->sll2_addr));
 
        if (!ndo->ndo_qflag) {
@@ -399,7 +398,7 @@ sll2_print(netdissect_options *ndo, const struct sll2_header *sllp, u_int length
  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  * is the number of bytes actually captured.
  */
-u_int
+void
 sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int caplen = h->caplen;
@@ -414,16 +413,8 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        char ifname[IF_NAMESIZE];
 #endif
 
-       ndo->ndo_protocol = "sll2_if";
-       if (caplen < SLL2_HDR_LEN) {
-               /*
-                * XXX - this "can't happen" because "pcap-linux.c" always
-                * adds this many bytes of header to every packet in a
-                * cooked socket capture.
-                */
-               nd_print_trunc(ndo);
-               return (caplen);
-       }
+       ndo->ndo_protocol = "sll2";
+       ND_TCHECK_LEN(p, SLL2_HDR_LEN);
 
        sllp = (const struct sll2_header *)p;
 #ifdef HAVE_NET_IF_H
@@ -455,7 +446,9 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
                 * This is an packet with a radiotap header;
                 * just dissect the payload as such.
                 */
-               return (SLL_HDR_LEN + ieee802_11_radio_print(ndo, p, length, caplen));
+               ndo->ndo_ll_hdr_len += SLL2_HDR_LEN;
+               ndo->ndo_ll_hdr_len += ieee802_11_radio_print(ndo, p, length, caplen);
+               return;
        }
        ether_type = GET_BE_U_2(sllp->sll2_protocol);
 
@@ -505,7 +498,8 @@ recurse:
                if (caplen < 4) {
                        ndo->ndo_protocol = "vlan";
                        nd_print_trunc(ndo);
-                       return (hdrlen + caplen);
+                       ndo->ndo_ll_hdr_len += hdrlen + caplen;
+                       return;
                }
                if (ndo->ndo_eflag) {
                        uint16_t tag = GET_BE_U_2(p);
@@ -529,11 +523,11 @@ recurse:
                if (ethertype_print(ndo, ether_type, p, length, caplen, NULL, NULL) == 0) {
                        /* ether_type not known, print raw packet */
                        if (!ndo->ndo_eflag)
-                               sll2_print(ndo, sllp, length + SLL_HDR_LEN);
+                               sll2_print(ndo, sllp, length + SLL2_HDR_LEN);
                        if (!ndo->ndo_suppress_default_print)
                                ND_DEFAULTPRINT(p, caplen);
                }
        }
 
-       return (hdrlen);
+       ndo->ndo_ll_hdr_len += hdrlen;
 }