123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <netdissect-stdinc.h>
- #include "netdissect.h"
- #include "addrtoname.h"
- #include "ethertype.h"
- #include "extract.h"
- #include "ether.h"
- #define SLL_HDR_LEN 16
- #define SLL_ADDRLEN 8
- struct sll_header {
- uint16_t sll_pkttype;
- uint16_t sll_hatype;
- uint16_t sll_halen;
- uint8_t sll_addr[SLL_ADDRLEN];
- uint16_t sll_protocol;
- };
- #define LINUX_SLL_HOST 0
- #define LINUX_SLL_BROADCAST 1
- #define LINUX_SLL_MULTICAST 2
- #define LINUX_SLL_OTHERHOST 3
- #define LINUX_SLL_OUTGOING 4
- #define LINUX_SLL_P_802_3 0x0001
- #define LINUX_SLL_P_802_2 0x0004
- static const struct tok sll_pkttype_values[] = {
- { LINUX_SLL_HOST, "In" },
- { LINUX_SLL_BROADCAST, "B" },
- { LINUX_SLL_MULTICAST, "M" },
- { LINUX_SLL_OTHERHOST, "P" },
- { LINUX_SLL_OUTGOING, "Out" },
- { 0, NULL}
- };
- static inline void
- sll_print(netdissect_options *ndo, register const struct sll_header *sllp, u_int length)
- {
- u_short ether_type;
- ND_PRINT((ndo, "%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_16BITS(&sllp->sll_pkttype))));
-
- if (EXTRACT_16BITS(&sllp->sll_halen) == 6)
- ND_PRINT((ndo, "%s ", etheraddr_string(ndo, sllp->sll_addr)));
- if (!ndo->ndo_qflag) {
- ether_type = EXTRACT_16BITS(&sllp->sll_protocol);
- if (ether_type <= ETHERMTU) {
-
- switch (ether_type) {
- case LINUX_SLL_P_802_3:
-
- ND_PRINT((ndo, "802.3"));
- break;
- case LINUX_SLL_P_802_2:
-
- ND_PRINT((ndo, "802.2"));
- break;
- default:
-
- ND_PRINT((ndo, "ethertype Unknown (0x%04x)",
- ether_type));
- break;
- }
- } else {
- ND_PRINT((ndo, "ethertype %s (0x%04x)",
- tok2str(ethertype_values, "Unknown", ether_type),
- ether_type));
- }
- ND_PRINT((ndo, ", length %u: ", length));
- }
- }
- u_int
- sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
- {
- u_int caplen = h->caplen;
- u_int length = h->len;
- register const struct sll_header *sllp;
- u_short ether_type;
- int llc_hdrlen;
- u_int hdrlen;
- if (caplen < SLL_HDR_LEN) {
-
- ND_PRINT((ndo, "[|sll]"));
- return (caplen);
- }
- sllp = (const struct sll_header *)p;
- if (ndo->ndo_eflag)
- sll_print(ndo, sllp, length);
-
- length -= SLL_HDR_LEN;
- caplen -= SLL_HDR_LEN;
- p += SLL_HDR_LEN;
- hdrlen = SLL_HDR_LEN;
- ether_type = EXTRACT_16BITS(&sllp->sll_protocol);
- recurse:
-
- if (ether_type <= ETHERMTU) {
-
- switch (ether_type) {
- case LINUX_SLL_P_802_3:
-
- ipx_print(ndo, p, length);
- break;
- case LINUX_SLL_P_802_2:
-
- llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
- if (llc_hdrlen < 0)
- goto unknown;
- hdrlen += llc_hdrlen;
- break;
- default:
-
- unknown:
-
- if (!ndo->ndo_suppress_default_print)
- ND_DEFAULTPRINT(p, caplen);
- break;
- }
- } else if (ether_type == ETHERTYPE_8021Q) {
-
- if (caplen < 4) {
- ND_PRINT((ndo, "[|vlan]"));
- return (hdrlen + caplen);
- }
- if (length < 4) {
- ND_PRINT((ndo, "[|vlan]"));
- return (hdrlen + length);
- }
- if (ndo->ndo_eflag) {
- uint16_t tag = EXTRACT_16BITS(p);
- ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag)));
- }
- ether_type = EXTRACT_16BITS(p + 2);
- if (ether_type <= ETHERMTU)
- ether_type = LINUX_SLL_P_802_2;
- if (!ndo->ndo_qflag) {
- ND_PRINT((ndo, "ethertype %s, ",
- tok2str(ethertype_values, "Unknown", ether_type)));
- }
- p += 4;
- length -= 4;
- caplen -= 4;
- hdrlen += 4;
- goto recurse;
- } else {
- if (ethertype_print(ndo, ether_type, p, length, caplen, NULL, NULL) == 0) {
-
- if (!ndo->ndo_eflag)
- sll_print(ndo, sllp, length + SLL_HDR_LEN);
- if (!ndo->ndo_suppress_default_print)
- ND_DEFAULTPRINT(p, caplen);
- }
- }
- return (hdrlen);
- }
|