X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/59864b113d8f2310a38d916e11a27c6f7e979ad9..1a04b92e365f5ed01ca38619b41bcc4fc9cbd63c:/print-fddi.c?ds=sidebyside diff --git a/print-fddi.c b/print-fddi.c index 9e6ec0b1..0b85034a 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -19,26 +19,28 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +/* \summary: Fiber Distributed Data Interface (FDDI) printer */ + #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" /* * Based on Ultrix if_fddi.h */ struct fddi_header { - u_char fddi_fc; /* frame control */ - u_char fddi_dhost[6]; - u_char fddi_shost[6]; + nd_uint8_t fddi_fc; /* frame control */ + nd_mac_addr fddi_dhost; + nd_mac_addr fddi_shost; }; /* @@ -83,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 /* @@ -227,7 +229,7 @@ print_fddi_fc(netdissect_options *ndo, u_char fc) static inline void extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) { - register int i; + int i; if (fddi_bitswap) { /* @@ -250,25 +252,19 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) */ static inline void 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 struct fddi_header *fddip, u_int length, + const u_char *fsrc, const u_char *fdst) { const char *srcname, *dstname; srcname = etheraddr_string(ndo, fsrc); dstname = etheraddr_string(ndo, fdst); - if (ndo->ndo_vflag) - ND_PRINT((ndo, "%02x %s %s %d: ", - fddip->fddi_fc, - srcname, dstname, - length)); - else if (ndo->ndo_qflag) - ND_PRINT((ndo, "%s %s %d: ", srcname, dstname, length)); - else { - print_fddi_fc(ndo, fddip->fddi_fc); - ND_PRINT((ndo, "%s %s %d: ", srcname, dstname, length)); - } + if (!ndo->ndo_qflag) + print_fddi_fc(ndo, EXTRACT_U_1(fddip->fddi_fc)); + ND_PRINT((ndo, "%s > %s, length %u: ", + srcname, dstname, + length)); } static inline void @@ -277,24 +273,34 @@ fddi_smt_print(netdissect_options *ndo, const u_char *p _U_, u_int length _U_) ND_PRINT((ndo, "")); } -void +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; + uint8_t fc; + nd_mac_addr srcmac, dstmac; + struct lladdr_info src, dst; + int llc_hdrlen; if (caplen < FDDI_HDRLEN) { ND_PRINT((ndo, "[|fddi]")); - return; + return (caplen); } + fc = EXTRACT_U_1(fddip->fddi_fc); + /* * Get the FDDI addresses into a canonical form */ - extract_fddi_addrs(fddip, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); + extract_fddi_addrs(fddip, (char *)srcmac, (char *)dstmac); if (ndo->ndo_eflag) - fddi_hdr_print(ndo, fddip, length, ESRC(&ehdr), EDST(&ehdr)); + fddi_hdr_print(ndo, fddip, length, srcmac, dstmac); + + src.addr = srcmac; + src.addr_string = etheraddr_string; + dst.addr = dstmac; + dst.addr_string = etheraddr_string; /* Skip over FDDI MAC header */ length -= FDDI_HDRLEN; @@ -302,26 +308,31 @@ fddi_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) caplen -= FDDI_HDRLEN; /* Frame Control field determines interpretation of packet */ - if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { + if ((fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(ndo, p, length, caplen, ESRC(&ehdr), EDST(&ehdr)) == 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 (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = -llc_hdrlen; } - } else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT) + } else if ((fc & FDDIFC_CLFF) == FDDIFC_SMT) { fddi_smt_print(ndo, p, caplen); - else { + llc_hdrlen = 0; + } else { /* Some kinds of FDDI packet we cannot handle intelligently */ if (!ndo->ndo_eflag) - fddi_hdr_print(ndo, fddip, length + FDDI_HDRLEN, ESRC(&ehdr), - EDST(&ehdr)); + fddi_hdr_print(ndo, fddip, length + FDDI_HDRLEN, srcmac, + dstmac); if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = 0; } + return (FDDI_HDRLEN + llc_hdrlen); } /* @@ -331,9 +342,7 @@ fddi_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) * is the number of bytes actually captured. */ u_int -fddi_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) +fddi_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { - fddi_print(ndo, p, h->len, h->caplen); - - return (FDDI_HDRLEN); + return (fddi_print(ndo, p, h->len, h->caplen)); }