]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize AH, BEEP and DTP decoders
authorDenis Ovsienko <[email protected]>
Thu, 27 Feb 2014 11:13:43 +0000 (15:13 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 27 Feb 2014 12:01:23 +0000 (16:01 +0400)
Also remove some unnecessary passages.

interface.h
netdissect.h
print-ah.c
print-beep.c
print-dtp.c
print-ip.c
print-ip6.c
print-llc.c
print-tcp.c

index 3187e24c771f41e2006d3c70838264dfe79517c8..f636e482069dae26555404a8a82cd31b03102133 100644 (file)
@@ -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);
index ce647cca9e5433374b0fd9b266920e1f8d45d670..15c127f164e7d71de2ec747206a7c3519ee4b075 100644 (file)
@@ -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 *);
index 1af1feb49bfd7d7a135d42aa5f771028c39c5c29..360fc5e5421e42f0418df12b2db3cf60503d2488 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-
 #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;
 }
index c8145658e37a53420b45b65ecc401a8e8df8784a..1ddb9eb5f4a95411518f0a7a7a5183b80beb0653 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
-#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)"));
 }
index 90ce6cc377c13fb56f76291390e3c5f0de94251c..e502ad54ce1f394b6112124c0365dd751c1b5a76 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <string.h>
-
-#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]"));
 }
 
 /*
index ef23bd5332199ee74c04a359c0fd81585c9ecd08..b069e4de30979817d8c0890659aa8b470b026245 100644 (file)
@@ -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;
index 484b2f1bf44da2682275b4636f356a18562c5f86..8e088cd573cc8f4a6a79e281bd3ea3130de3947c 100644 (file)
@@ -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:
index 597773bb25722809a8c9997493edf4266ed0fe2c..5794365fc81f625f5270972970f13ae1945b5714 100644 (file)
@@ -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);
index e5acfa4c0694c977df85c84308a0a72ab98a4b3a..2b470f5929c58df18052897d525a35089d2a626f 100644 (file)
@@ -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 &&