]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sll.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-sll.c
index ad0ae7f1e6bf52332e1ca09b2cde3156f32512b8..87d824466508326df2d8cf9689aeb3a67632acce 100644 (file)
 
 /* \summary: Linux cooked sockets capture printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
 #include <net/if.h>
 #endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "ethertype.h"
@@ -162,8 +161,8 @@ 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) == MAC_ADDR_LEN)
-               ND_PRINT("%s ", GET_ETHERADDR_STRING(sllp->sll_addr));
+       if (GET_BE_U_2(sllp->sll_halen) == MAC48_LEN)
+               ND_PRINT("%s ", GET_MAC48_STRING(sllp->sll_addr));
 
        if (!ndo->ndo_qflag) {
                ether_type = GET_BE_U_2(sllp->sll_protocol);
@@ -223,16 +222,7 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        u_int hdrlen;
 
        ndo->ndo_protocol = "sll";
-       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);
-               ndo->ndo_ll_hdr_len += caplen;
-               return;
-       }
+       ND_TCHECK_LEN(p, SLL_HDR_LEN);
 
        sllp = (const struct sll_header *)p;
 
@@ -354,8 +344,8 @@ 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) == MAC_ADDR_LEN)
-               ND_PRINT("%s ", GET_ETHERADDR_STRING(sllp->sll2_addr));
+       if (GET_U_1(sllp->sll2_halen) == MAC48_LEN)
+               ND_PRINT("%s ", GET_MAC48_STRING(sllp->sll2_addr));
 
        if (!ndo->ndo_qflag) {
                ether_type = GET_BE_U_2(sllp->sll2_protocol);
@@ -402,6 +392,19 @@ sll2_print(netdissect_options *ndo, const struct sll2_header *sllp, u_int length
  * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp,
  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  * is the number of bytes actually captured.
+ *
+ * On Linux, we attempt to look up the interface index and print the
+ * name of the interface on which the packet arrived or was sent.
+ *
+ * This look up is only likely to work well if done on the same machine
+ * as the one on which the capture was done, as the interface with a
+ * given index on the latter machine is unlikely to have the same
+ * name as the interface with that index on the former machine.
+ *
+ * As DLT_LINUX_SLL2 live captures are supported only on Linux, this
+ * means that if the machine on which we're reading the file isn't
+ * running Linux, it's probably not the machine that captured the file,
+ * so we don't bother trying to do the lookup on non-Linux machines.
  */
 void
 sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
@@ -413,25 +416,16 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        u_short ether_type;
        int llc_hdrlen;
        u_int hdrlen;
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
        uint32_t if_index;
        char ifname[IF_NAMESIZE];
 #endif
 
        ndo->ndo_protocol = "sll2";
-       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);
-               ndo->ndo_ll_hdr_len += caplen;
-               return;
-       }
+       ND_TCHECK_LEN(p, SLL2_HDR_LEN);
 
        sllp = (const struct sll2_header *)p;
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
        if_index = GET_BE_U_4(sllp->sll2_if_index);
        if (!if_indextoname(if_index, ifname))
                strncpy(ifname, "?", 2);