X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ad7a38341c19e71e3595c17368ac18f08b71482d..d7b497cac78b6e22a66a6bae9bdec60a8044f67a:/print-fddi.c diff --git a/print-fddi.c b/print-fddi.c index 490b10aa..27803783 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -19,25 +19,18 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.66 2005-11-13 12:12:41 guy Exp $ (LBL)"; -#endif +/* \summary: Fiber Distributed Data Interface (FDDI) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include -#include -#include #include -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" -#include "ethertype.h" - #include "ether.h" /* @@ -92,9 +85,9 @@ struct fddi_header { * Some FDDI interfaces use bit-swapped addresses. */ #if defined(ultrix) || defined(__alpha) || defined(__bsdi) || defined(__NetBSD__) || defined(__linux__) -int fddi_bitswap = 0; +static int fddi_bitswap = 0; #else -int fddi_bitswap = 1; +static int fddi_bitswap = 1; #endif /* @@ -166,67 +159,67 @@ static const u_char fddi_bit_swap[] = { * Print FDDI frame-control bits */ static inline void -print_fddi_fc(u_char fc) +print_fddi_fc(netdissect_options *ndo, u_char fc) { switch (fc) { case FDDIFC_VOID: /* Void frame */ - printf("void "); + ND_PRINT((ndo, "void ")); break; case FDDIFC_NRT: /* Nonrestricted token */ - printf("nrt "); + ND_PRINT((ndo, "nrt ")); break; case FDDIFC_RT: /* Restricted token */ - printf("rt "); + ND_PRINT((ndo, "rt ")); break; case FDDIFC_SMT_INFO: /* SMT Info */ - printf("info "); + ND_PRINT((ndo, "info ")); break; case FDDIFC_SMT_NSA: /* SMT Next station adrs */ - printf("nsa "); + ND_PRINT((ndo, "nsa ")); break; case FDDIFC_MAC_BEACON: /* MAC Beacon frame */ - printf("beacon "); + ND_PRINT((ndo, "beacon ")); break; case FDDIFC_MAC_CLAIM: /* MAC Claim frame */ - printf("claim "); + ND_PRINT((ndo, "claim ")); break; default: switch (fc & FDDIFC_CLFF) { case FDDIFC_MAC: - printf("mac%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "mac%1x ", fc & FDDIFC_ZZZZ)); break; case FDDIFC_SMT: - printf("smt%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "smt%1x ", fc & FDDIFC_ZZZZ)); break; case FDDIFC_LLC_ASYNC: - printf("async%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "async%1x ", fc & FDDIFC_ZZZZ)); break; case FDDIFC_LLC_SYNC: - printf("sync%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "sync%1x ", fc & FDDIFC_ZZZZ)); break; case FDDIFC_IMP_ASYNC: - printf("imp_async%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "imp_async%1x ", fc & FDDIFC_ZZZZ)); break; case FDDIFC_IMP_SYNC: - printf("imp_sync%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT((ndo, "imp_sync%1x ", fc & FDDIFC_ZZZZ)); break; default: - printf("%02x ", fc); + ND_PRINT((ndo, "%02x ", fc)); break; } } @@ -258,43 +251,39 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) * Print the FDDI MAC header */ static inline void -fddi_hdr_print(register const struct fddi_header *fddip, register u_int length, - register const u_char *fsrc, register const u_char *fdst) +fddi_hdr_print(netdissect_options *ndo, + register const struct fddi_header *fddip, register u_int length, + register const u_char *fsrc, register const u_char *fdst) { const char *srcname, *dstname; - srcname = etheraddr_string(fsrc); - dstname = etheraddr_string(fdst); + srcname = etheraddr_string(ndo, fsrc); + dstname = etheraddr_string(ndo, fdst); - if (vflag) - (void) printf("%02x %s %s %d: ", - fddip->fddi_fc, - srcname, dstname, - length); - else if (qflag) - printf("%s %s %d: ", srcname, dstname, length); - else { - (void) print_fddi_fc(fddip->fddi_fc); - (void) printf("%s %s %d: ", srcname, dstname, length); - } + if (!ndo->ndo_qflag) + print_fddi_fc(ndo, fddip->fddi_fc); + ND_PRINT((ndo, "%s > %s, length %u: ", + srcname, dstname, + length)); } static inline void -fddi_smt_print(const u_char *p _U_, u_int length _U_) +fddi_smt_print(netdissect_options *ndo, const u_char *p _U_, u_int length _U_) { - printf(""); + ND_PRINT((ndo, "")); } -void -fddi_print(const u_char *p, u_int length, u_int caplen) +u_int +fddi_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { const struct fddi_header *fddip = (const struct fddi_header *)p; struct ether_header ehdr; - u_short extracted_ethertype; + struct lladdr_info src, dst; + int llc_hdrlen; if (caplen < FDDI_HDRLEN) { - printf("[|fddi]"); - return; + ND_PRINT((ndo, "[|fddi]")); + return (caplen); } /* @@ -302,8 +291,13 @@ fddi_print(const u_char *p, u_int length, u_int caplen) */ extract_fddi_addrs(fddip, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); - if (eflag) - fddi_hdr_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); + if (ndo->ndo_eflag) + fddi_hdr_print(ndo, fddip, length, ESRC(&ehdr), EDST(&ehdr)); + + src.addr = ESRC(&ehdr); + src.addr_string = etheraddr_string; + dst.addr = EDST(&ehdr); + dst.addr_string = etheraddr_string; /* Skip over FDDI MAC header */ length -= FDDI_HDRLEN; @@ -313,32 +307,29 @@ fddi_print(const u_char *p, u_int length, u_int caplen) /* Frame Control field determines interpretation of packet */ if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), - &extracted_ethertype) == 0) { + llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); + if (llc_hdrlen < 0) { /* * Some kinds of LLC packet we cannot * handle intelligently */ - if (!eflag) - fddi_hdr_print(fddip, length + FDDI_HDRLEN, - ESRC(&ehdr), EDST(&ehdr)); - if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); - } - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = -llc_hdrlen; } - } else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT) - fddi_smt_print(p, caplen); - else { + } else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT) { + fddi_smt_print(ndo, p, caplen); + llc_hdrlen = 0; + } else { /* Some kinds of FDDI packet we cannot handle intelligently */ - if (!eflag) - fddi_hdr_print(fddip, length + FDDI_HDRLEN, ESRC(&ehdr), + if (!ndo->ndo_eflag) + fddi_hdr_print(ndo, fddip, length + FDDI_HDRLEN, ESRC(&ehdr), EDST(&ehdr)); - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = 0; } + return (FDDI_HDRLEN + llc_hdrlen); } /* @@ -348,9 +339,7 @@ fddi_print(const u_char *p, u_int length, u_int caplen) * is the number of bytes actually captured. */ u_int -fddi_if_print(const struct pcap_pkthdr *h, register const u_char *p) +fddi_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { - fddi_print(p, h->len, h->caplen); - - return (FDDI_HDRLEN); + return (fddi_print(ndo, p, h->len, h->caplen)); }