X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/1fe6e66ecec3fb7a7cc729038012cbb264542331..refs/pull/494/head:/print-token.c diff --git a/print-token.c b/print-token.c index 8dd23b33..6f9950db 100644 --- a/print-token.c +++ b/print-token.c @@ -24,16 +24,15 @@ * Guy Harris */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "ether.h" @@ -82,12 +81,12 @@ #define SEGMENT_COUNT(trp) ((int)((RIF_LENGTH(trp) - 2) / 2)) struct token_header { - u_int8_t token_ac; - u_int8_t token_fc; - u_int8_t token_dhost[TOKEN_RING_MAC_LEN]; - u_int8_t token_shost[TOKEN_RING_MAC_LEN]; - u_int16_t token_rcf; - u_int16_t token_rseg[ROUTING_SEGMENT_MAX]; + uint8_t token_ac; + uint8_t token_fc; + uint8_t token_dhost[TOKEN_RING_MAC_LEN]; + uint8_t token_shost[TOKEN_RING_MAC_LEN]; + uint16_t token_rcf; + uint16_t token_rseg[ROUTING_SEGMENT_MAX]; }; static const char tstr[] = "[|token-ring]"; @@ -110,17 +109,16 @@ token_hdr_print(netdissect_options *ndo, { const char *srcname, *dstname; - srcname = etheraddr_string(fsrc); - dstname = etheraddr_string(fdst); + srcname = etheraddr_string(ndo, fsrc); + dstname = etheraddr_string(ndo, fdst); - if (ndo->ndo_vflag) - ND_PRINT((ndo, "%02x %02x %s %s %d: ", + if (!ndo->ndo_qflag) + ND_PRINT((ndo, "%02x %02x ", trp->token_ac, - trp->token_fc, - srcname, dstname, - length)); - else - ND_PRINT((ndo, "%s %s %d: ", srcname, dstname, length)); + trp->token_fc)); + ND_PRINT((ndo, "%s > %s, length %u: ", + srcname, dstname, + length)); } static const char *broadcast_indicator[] = { @@ -149,7 +147,7 @@ u_int token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { const struct token_header *trp; - u_short extracted_ethertype; + int llc_hdrlen; struct ether_header ehdr; u_int route_len = 0, hdr_len = TOKEN_HDRLEN; int seg; @@ -211,20 +209,15 @@ token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen /* Frame Control field determines interpretation of packet */ if (FRAME_TYPE(trp) == TOKEN_FC_LLC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), - &extracted_ethertype) == 0) { - /* ether_type not known, print raw packet */ - if (!ndo->ndo_eflag) - token_hdr_print(ndo, trp, - length + TOKEN_HDRLEN + route_len, - ESRC(&ehdr), EDST(&ehdr)); - if (extracted_ethertype) { - ND_PRINT((ndo, "(LLC %s) ", - etherproto_string(htons(extracted_ethertype)))); - } + llc_hdrlen = llc_print(ndo, p, length, caplen, ESRC(&ehdr), + EDST(&ehdr)); + if (llc_hdrlen < 0) { + /* packet type not known, print raw packet */ if (!ndo->ndo_suppress_default_print) - ndo->ndo_default_print(ndo, p, caplen); + ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = -llc_hdrlen; } + hdr_len += llc_hdrlen; } else { /* Some kinds of TR packet we cannot handle intelligently */ /* XXX - dissect MAC packets if frame type is 0 */ @@ -232,7 +225,7 @@ token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen token_hdr_print(ndo, trp, length + TOKEN_HDRLEN + route_len, ESRC(&ehdr), EDST(&ehdr)); if (!ndo->ndo_suppress_default_print) - ndo->ndo_default_print(ndo, p, caplen); + ND_DEFAULTPRINT(p, caplen); } return (hdr_len); }