X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a04d5026297a95147d927883aa407cd78e5f95a9..e7cfa5e63a27e6fbb75e0bbd151af2c7d0d222e9:/print-sll.c diff --git a/print-sll.c b/print-sll.c index 96031442..d165da22 100644 --- a/print-sll.c +++ b/print-sll.c @@ -25,6 +25,10 @@ #include #endif +#ifdef HAVE_NET_IF_H +#include +#endif + #include "netdissect-stdinc.h" #include "netdissect.h" @@ -150,18 +154,19 @@ sll_print(netdissect_options *ndo, const struct sll_header *sllp, u_int length) u_short ether_type; ndo->ndo_protocol = "sll"; - ND_PRINT("%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_BE_U_2(sllp->sll_pkttype))); + ND_PRINT("%3s ", + tok2str(sll_pkttype_values,"?",GET_BE_U_2(sllp->sll_pkttype))); /* * XXX - check the link-layer address type value? * For now, we just assume 6 means Ethernet. * XXX - print others as strings of hex? */ - if (EXTRACT_BE_U_2(sllp->sll_halen) == 6) + if (GET_BE_U_2(sllp->sll_halen) == 6) ND_PRINT("%s ", etheraddr_string(ndo, sllp->sll_addr)); if (!ndo->ndo_qflag) { - ether_type = EXTRACT_BE_U_2(sllp->sll_protocol); + ether_type = GET_BE_U_2(sllp->sll_protocol); if (ether_type <= MAX_ETHERNET_LENGTH_VAL) { /* @@ -212,6 +217,7 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char u_int caplen = h->caplen; u_int length = h->len; const struct sll_header *sllp; + u_short hatype; u_short ether_type; int llc_hdrlen; u_int hdrlen; @@ -240,7 +246,17 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char p += SLL_HDR_LEN; hdrlen = SLL_HDR_LEN; - ether_type = EXTRACT_BE_U_2(sllp->sll_protocol); + hatype = GET_BE_U_2(sllp->sll_hatype); + switch (hatype) { + + case 803: + /* + * 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)); + } + ether_type = GET_BE_U_2(sllp->sll_protocol); recurse: /* @@ -286,20 +302,17 @@ recurse: * the enclosed type field. */ if (caplen < 4) { - ND_PRINT("[|vlan]"); + ndo->ndo_protocol = "vlan"; + nd_print_trunc(ndo); return (hdrlen + caplen); } - if (length < 4) { - ND_PRINT("[|vlan]"); - return (hdrlen + length); - } if (ndo->ndo_eflag) { - uint16_t tag = EXTRACT_BE_U_2(p); + uint16_t tag = GET_BE_U_2(p); ND_PRINT("%s, ", ieee8021q_tci_string(tag)); } - ether_type = EXTRACT_BE_U_2(p + 2); + ether_type = GET_BE_U_2(p + 2); if (ether_type <= MAX_ETHERNET_LENGTH_VAL) ether_type = LINUX_SLL_P_802_2; if (!ndo->ndo_qflag) { @@ -330,18 +343,19 @@ sll2_print(netdissect_options *ndo, const struct sll2_header *sllp, u_int length u_short ether_type; ndo->ndo_protocol = "sll2"; - ND_PRINT("%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_U_1(sllp->sll2_pkttype))); + ND_PRINT("%3s ", + tok2str(sll_pkttype_values,"?",GET_U_1(sllp->sll2_pkttype))); /* * XXX - check the link-layer address type value? * For now, we just assume 6 means Ethernet. * XXX - print others as strings of hex? */ - if (EXTRACT_U_1(sllp->sll2_halen) == 6) + if (GET_U_1(sllp->sll2_halen) == 6) ND_PRINT("%s ", etheraddr_string(ndo, sllp->sll2_addr)); if (!ndo->ndo_qflag) { - ether_type = EXTRACT_BE_U_2(sllp->sll2_protocol); + ether_type = GET_BE_U_2(sllp->sll2_protocol); if (ether_type <= MAX_ETHERNET_LENGTH_VAL) { /* @@ -392,9 +406,14 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char u_int caplen = h->caplen; u_int length = h->len; const struct sll2_header *sllp; + u_short hatype; u_short ether_type; int llc_hdrlen; u_int hdrlen; +#ifdef HAVE_NET_IF_H + uint32_t if_index; + char ifname[IF_NAMESIZE]; +#endif ndo->ndo_protocol = "sll2_if"; if (caplen < SLL2_HDR_LEN) { @@ -408,6 +427,13 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char } sllp = (const struct sll2_header *)p; +#ifdef HAVE_NET_IF_H + if_index = GET_BE_U_4(sllp->sll2_if_index); + if (if_indextoname(if_index, ifname)) + ND_PRINT("ifindex %u (%s) ", if_index, ifname); + else + ND_PRINT("ifindex %u ", if_index); +#endif if (ndo->ndo_eflag) sll2_print(ndo, sllp, length); @@ -420,7 +446,17 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char p += SLL2_HDR_LEN; hdrlen = SLL2_HDR_LEN; - ether_type = EXTRACT_BE_U_2(sllp->sll2_protocol); + hatype = GET_BE_U_2(sllp->sll2_hatype); + switch (hatype) { + + case 803: + /* + * 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)); + } + ether_type = GET_BE_U_2(sllp->sll2_protocol); recurse: /* @@ -466,20 +502,17 @@ recurse: * the enclosed type field. */ if (caplen < 4) { - ND_PRINT("[|vlan]"); + ndo->ndo_protocol = "vlan"; + nd_print_trunc(ndo); return (hdrlen + caplen); } - if (length < 4) { - ND_PRINT("[|vlan]"); - return (hdrlen + length); - } if (ndo->ndo_eflag) { - uint16_t tag = EXTRACT_BE_U_2(p); + uint16_t tag = GET_BE_U_2(p); ND_PRINT("%s, ", ieee8021q_tci_string(tag)); } - ether_type = EXTRACT_BE_U_2(p + 2); + ether_type = GET_BE_U_2(p + 2); if (ether_type <= MAX_ETHERNET_LENGTH_VAL) ether_type = LINUX_SLL_P_802_2; if (!ndo->ndo_qflag) {