From: Denis Ovsienko Date: Thu, 27 Feb 2014 11:13:43 +0000 (+0400) Subject: NDOize AH, BEEP and DTP decoders X-Git-Tag: tcpdump-4.6.0~209 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/39d15607cad1b4b463794c1a67873f6182dc52f7 NDOize AH, BEEP and DTP decoders Also remove some unnecessary passages. --- diff --git a/interface.h b/interface.h index 3187e24c..f636e482 100644 --- a/interface.h +++ b/interface.h @@ -190,7 +190,6 @@ extern u_int sunatm_if_print(const struct pcap_pkthdr *, const u_char *); extern int oam_print(const u_char *, u_int, u_int); extern void bootp_print(const u_char *, u_int); extern void bgp_print(const u_char *, int); -extern void beep_print(const u_char *, u_int); extern void cnfp_print(const u_char *, const u_char *); extern void decnet_print(const u_char *, u_int, u_int); extern void default_print(const u_char *, u_int); @@ -296,7 +295,6 @@ extern void udld_print(const u_char *, u_int); extern void udp_print(const u_char *, u_int, const u_char *, int); extern void vtp_print(const u_char *, u_int); extern void wb_print(const void *, u_int); -extern int ah_print(register const u_char *); extern int ipcomp_print(register const u_char *, int *); extern void rx_print(register const u_char *, int, int, int, u_char *); extern void netbeui_print(u_short, const u_char *, int); @@ -316,7 +314,6 @@ extern void mpcp_print(const u_char *, u_int); extern void cfm_print(const u_char *, u_int); extern void pgm_print(const u_char *, u_int, const u_char *); extern void cdp_print(const u_char *, u_int, u_int); -extern void dtp_print(const u_char *, u_int); extern void stp_print(const u_char *, u_int); extern void radius_print(const u_char *, u_int); extern void lwres_print(const u_char *, u_int); diff --git a/netdissect.h b/netdissect.h index ce647cca..15c127f1 100644 --- a/netdissect.h +++ b/netdissect.h @@ -368,6 +368,9 @@ extern int print_unknown_data(netdissect_options *,const u_char *, const char *, extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int); extern void hex_print(netdissect_options *,const char *ident, const u_char *cp,u_int); +extern int ah_print(netdissect_options *, register const u_char *); +extern void beep_print(netdissect_options *, const u_char *, u_int); +extern void dtp_print(netdissect_options *, const u_char *, u_int); /* stuff that has not yet been rototiled */ extern const u_char * ns_nprint (register const u_char *, register const u_char *); @@ -487,8 +490,6 @@ extern void timed_print(netdissect_options *,const u_char *, u_int); extern void udp_print(netdissect_options *,const u_char *, u_int, const u_char *, int); extern void wb_print(netdissect_options *,const void *, u_int); -extern int ah_print(netdissect_options *,register const u_char *, - register const u_char *); extern void esp_print_decodesecret(netdissect_options *ndo); extern int ipcomp_print(netdissect_options *,register const u_char *, register const u_char *, int *); diff --git a/print-ah.c b/print-ah.c index 1af1feb4..360fc5e5 100644 --- a/print-ah.c +++ b/print-ah.c @@ -27,15 +27,13 @@ #include -#include - #include "ah.h" -#include "interface.h" +#include "netdissect.h" #include "extract.h" int -ah_print(register const u_char *bp) +ah_print(netdissect_options *ndo, register const u_char *bp) { register const struct ah *ah; register const u_char *ep; @@ -43,23 +41,23 @@ ah_print(register const u_char *bp) u_int32_t spi; ah = (const struct ah *)bp; - ep = snapend; /* 'ep' points to the end of available data. */ + ep = ndo->ndo_snapend; /* 'ep' points to the end of available data. */ - TCHECK(*ah); + ND_TCHECK(*ah); sumlen = ah->ah_len << 2; spi = EXTRACT_32BITS(&ah->ah_spi); - printf("AH(spi=0x%08x", spi); - if (vflag) - printf(",sumlen=%d", sumlen); - printf(",seq=0x%x", EXTRACT_32BITS(ah + 1)); + ND_PRINT((ndo, "AH(spi=0x%08x", spi)); + if (ndo->ndo_vflag) + ND_PRINT((ndo, ",sumlen=%d", sumlen)); + ND_PRINT((ndo, ",seq=0x%x", EXTRACT_32BITS(ah + 1))); if (bp + sizeof(struct ah) + sumlen > ep) - fputs("[truncated]", stdout); - fputs("): ", stdout); + ND_PRINT((ndo, "[truncated]")); + ND_PRINT((ndo, "): ")); return sizeof(struct ah) + sumlen; trunc: - fputs("[|AH]", stdout); + ND_PRINT((ndo, "[|AH]")); return -1; } diff --git a/print-beep.c b/print-beep.c index c8145658..1ddb9eb5 100644 --- a/print-beep.c +++ b/print-beep.c @@ -15,15 +15,9 @@ #include -#ifdef HAVE_MEMORY_H -#include -#endif -#include -#include #include -#include "interface.h" -#include "extract.h" +#include "netdissect.h" /* Check for a string but not go beyond length * Return TRUE on match, FALSE otherwise @@ -31,8 +25,6 @@ * Looks at the first few chars up to tl1 ... */ -static int l_strnstart(const char *, u_int, const char *, u_int); - static int l_strnstart(const char *tstr1, u_int tl1, const char *str2, u_int l2) { @@ -44,23 +36,23 @@ l_strnstart(const char *tstr1, u_int tl1, const char *str2, u_int l2) } void -beep_print(const u_char *bp, u_int length) +beep_print(netdissect_options *ndo, const u_char *bp, u_int length) { if (l_strnstart("MSG", 4, (const char *)bp, length)) /* A REQuest */ - printf(" BEEP MSG"); + ND_PRINT((ndo, " BEEP MSG")); else if (l_strnstart("RPY ", 4, (const char *)bp, length)) - printf(" BEEP RPY"); + ND_PRINT((ndo, " BEEP RPY")); else if (l_strnstart("ERR ", 4, (const char *)bp, length)) - printf(" BEEP ERR"); + ND_PRINT((ndo, " BEEP ERR")); else if (l_strnstart("ANS ", 4, (const char *)bp, length)) - printf(" BEEP ANS"); + ND_PRINT((ndo, " BEEP ANS")); else if (l_strnstart("NUL ", 4, (const char *)bp, length)) - printf(" BEEP NUL"); + ND_PRINT((ndo, " BEEP NUL")); else if (l_strnstart("SEQ ", 4, (const char *)bp, length)) - printf(" BEEP SEQ"); + ND_PRINT((ndo, " BEEP SEQ")); else if (l_strnstart("END", 4, (const char *)bp, length)) - printf(" BEEP END"); + ND_PRINT((ndo, " BEEP END")); else - printf(" BEEP (payload or undecoded)"); + ND_PRINT((ndo, " BEEP (payload or undecoded)")); } diff --git a/print-dtp.c b/print-dtp.c index 90ce6cc3..e502ad54 100644 --- a/print-dtp.c +++ b/print-dtp.c @@ -23,13 +23,9 @@ #include -#include -#include - -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" -#include "nlpid.h" #define DTP_HEADER_LEN 1 #define DTP_DOMAIN_TLV 0x0001 @@ -46,7 +42,7 @@ static const struct tok dtp_tlv_values[] = { }; void -dtp_print (const u_char *pptr, u_int length) +dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length) { int type, len; const u_char *tptr; @@ -56,17 +52,17 @@ dtp_print (const u_char *pptr, u_int length) tptr = pptr; - if (!TTEST2(*tptr, DTP_HEADER_LEN)) + if (!ND_TTEST2(*tptr, DTP_HEADER_LEN)) goto trunc; - printf("DTPv%u, length %u", + ND_PRINT((ndo, "DTPv%u, length %u", (*tptr), - length); + length)); /* * In non-verbose mode, just print version. */ - if (vflag < 1) { + if (ndo->ndo_vflag < 1) { return; } @@ -74,7 +70,7 @@ dtp_print (const u_char *pptr, u_int length) while (tptr < (pptr+length)) { - if (!TTEST2(*tptr, 4)) + if (!ND_TTEST2(*tptr, 4)) goto trunc; type = EXTRACT_16BITS(tptr); @@ -85,22 +81,22 @@ dtp_print (const u_char *pptr, u_int length) return; } - printf("\n\t%s (0x%04x) TLV, length %u", + ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u", tok2str(dtp_tlv_values, "Unknown", type), - type, len); + type, len)); switch (type) { case DTP_DOMAIN_TLV: - printf(", %s", tptr+4); + ND_PRINT((ndo, ", %s", tptr+4)); break; case DTP_STATUS_TLV: case DTP_DTP_TYPE_TLV: - printf(", 0x%x", *(tptr+4)); + ND_PRINT((ndo, ", 0x%x", *(tptr+4))); break; case DTP_NEIGHBOR_TLV: - printf(", %s", etheraddr_string(tptr+4)); + ND_PRINT((ndo, ", %s", etheraddr_string(tptr+4))); break; default: @@ -112,7 +108,7 @@ dtp_print (const u_char *pptr, u_int length) return; trunc: - printf("[|dtp]"); + ND_PRINT((ndo, "[|dtp]")); } /* diff --git a/print-ip.c b/print-ip.c index ef23bd53..b069e4de 100644 --- a/print-ip.c +++ b/print-ip.c @@ -327,7 +327,7 @@ again: case IPPROTO_AH: ipds->nh = *ipds->cp; - ipds->advance = ah_print(ipds->cp); + ipds->advance = ah_print(gndo, ipds->cp); if (ipds->advance <= 0) break; ipds->cp += ipds->advance; diff --git a/print-ip6.c b/print-ip6.c index 484b2f1b..8e088cd5 100644 --- a/print-ip6.c +++ b/print-ip6.c @@ -205,7 +205,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length) icmp6_print(ndo, cp, len, (const u_char *)ip6, fragmented); return; case IPPROTO_AH: - advance = ah_print(cp); + advance = ah_print(gndo, cp); nh = *cp; break; case IPPROTO_ESP: diff --git a/print-llc.c b/print-llc.c index 597773bb..5794365f 100644 --- a/print-llc.c +++ b/print-llc.c @@ -440,7 +440,7 @@ snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad) cdp_print(p, length, caplen); return (1); case PID_CISCO_DTP: - dtp_print(p, length); + dtp_print(gndo, p, length); return (1); case PID_CISCO_UDLD: udld_print(p, length); diff --git a/print-tcp.c b/print-tcp.c index e5acfa4c..2b470f59 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -683,7 +683,7 @@ tcp_print(register const u_char *bp, register u_int length, smb_tcp_print(bp, length); #endif else if (sport == BEEP_PORT || dport == BEEP_PORT) - beep_print(bp, length); + beep_print(gndo, bp, length); else if (sport == OPENFLOW_PORT || dport == OPENFLOW_PORT) openflow_print(bp, length); else if (length > 2 &&