X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/2cfe2bf4a5bdba199215e4c92129a36271b10a64..refs/heads/master:/print-fddi.c diff --git a/print-fddi.c b/print-fddi.c index caa1f11f..ccdf5889 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -19,43 +19,73 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.51 2001-07-04 22:03:14 fenner Exp $ (LBL)"; -#endif - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +/* \summary: Fiber Distributed Data Interface (FDDI) printer */ -#include -#include -#include -#include -#include +#include -#include +#include "netdissect-stdinc.h" -#include -#include -#include -#include #include -#include "interface.h" +#include "netdissect.h" +#include "extract.h" #include "addrtoname.h" -#include "ethertype.h" -#include "ether.h" -#include "fddi.h" +/* + * Based on Ultrix if_fddi.h + */ + +struct fddi_header { + nd_uint8_t fddi_fc; /* frame control */ + nd_mac48 fddi_dhost; + nd_mac48 fddi_shost; +}; + +/* + * Length of an FDDI header; note that some compilers may pad + * "struct fddi_header" to a multiple of 4 bytes, for example, so + * "sizeof (struct fddi_header)" may not give the right + * answer. + */ +#define FDDI_HDRLEN 13 + +/* Useful values for fddi_fc (frame control) field */ + +/* + * FDDI Frame Control bits + */ +#define FDDIFC_C 0x80 /* Class bit */ +#define FDDIFC_L 0x40 /* Address length bit */ +#define FDDIFC_F 0x30 /* Frame format bits */ +#define FDDIFC_Z 0x0f /* Control bits */ + +/* + * FDDI Frame Control values. (48-bit addressing only). + */ +#define FDDIFC_VOID 0x40 /* Void frame */ +#define FDDIFC_NRT 0x80 /* Nonrestricted token */ +#define FDDIFC_RT 0xc0 /* Restricted token */ +#define FDDIFC_SMT_INFO 0x41 /* SMT Info */ +#define FDDIFC_SMT_NSA 0x4F /* SMT Next station adrs */ +#define FDDIFC_MAC_BEACON 0xc2 /* MAC Beacon frame */ +#define FDDIFC_MAC_CLAIM 0xc3 /* MAC Claim frame */ +#define FDDIFC_LLC_ASYNC 0x50 /* Async. LLC frame */ +#define FDDIFC_LLC_SYNC 0xd0 /* Sync. LLC frame */ +#define FDDIFC_IMP_ASYNC 0x60 /* Implementor Async. */ +#define FDDIFC_IMP_SYNC 0xe0 /* Implementor Synch. */ +#define FDDIFC_SMT 0x40 /* SMT frame */ +#define FDDIFC_MAC 0xc0 /* MAC frame */ + +#define FDDIFC_CLFF 0xF0 /* Class/Length/Format bits */ +#define FDDIFC_ZZZZ 0x0F /* Control bits */ /* * Some FDDI interfaces use bit-swapped addresses. */ -#if defined(ultrix) || defined(__alpha) || defined(__bsdi) || defined(__NetBSD__) -int fddi_bitswap = 0; +#if defined(__alpha) || defined(__NetBSD__) || defined(__linux__) +static int fddi_bitswap = 0; #else -int fddi_bitswap = 1; +static int fddi_bitswap = 1; #endif /* @@ -88,7 +118,7 @@ int fddi_bitswap = 1; * - vj */ -static u_char fddi_bit_swap[] = { +static const u_char fddi_bit_swap[] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, @@ -126,78 +156,78 @@ static u_char fddi_bit_swap[] = { /* * Print FDDI frame-control bits */ -static inline void -print_fddi_fc(u_char fc) +static void +print_fddi_fc(netdissect_options *ndo, u_char fc) { switch (fc) { case FDDIFC_VOID: /* Void frame */ - printf("void "); + ND_PRINT("void "); break; case FDDIFC_NRT: /* Nonrestricted token */ - printf("nrt "); + ND_PRINT("nrt "); break; case FDDIFC_RT: /* Restricted token */ - printf("rt "); + ND_PRINT("rt "); break; case FDDIFC_SMT_INFO: /* SMT Info */ - printf("info "); + ND_PRINT("info "); break; case FDDIFC_SMT_NSA: /* SMT Next station adrs */ - printf("nsa "); + ND_PRINT("nsa "); break; case FDDIFC_MAC_BEACON: /* MAC Beacon frame */ - printf("beacon "); + ND_PRINT("beacon "); break; case FDDIFC_MAC_CLAIM: /* MAC Claim frame */ - printf("claim "); + ND_PRINT("claim "); break; default: switch (fc & FDDIFC_CLFF) { case FDDIFC_MAC: - printf("mac%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("mac%1x ", fc & FDDIFC_ZZZZ); break; case FDDIFC_SMT: - printf("smt%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("smt%1x ", fc & FDDIFC_ZZZZ); break; case FDDIFC_LLC_ASYNC: - printf("async%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("async%1x ", fc & FDDIFC_ZZZZ); break; case FDDIFC_LLC_SYNC: - printf("sync%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("sync%1x ", fc & FDDIFC_ZZZZ); break; case FDDIFC_IMP_ASYNC: - printf("imp_async%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("imp_async%1x ", fc & FDDIFC_ZZZZ); break; case FDDIFC_IMP_SYNC: - printf("imp_sync%1x ", fc & FDDIFC_ZZZZ); + ND_PRINT("imp_sync%1x ", fc & FDDIFC_ZZZZ); break; default: - printf("%02x ", fc); + ND_PRINT("%02x ", fc); break; } } } /* Extract src, dst addresses */ -static inline void +static void extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) { - register int i; + int i; if (fddi_bitswap) { /* @@ -208,87 +238,67 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) fdst[i] = fddi_bit_swap[fddip->fddi_dhost[i]]; for (i = 0; i < 6; ++i) fsrc[i] = fddi_bit_swap[fddip->fddi_shost[i]]; - } - else { - memcpy(fdst, (char *)fddip->fddi_dhost, 6); - memcpy(fsrc, (char *)fddip->fddi_shost, 6); + } else { + memcpy(fdst, (const char *)fddip->fddi_dhost, 6); + memcpy(fsrc, (const char *)fddip->fddi_shost, 6); } } /* * Print the FDDI MAC header */ -static inline void -fddi_print(register const struct fddi_header *fddip, register u_int length, - register const u_char *fsrc, register const u_char *fdst) +static void +fddi_hdr_print(netdissect_options *ndo, + const struct fddi_header *fddip, u_int length, + const u_char *fsrc, const u_char *fdst) { - char *srcname, *dstname; - - srcname = etheraddr_string(fsrc); - dstname = etheraddr_string(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); - } + const char *srcname, *dstname; + + srcname = mac48_string(ndo, fsrc); + dstname = mac48_string(ndo, fdst); + + if (!ndo->ndo_qflag) + print_fddi_fc(ndo, GET_U_1(fddip->fddi_fc)); + ND_PRINT("%s > %s, length %u: ", + srcname, dstname, + length); } -static inline void -fddi_smt_print(const u_char *p, u_int length) +static void +fddi_smt_print(netdissect_options *ndo, const u_char *p _U_, u_int length _U_) { - printf(""); + ND_PRINT(""); } -/* - * This is the top level routine of the printer. 'sp' is the points - * to the FDDI header of the packet, 'tvp' is the timestamp, - * 'length' is the length of the packet off the wire, and 'caplen' - * is the number of bytes actually captured. - */ -void -fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, - register const u_char *p) +u_int +fddi_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { - u_int caplen = h->caplen; - u_int length = h->len; - const struct fddi_header *fddip = (struct fddi_header *)p; - struct ether_header ehdr; - u_short extracted_ethertype; - - ++infodelay; - ts_print(&h->ts); + const struct fddi_header *fddip = (const struct fddi_header *)p; + uint8_t fc; + nd_mac48 srcmac, dstmac; + struct lladdr_info src, dst; + int llc_hdrlen; + ndo->ndo_protocol = "fddi"; if (caplen < FDDI_HDRLEN) { - printf("[|fddi]"); - goto out; + nd_print_trunc(ndo); + return (caplen); } + + fc = GET_U_1(fddip->fddi_fc); + /* * Get the FDDI addresses into a canonical form */ - extract_fddi_addrs(fddip, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); - /* - * Some printers want to get back at the link level addresses, - * and/or check that they're not walking off the end of the packet. - * Rather than pass them all the way down, we set these globals. - */ - snapend = p + caplen; - /* - * Actually, the only printers that use packetp are print-arp.c - * and print-bootp.c, and they assume that packetp points to an - * Ethernet header. The right thing to do is to fix them to know - * which link type is in use when they excavate. XXX - */ - packetp = (u_char *)&ehdr; + extract_fddi_addrs(fddip, (char *)srcmac, (char *)dstmac); + + if (ndo->ndo_eflag) + fddi_hdr_print(ndo, fddip, length, srcmac, dstmac); - if (eflag) - fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); + src.addr = srcmac; + src.addr_string = mac48_string; + dst.addr = dstmac; + dst.addr_string = mac48_string; /* Skip over FDDI MAC header */ length -= FDDI_HDRLEN; @@ -296,40 +306,42 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, caplen -= FDDI_HDRLEN; /* Frame Control field determines interpretation of packet */ - extracted_ethertype = 0; - 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(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_print(fddip, length + FDDI_HDRLEN, - ESRC(&ehdr), EDST(&ehdr)); - if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); - } - if (!xflag && !qflag) - 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 ((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_print(fddip, length + FDDI_HDRLEN, ESRC(&ehdr), - EDST(&ehdr)); - if (!xflag && !qflag) - default_print(p, caplen); + if (!ndo->ndo_eflag) + fddi_hdr_print(ndo, fddip, length + FDDI_HDRLEN, srcmac, + dstmac); + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = 0; } - if (xflag) - default_print(p, caplen); -out: - putchar('\n'); - --infodelay; - if (infoprint) - info(0); + return (FDDI_HDRLEN + llc_hdrlen); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the FDDI header of the packet, 'h->ts' is the timestamp, + * 'h->len' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +void +fddi_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) +{ + ndo->ndo_protocol = "fddi"; + ndo->ndo_ll_hdr_len += fddi_print(ndo, p, h->len, h->caplen); }