From: Denis Ovsienko Date: Fri, 7 Mar 2014 13:52:45 +0000 (+0400) Subject: NDOize 5 more decoders X-Git-Tag: tcpdump-4.6.0~189 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/374aad6c0ea6d12ac4316ead82bb78fc3ff5e05d NDOize 5 more decoders Update Apple's IP over IEEE1394, Bluetooth, CALM/FAST, IPv6 fragments and LAN emulation decoders. Remove some stray passages while at it. --- diff --git a/interface.h b/interface.h index 49372ac8..e00748af 100644 --- a/interface.h +++ b/interface.h @@ -211,7 +211,6 @@ extern char *q922_string(const u_char *); extern u_int ieee802_11_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_11_radio_if_print(const struct pcap_pkthdr *, const u_char *); -extern u_int ap1394_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_11_radio_avs_if_print(const struct pcap_pkthdr *, const u_char *); extern void gre_print(const u_char *, u_int); @@ -258,8 +257,6 @@ extern void vqp_print(register const u_char *, register u_int); extern u_int raw_if_print(const struct pcap_pkthdr *, const u_char *); extern void rip_print(const u_char *, u_int); extern u_int sl_if_print(const struct pcap_pkthdr *, const u_char *); -extern void lane_print(const u_char *, u_int, u_int); -extern u_int lane_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int sl_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int chdlc_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int chdlc_print(register const u_char *, u_int); @@ -322,7 +319,6 @@ extern void bfd_print(const u_char *, u_int, u_int); extern void sip_print(const u_char *, u_int); extern void syslog_print(const u_char *, u_int); extern int mptcp_print(const u_char *, u_int, u_char); -extern u_int bt_if_print(const struct pcap_pkthdr *, const u_char *); extern u_int usb_linux_48_byte_print(const struct pcap_pkthdr *, const u_char *); extern u_int usb_linux_64_byte_print(const struct pcap_pkthdr *, const u_char *); extern void vxlan_print(const u_char *, u_int); @@ -334,7 +330,6 @@ extern void ahcp_print(const u_char *, const u_int); extern void ip6_opt_print(const u_char *, int); extern int hbhopt_print(const u_char *); extern int dstopt_print(const u_char *); -extern int frag6_print(const u_char *, const u_char *); extern int mobility_print(const u_char *, const u_char *); extern void ripng_print(const u_char *, unsigned int); extern int rt6_print(const u_char *, const u_char *); diff --git a/netdissect.h b/netdissect.h index e5550298..25618c7a 100644 --- a/netdissect.h +++ b/netdissect.h @@ -380,6 +380,10 @@ extern void igrp_print(netdissect_options *, const u_char *, u_int); extern void msdp_print(netdissect_options *, const u_char *, u_int); extern u_int null_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void mobile_print(netdissect_options *, const u_char *, u_int); +extern u_int ap1394_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); +extern u_int bt_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); +extern void lane_print(netdissect_options *, const u_char *, u_int, u_int); +extern u_int lane_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); /* stuff that has not yet been rototiled */ extern const u_char * ns_nprint (register const u_char *, register const u_char *); @@ -533,12 +537,11 @@ extern u_int ieee802_15_4_if_print(netdissect_options *,const struct pcap_pkthdr #ifdef INET6 extern void ip6_print(netdissect_options *,const u_char *, u_int); +extern int frag6_print(netdissect_options *, const u_char *, const u_char *); #if 0 extern void ip6_opt_print(netdissect_options *,const u_char *, int); extern int hbhopt_print(netdissect_options *,const u_char *); extern int dstopt_print(netdissect_options *,const u_char *); -extern int frag6_print(netdissect_options *,const u_char *, - const u_char *); extern void icmp6_print(netdissect_options *,const u_char *, const u_char *); extern void ripng_print(netdissect_options *,const u_char *, int); diff --git a/print-ap1394.c b/print-ap1394.c index 3d1cb2e4..6a9e891a 100644 --- a/print-ap1394.c +++ b/print-ap1394.c @@ -25,9 +25,7 @@ #include -#include - -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "ethertype.h" @@ -50,27 +48,27 @@ struct firewire_header { #define FIREWIRE_HDRLEN 18 static inline void -ap1394_hdr_print(register const u_char *bp, u_int length) +ap1394_hdr_print(netdissect_options *ndo, register const u_char *bp, u_int length) { register const struct firewire_header *fp; u_int16_t firewire_type; fp = (const struct firewire_header *)bp; - (void)printf("%s > %s", + ND_PRINT((ndo, "%s > %s", linkaddr_string(fp->firewire_dhost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN), - linkaddr_string(fp->firewire_shost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN)); + linkaddr_string(fp->firewire_shost, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN))); firewire_type = EXTRACT_16BITS(&fp->firewire_type); - if (!qflag) { - (void)printf(", ethertype %s (0x%04x)", + if (!ndo->ndo_qflag) { + ND_PRINT((ndo, ", ethertype %s (0x%04x)", tok2str(ethertype_values,"Unknown", firewire_type), - firewire_type); + firewire_type)); } else { - (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type)); + ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type))); } - (void)printf(", length %u: ", length); + ND_PRINT((ndo, ", length %u: ", length)); } /* @@ -80,7 +78,7 @@ ap1394_hdr_print(register const u_char *bp, u_int length) * is the number of bytes actually captured. */ u_int -ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p) +ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int length = h->len; u_int caplen = h->caplen; @@ -88,12 +86,12 @@ ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p) u_short ether_type; if (caplen < FIREWIRE_HDRLEN) { - printf("[|ap1394]"); + ND_PRINT((ndo, "[|ap1394]")); return FIREWIRE_HDRLEN; } - if (eflag) - ap1394_hdr_print(p, length); + if (ndo->ndo_eflag) + ap1394_hdr_print(ndo, p, length); length -= FIREWIRE_HDRLEN; caplen -= FIREWIRE_HDRLEN; @@ -101,13 +99,13 @@ ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p) p += FIREWIRE_HDRLEN; ether_type = EXTRACT_16BITS(&fp->firewire_type); - if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) { + if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) { /* ether_type not known, print raw packet */ - if (!eflag) - ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN); + if (!ndo->ndo_eflag) + ap1394_hdr_print(ndo, (u_char *)fp, length + FIREWIRE_HDRLEN); - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ndo->ndo_default_print(ndo, p, caplen); } return FIREWIRE_HDRLEN; diff --git a/print-atm.c b/print-atm.c index 1e075d74..dbd251ff 100644 --- a/print-atm.c +++ b/print-atm.c @@ -329,7 +329,7 @@ atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, break; case ATM_LANE: - lane_print(p, length, caplen); + lane_print(gndo, p, length, caplen); break; } } diff --git a/print-bt.c b/print-bt.c index 03a18dc4..95741e60 100644 --- a/print-bt.c +++ b/print-bt.c @@ -23,9 +23,6 @@ #include -#include -#include - #include "interface.h" #include "extract.h" @@ -40,24 +37,24 @@ * is the number of bytes actually captured. */ u_int -bt_if_print(const struct pcap_pkthdr *h, const u_char *p) +bt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int length = h->len; u_int caplen = h->caplen; const pcap_bluetooth_h4_header* hdr = (const pcap_bluetooth_h4_header*)p; if (caplen < BT_HDRLEN) { - printf("[|bt]"); + ND_PRINT((ndo, "[|bt]")); return (BT_HDRLEN); } caplen -= BT_HDRLEN; length -= BT_HDRLEN; p += BT_HDRLEN; - if (eflag) - (void)printf("hci length %d, direction %s, ", length, (EXTRACT_32BITS(&hdr->direction)&0x1)?"in":"out"); + if (ndo->ndo_eflag) + ND_PRINT((ndo, "hci length %d, direction %s, ", length, (EXTRACT_32BITS(&hdr->direction)&0x1)?"in":"out")); - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ndo->ndo_default_print(ndo, p, caplen); return (BT_HDRLEN); } diff --git a/print-calm-fast.c b/print-calm-fast.c index d67c6f54..3d58fe0d 100644 --- a/print-calm-fast.c +++ b/print-calm-fast.c @@ -21,11 +21,7 @@ #include -#include -#include - -#include "interface.h" -#include "extract.h" +#include "netdissect.h" #include "addrtoname.h" /* @@ -46,12 +42,12 @@ calm_fast_print(netdissect_options *ndo, const u_char *eth, const u_char *bp, u_ length -= 2; bp += 2; - printf("CALM FAST src:%s; ", etheraddr_string(eth+6)); - printf("SrcNwref:%d; ", srcNwref); - printf("DstNwref:%d; ", dstNwref); + ND_PRINT((ndo, "CALM FAST src:%s; ", etheraddr_string(eth+6))); + ND_PRINT((ndo, "SrcNwref:%d; ", srcNwref)); + ND_PRINT((ndo, "DstNwref:%d; ", dstNwref)); if (ndo->ndo_vflag) - default_print(bp, length); + ndo->ndo_default_print(ndo, bp, length); } diff --git a/print-frag6.c b/print-frag6.c index 0cc99d50..b8c49fd9 100644 --- a/print-frag6.c +++ b/print-frag6.c @@ -27,15 +27,12 @@ #include -#include - #include "ip6.h" - -#include "interface.h" +#include "netdissect.h" #include "extract.h" int -frag6_print(register const u_char *bp, register const u_char *bp2) +frag6_print(netdissect_options *ndo, register const u_char *bp, register const u_char *bp2) { register const struct ip6_frag *dp; register const struct ip6_hdr *ip6; @@ -43,34 +40,31 @@ frag6_print(register const u_char *bp, register const u_char *bp2) dp = (const struct ip6_frag *)bp; ip6 = (const struct ip6_hdr *)bp2; - TCHECK(dp->ip6f_offlg); + ND_TCHECK(dp->ip6f_offlg); - if (vflag) { - printf("frag (0x%08x:%d|%ld)", + if (ndo->ndo_vflag) { + ND_PRINT((ndo, "frag (0x%08x:%d|%ld)", EXTRACT_32BITS(&dp->ip6f_ident), EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK, sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) - - (long)(bp - bp2) - sizeof(struct ip6_frag)); + (long)(bp - bp2) - sizeof(struct ip6_frag))); } else { - printf("frag (%d|%ld)", + ND_PRINT((ndo, "frag (%d|%ld)", EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK, sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) - - (long)(bp - bp2) - sizeof(struct ip6_frag)); + (long)(bp - bp2) - sizeof(struct ip6_frag))); } -#if 1 /* it is meaningless to decode non-first fragment */ if ((EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK) != 0) return -1; else -#endif { - fputs(" ", stdout); + ND_PRINT((ndo, " ")); return sizeof(struct ip6_frag); } trunc: - fputs("[|frag]", stdout); + ND_PRINT((ndo, "[|frag]")); return -1; -#undef TCHECK } #endif /* INET6 */ diff --git a/print-ip6.c b/print-ip6.c index a2d35ffe..62525346 100644 --- a/print-ip6.c +++ b/print-ip6.c @@ -163,7 +163,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length) nh = *cp; break; case IPPROTO_FRAGMENT: - advance = frag6_print(cp, (const u_char *)ip6); + advance = frag6_print(ndo, cp, (const u_char *)ip6); if (ndo->ndo_snapend <= cp + advance) return; nh = *cp; diff --git a/print-lane.c b/print-lane.c index 49dc3ab1..dd8aff0b 100644 --- a/print-lane.c +++ b/print-lane.c @@ -26,16 +26,10 @@ #include -#include - -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "ether.h" -#ifndef ETHER_ADDR_LEN -#define ETHER_ADDR_LEN 6 -#endif - struct lecdatahdr_8023 { u_int16_t le_header; u_int8_t h_dest[ETHER_ADDR_LEN]; @@ -85,12 +79,12 @@ lane_hdr_print(netdissect_options *ndo, const u_char *bp) * This assumes 802.3, not 802.5, LAN emulation. */ void -lane_print(const u_char *p, u_int length, u_int caplen) +lane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { struct lane_controlhdr *lec; if (caplen < sizeof(struct lane_controlhdr)) { - printf("[|lane]"); + ND_PRINT((ndo, "[|lane]")); return; } @@ -99,9 +93,9 @@ lane_print(const u_char *p, u_int length, u_int caplen) /* * LE Control. */ - printf("lec: proto %x vers %x %s", + ND_PRINT((ndo, "lec: proto %x vers %x %s", lec->lec_proto, lec->lec_vers, - tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode))); + tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode)))); return; } @@ -116,13 +110,13 @@ lane_print(const u_char *p, u_int length, u_int caplen) * Now print the encapsulated frame, under the assumption * that it's an Ethernet frame. */ - ether_print(gndo, p, length, caplen, lane_hdr_print, p - 2); + ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2); } u_int -lane_if_print(const struct pcap_pkthdr *h, const u_char *p) +lane_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { - lane_print(p, h->len, h->caplen); + lane_print(ndo, p, h->len, h->caplen); return (sizeof(struct lecdatahdr_8023)); } diff --git a/tcpdump.c b/tcpdump.c index aeb43cc4..17ecbedf 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -172,9 +172,6 @@ static const struct printer printers[] = { { arcnet_linux_if_print, DLT_ARCNET_LINUX }, #endif { token_if_print, DLT_IEEE802 }, -#ifdef DLT_LANE8023 - { lane_if_print, DLT_LANE8023 }, -#endif { sl_if_print, DLT_SLIP }, #ifdef DLT_SLIP_BSDOS { sl_bsdos_if_print, DLT_SLIP_BSDOS }, @@ -234,9 +231,6 @@ static const struct printer printers[] = { #ifdef DLT_SYMANTEC_FIREWALL { symantec_if_print, DLT_SYMANTEC_FIREWALL }, #endif -#ifdef DLT_APPLE_IP_OVER_IEEE1394 - { ap1394_if_print, DLT_APPLE_IP_OVER_IEEE1394 }, -#endif #ifdef DLT_IEEE802_11_RADIO_AVS { ieee802_11_radio_avs_if_print, DLT_IEEE802_11_RADIO_AVS }, #endif @@ -288,9 +282,6 @@ static const struct printer printers[] = { #ifdef DLT_MFR { mfr_if_print, DLT_MFR }, #endif -#if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H) - { bt_if_print, DLT_BLUETOOTH_HCI_H4_WITH_PHDR}, -#endif #ifdef HAVE_PCAP_USB_H #ifdef DLT_USB_LINUX { usb_linux_48_byte_print, DLT_USB_LINUX}, @@ -343,6 +334,15 @@ static const struct ndo_printer ndo_printers[] = { { null_if_print, DLT_NULL }, #ifdef DLT_LOOP { null_if_print, DLT_LOOP }, +#endif +#ifdef DLT_APPLE_IP_OVER_IEEE1394 + { ap1394_if_print, DLT_APPLE_IP_OVER_IEEE1394 }, +#endif +#if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H) + { bt_if_print, DLT_BLUETOOTH_HCI_H4_WITH_PHDR}, +#endif +#ifdef DLT_LANE8023 + { lane_if_print, DLT_LANE8023 }, #endif { NULL, 0 }, };