]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize some generic code
authorDenis Ovsienko <[email protected]>
Thu, 3 Apr 2014 13:40:30 +0000 (17:40 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 3 Apr 2014 13:43:33 +0000 (17:43 +0400)
16 files changed:
interface.h
netdissect.h
print-domain.c
print-dvmrp.c
print-fr.c
print-hsrp.c
print-igmp.c
print-isoclns.c
print-lspping.c
print-lwres.c
print-pim.c
print-rsvp.c
signature.c
signature.h
tcpdump.c
util.c

index b05a9a168161c8eef475d096b1190577c730d415..d08f9880f2937f6dd96777d9b8a435a78ff2abe1 100644 (file)
@@ -117,9 +117,6 @@ extern int32_t thiszone;    /* seconds offset from gmt to local time */
 /* Bail if "var" was not captured */
 #define TCHECK(var) TCHECK2(var, sizeof(var))
 
-extern void ts_print(const struct timeval *);
-extern void relts_print(int);
-
 extern int fn_print(const u_char *, const u_char *);
 extern int fn_printn(const u_char *, u_int, const u_char *);
 extern int fn_printzp(const u_char *, u_int, const u_char *);
index 1c53dae85bc4344b0c7e4f00d7a56dcb39fe92a4..8ea2c37caebff186e2790364f3341f06bd61ba38 100644 (file)
@@ -252,11 +252,8 @@ struct netdissect_options {
 #define ND_PRINT(STUFF) (*ndo->ndo_printf)STUFF
 #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
 
-#if 0
-extern void ts_print(netdissect_options *ipdo,
-                    const struct timeval *);
-extern void relts_print(int);
-#endif
+extern void ts_print(netdissect_options *, const struct timeval *);
+extern void relts_print(netdissect_options *, int);
 
 extern int fn_print(const u_char *, const u_char *);
 extern int fn_printn(const u_char *, u_int, const u_char *);
index ee556d6c58c7c56b0d1d06f05be79bad5c65d7a4..001195680f68a54088a9bb4e2c324fb3b8cb4972 100644 (file)
@@ -395,7 +395,7 @@ ns_rprint(netdissect_options *ndo,
        } else if (ndo->ndo_vflag > 2) {
                /* print ttl */
                ND_PRINT((ndo, " ["));
-               relts_print(EXTRACT_32BITS(cp));
+               relts_print(ndo, EXTRACT_32BITS(cp));
                ND_PRINT((ndo, "]"));
                cp += 4;
        } else {
index 20af2cf5298d22657a972b57a21295ce148ab018..2d712d8258b0a8b231211f8fa1c9df2bb716538a 100644 (file)
@@ -337,7 +337,7 @@ print_prune(netdissect_options *ndo,
        ND_PRINT((ndo, " src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)));
        bp += 8;
        ND_PRINT((ndo, " timer "));
-       relts_print(EXTRACT_32BITS(bp));
+       relts_print(ndo, EXTRACT_32BITS(bp));
        return (0);
 trunc:
        return (-1);
index 41ef2e2e7086daa883ad299c1d60039f741e7234..29976ab90e4dd5def60d1967f52b1ed8b8c96140 100644 (file)
@@ -469,7 +469,7 @@ mfr_print(netdissect_options *ndo,
 
             case MFR_CTRL_IE_TIMESTAMP:
                 if (ie_len == sizeof(struct timeval)) {
-                    ts_print((const struct timeval *)tptr);
+                    ts_print(ndo, (const struct timeval *)tptr);
                     break;
                 }
                 /* fall through and hexdump if no unix timestamp */
index f8299bcdfdabffb45307b706109a2633f1ef5163..f35188f79e09509844e27687d5a31639f38c0295 100644 (file)
@@ -116,9 +116,9 @@ hsrp_print(netdissect_options *ndo, register const u_int8_t *bp, register u_int
        ND_PRINT((ndo, "addr=%s", ipaddr_string(&hp->hsrp_virtaddr)));
        if (ndo->ndo_vflag) {
                ND_PRINT((ndo, " hellotime="));
-               relts_print(hp->hsrp_hellotime);
+               relts_print(ndo, hp->hsrp_hellotime);
                ND_PRINT((ndo, " holdtime="));
-               relts_print(hp->hsrp_holdtime);
+               relts_print(ndo, hp->hsrp_holdtime);
                ND_PRINT((ndo, " priority=%d", hp->hsrp_priority));
                ND_PRINT((ndo, " auth=\""));
                if (fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata),
index ae931a88facb5c5f1aee737acf1e9b231e5989b3..1c9a71c9cd0ec3e9c8647738f130dc0ce6f4423c 100644 (file)
@@ -226,7 +226,7 @@ print_igmpv3_query(netdissect_options *ndo,
         if (mrt < 600) {
             ND_PRINT((ndo, "%.1fs", mrt * 0.1));
         } else {
-            relts_print(mrt / 10);
+            relts_print(ndo, mrt / 10);
         }
        ND_PRINT((ndo, "]"));
     }
index 50e268c8439b0f905434ed31db37430c2e2a1dc0..d9a69093d127259bff3e93b9e192881a54e9e1cb 100644 (file)
@@ -2675,7 +2675,7 @@ isis_print(netdissect_options *ndo,
                     ND_PRINT((ndo, ", (malformed subTLV) "));
 
 #ifdef HAVE_LIBCRYPTO
-                sigcheck = signature_verify(optr, length,
+                sigcheck = signature_verify(ndo, optr, length,
                                             (unsigned char *)tptr + 1);
 #else
                 sigcheck = CANT_CHECK_SIGNATURE;
index 9ecc77ed0808b9994504083223d7754a92fe276e..4103a924da82837b5f269407f8f57e2a761e032a 100644 (file)
@@ -552,13 +552,13 @@ lspping_print(netdissect_options *ndo,
     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_sent_sec);
     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_sent_usec);
     ND_PRINT((ndo, "\n\t  Sender Timestamp: "));
-    ts_print(&timestamp);
+    ts_print(ndo, &timestamp);
 
     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_sec);
     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_usec);
     ND_PRINT((ndo, "Receiver Timestamp: "));
     if ((timestamp.tv_sec != 0) && (timestamp.tv_usec != 0))
-        ts_print(&timestamp);
+        ts_print(ndo, &timestamp);
     else
         ND_PRINT((ndo, "no timestamp"));
 
index d253da9d96c3b3e7582d42a21da66ea4fe9e9eb3..90334e8c2de65c19cbf45331cadf10366b94bc40 100644 (file)
@@ -543,7 +543,7 @@ lwres_print(netdissect_options *ndo,
                                    EXTRACT_16BITS(&grbn->rdclass))));
                        }
                        ND_PRINT((ndo, " TTL "));
-                       relts_print(EXTRACT_32BITS(&grbn->ttl));
+                       relts_print(ndo, EXTRACT_32BITS(&grbn->ttl));
                        ND_PRINT((ndo, " %u/%u", EXTRACT_16BITS(&grbn->nrdatas),
                            EXTRACT_16BITS(&grbn->nsigs)));
 
index 645a490126c3c9266ba8ff7b36b9216e4ed4faf3..9ac9eeb68bc4eb960382c362fe96cfbc69d59590 100644 (file)
@@ -127,7 +127,7 @@ pimv1_join_prune_print(netdissect_options *ndo,
                hold = EXTRACT_16BITS(&bp[6]);
                if (hold != 180) {
                        ND_PRINT((ndo, "Hold "));
-                       relts_print(hold);
+                       relts_print(ndo, hold);
                }
                ND_PRINT((ndo, "%s (%s/%d, %s", njoin ? "Join" : "Prune",
                ipaddr_string(&bp[26]), bp[25] & 0x3f,
@@ -149,7 +149,7 @@ pimv1_join_prune_print(netdissect_options *ndo,
        if (ndo->ndo_vflag > 1)
                ND_PRINT((ndo, "\n"));
        ND_PRINT((ndo, " Hold time: "));
-       relts_print(EXTRACT_16BITS(&bp[6]));
+       relts_print(ndo, EXTRACT_16BITS(&bp[6]));
        if (ndo->ndo_vflag < 2)
                return;
        bp += 8;
@@ -234,7 +234,7 @@ pimv1_print(netdissect_options *ndo,
                if (ndo->ndo_vflag) {
                        ND_TCHECK2(bp[10],2);
                        ND_PRINT((ndo, " (Hold-time "));
-                       relts_print(EXTRACT_16BITS(&bp[10]));
+                       relts_print(ndo, EXTRACT_16BITS(&bp[10]));
                        ND_PRINT((ndo, ")"));
                }
                break;
@@ -264,7 +264,7 @@ pimv1_print(netdissect_options *ndo,
                        if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
                                ND_PRINT((ndo, "/%s", ipaddr_string(&bp[12])));
                        ND_PRINT((ndo, " RP %s hold ", ipaddr_string(&bp[16])));
-                       relts_print(EXTRACT_16BITS(&bp[22]));
+                       relts_print(ndo, EXTRACT_16BITS(&bp[22]));
                }
                break;
        case 5:
@@ -342,7 +342,7 @@ cisco_autorp_print(netdissect_options *ndo,
        ND_PRINT((ndo, " Hold "));
        hold = EXTRACT_16BITS(&bp[2]);
        if (hold)
-               relts_print(EXTRACT_16BITS(&bp[2]));
+               relts_print(ndo, EXTRACT_16BITS(&bp[2]));
        else
                ND_PRINT((ndo, "FOREVER"));
 
@@ -657,7 +657,7 @@ pimv2_print(netdissect_options *ndo,
 
                        switch (otype) {
                        case PIMV2_HELLO_OPTION_HOLDTIME:
-                               relts_print(EXTRACT_16BITS(bp));
+                               relts_print(ndo, EXTRACT_16BITS(bp));
                                break;
 
                        case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
@@ -698,7 +698,7 @@ pimv2_print(netdissect_options *ndo,
                                ND_PRINT((ndo, "v%d", *bp));
                                if (*(bp+1) != 0) {
                                        ND_PRINT((ndo, ", interval "));
-                                       relts_print(*(bp+1));
+                                       relts_print(ndo, *(bp+1));
                                }
                                if (EXTRACT_16BITS(bp+2) != 0) {
                                        ND_PRINT((ndo, " ?0x%04x?", EXTRACT_16BITS(bp+2)));
@@ -863,7 +863,7 @@ pimv2_print(netdissect_options *ndo,
                        if (holdtime == 0xffff)
                                ND_PRINT((ndo, "infinite"));
                        else
-                               relts_print(holdtime);
+                               relts_print(ndo, holdtime);
                }
                bp += 4; len -= 4;
                for (i = 0; i < ngroup; i++) {
@@ -967,7 +967,7 @@ pimv2_print(netdissect_options *ndo,
                                        goto bs_done;
                                }
                                ND_PRINT((ndo, ",holdtime="));
-                               relts_print(EXTRACT_16BITS(bp));
+                               relts_print(ndo, EXTRACT_16BITS(bp));
                                if (bp + 2 >= ep) {
                                        ND_PRINT((ndo, "...)"));
                                        goto bs_done;
@@ -1019,7 +1019,7 @@ pimv2_print(netdissect_options *ndo,
                ND_PRINT((ndo, " prio=%d", bp[1]));
                if (bp + 3 >= ep) break;
                ND_PRINT((ndo, " holdtime="));
-               relts_print(EXTRACT_16BITS(&bp[2]));
+               relts_print(ndo, EXTRACT_16BITS(&bp[2]));
                bp += 4;
 
                /* Encoded-Unicast-RP-Address */
@@ -1065,7 +1065,7 @@ pimv2_print(netdissect_options *ndo,
                bp += advance;
                ND_TCHECK2(bp[0], 2);
                ND_PRINT((ndo, " TUNR "));
-               relts_print(EXTRACT_16BITS(bp));
+               relts_print(ndo, EXTRACT_16BITS(bp));
                break;
 
 
index e869b970875917fe2157fdfcb1d5c04bf311745a..38bfbbb6c77f303d032f5e60003ca8c4eef3e962 100644 (file)
@@ -1666,7 +1666,7 @@ _U_
                        EXTRACT_32BITS(obj_ptr.rsvp_obj_integrity->digest + 12)));
 
 #ifdef HAVE_LIBCRYPTO
-                sigcheck = signature_verify(pptr, plen, (unsigned char *)obj_ptr.\
+                sigcheck = signature_verify(ndo, pptr, plen, (unsigned char *)obj_ptr.\
                                              rsvp_obj_integrity->digest);
 #else
                 sigcheck = CANT_CHECK_SIGNATURE;
index f80c285399b653331f81a07801a9667eae0530e2..c35b78383f8b895f69b1292405dfc1461c36b1a7 100644 (file)
@@ -115,7 +115,8 @@ USES_APPLE_RST
  * Currently only MD5 is supported.
  */
 int
-signature_verify (const u_char *pptr, u_int plen, u_char *sig_ptr)
+signature_verify(netdissect_options *ndo,
+                 const u_char *pptr, u_int plen, u_char *sig_ptr)
 {
     u_int8_t rcvsig[16];
     u_int8_t sig[16];
@@ -140,7 +141,7 @@ signature_verify (const u_char *pptr, u_int plen, u_char *sig_ptr)
     } else {
 
         for (i = 0; i < sizeof(sig); ++i) {
-            (void)printf("%02x", sig[i]);
+            ND_PRINT((ndo, "%02x", sig[i]));
         }
 
         return (SIGNATURE_INVALID);
index 3f664c5bae263232b74d4dba245ac67e5d42efaf..a052df866fb865e713bad86095d83384924bc362 100644 (file)
  * Original code by Hannes Gredler ([email protected])
  */
 
+/* for netdissect_options */
+#include "netdissect.h"
+
 /* signature checking result codes */
 #define SIGNATURE_VALID                0
 #define SIGNATURE_INVALID      1
 #define CANT_CHECK_SIGNATURE   2
 
 extern const struct tok signature_check_values[];
-extern int signature_verify (const u_char *, u_int, u_char *);
+extern int signature_verify(netdissect_options *, const u_char *, u_int, u_char *);
index 3d2ef4e9068fa5e0fb76caf1bf8b55e3c5f7f920..294c74bfea2684d367113d2d95cdac8356fd79c8 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1996,10 +1996,10 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
        ++packets_captured;
 
        ++infodelay;
-       ts_print(&h->ts);
 
        print_info = (struct print_info *)user;
         ndo = print_info->ndo;
+       ts_print(ndo, &h->ts);
 
        /*
         * Some printers want to check that they're not walking off the
diff --git a/util.c b/util.c
index 822b60e5e557d90b1681fe7dcd91a44b3b7f955b..4304e519875d7499dfd101064406fa2d529f97ee 100644 (file)
--- a/util.c
+++ b/util.c
@@ -38,8 +38,6 @@
 
 #include "interface.h"
 
-char * ts_format(register int, register int);
-
 /*
  * Print out a null-terminated filename (or other ascii string).
  * If ep is NULL, assume no truncation check is needed.
@@ -137,7 +135,7 @@ fn_printzp(register const u_char *s, register u_int n,
 /*
  * Format the timestamp
  */
-char *
+static char *
 ts_format(register int sec, register int usec)
 {
         static char buf[sizeof("00:00:00.000000")];
@@ -151,7 +149,8 @@ ts_format(register int sec, register int usec)
  * Print the timestamp
  */
 void
-ts_print(register const struct timeval *tvp)
+ts_print(netdissect_options *ndo,
+         register const struct timeval *tvp)
 {
        register int s;
        struct tm *tm;
@@ -161,20 +160,20 @@ ts_print(register const struct timeval *tvp)
        int d_usec;
        int d_sec;
 
-       switch (tflag) {
+       switch (ndo->ndo_tflag) {
 
        case 0: /* Default */
                s = (tvp->tv_sec + thiszone) % 86400;
-                (void)printf("%s ", ts_format(s, tvp->tv_usec));
+               ND_PRINT((ndo, "%s ", ts_format(s, tvp->tv_usec)));
                break;
 
        case 1: /* No time stamp */
                break;
 
        case 2: /* Unix timeval style */
-               (void)printf("%u.%06u ",
+               ND_PRINT((ndo, "%u.%06u ",
                             (unsigned)tvp->tv_sec,
-                            (unsigned)tvp->tv_usec);
+                            (unsigned)tvp->tv_usec));
                break;
 
        case 3: /* Microseconds since previous packet */
@@ -193,9 +192,9 @@ ts_print(register const struct timeval *tvp)
                     d_sec--;
                 }
 
-                (void)printf("%s ", ts_format(d_sec, d_usec));
+                ND_PRINT((ndo, "%s ", ts_format(d_sec, d_usec)));
 
-                if (tflag == 3) { /* set timestamp for last packet */
+                if (ndo->ndo_tflag == 3) { /* set timestamp for last packet */
                     b_sec = tvp->tv_sec;
                     b_usec = tvp->tv_usec;
                 }
@@ -206,11 +205,11 @@ ts_print(register const struct timeval *tvp)
                Time = (tvp->tv_sec + thiszone) - s;
                tm = gmtime (&Time);
                if (!tm)
-                       printf("Date fail  ");
+                       ND_PRINT((ndo, "Date fail  "));
                else
-                       printf("%04d-%02d-%02d %s ",
+                       ND_PRINT((ndo, "%04d-%02d-%02d %s ",
                                tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
-                               ts_format(s, tvp->tv_usec));
+                               ts_format(s, tvp->tv_usec)));
                break;
        }
 }
@@ -221,7 +220,8 @@ ts_print(register const struct timeval *tvp)
  * is represented as 1y1w1d1h1m1s.
  */
 void
-relts_print(int secs)
+relts_print(netdissect_options *ndo,
+            int secs)
 {
        static const char *lengths[] = {"y", "w", "d", "h", "m", "s"};
        static const int seconds[] = {31536000, 604800, 86400, 3600, 60, 1};
@@ -229,16 +229,16 @@ relts_print(int secs)
        const int *s = seconds;
 
        if (secs == 0) {
-               (void)printf("0s");
+               ND_PRINT((ndo, "0s"));
                return;
        }
        if (secs < 0) {
-               (void)printf("-");
+               ND_PRINT((ndo, "-"));
                secs = -secs;
        }
        while (secs > 0) {
                if (secs >= *s) {
-                       (void)printf("%d%s", secs / *s, *l);
+                       ND_PRINT((ndo, "%d%s", secs / *s, *l));
                        secs -= (secs / *s) * *s;
                }
                s++;
@@ -260,8 +260,8 @@ print_unknown_data(netdissect_options *ndo, const u_char *cp,const char *ident,i
                    ident));
                return(0);
        }
-       if (snapend - cp < len)
-               len = snapend - cp;
+       if (ndo->ndo_snapend - cp < len)
+               len = ndo->ndo_snapend - cp;
        if (len < 0) {
           ND_PRINT((ndo,"%sDissector error: print_unknown_data called with pointer past end of packet",
                    ident));