]> The Tcpdump Group git mirrors - tcpdump/commitdiff
finalize some previous NDO conversions
authorDenis Ovsienko <[email protected]>
Wed, 26 Mar 2014 09:08:22 +0000 (13:08 +0400)
committerDenis Ovsienko <[email protected]>
Wed, 26 Mar 2014 11:49:27 +0000 (15:49 +0400)
Eliminate a number of fputs(), putchar() and fflush() uses. Justify
preprocessor directives. Don't typecast ND_PRINT() to void and fix some
indentation.

12 files changed:
print-arcnet.c
print-ascii.c
print-bootp.c
print-dccp.c
print-dhcp6.c
print-esp.c
print-ether.c
print-icmp.c
print-icmp6.c
print-ip6.c
print-ip6opts.c
print-lane.c

index 08921bdb1ea81b4c5f74b6091249115c0d761d2d..666b3115b6d70ba91b96cf8f83bc99f742512c10 100644 (file)
@@ -340,7 +340,7 @@ arcnet_encap_print(netdissect_options *ndo, u_char arctype, const u_char *p,
 
        case ARCTYPE_ATALK:     /* XXX was this ever used? */
                if (ndo->ndo_vflag)
-                       fputs("et1 ", stdout);
+                       ND_PRINT((ndo, "et1 "));
                atalk_print(p, length);
                return (1);
 
index 55e0ae72589eca09f89dd974b51255ed7423e423..2f05c3873d210423c7e61d6b6b4ea92a00e7543c 100644 (file)
@@ -153,16 +153,16 @@ hex_print_with_offset(netdissect_options *ndo,
        i = 0;
        while (--nshorts >= 0) {
                if ((i++ % 8) == 0) {
-                  (void)ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
-                  oset += HEXDUMP_BYTES_PER_LINE;
+                       ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
+                       oset += HEXDUMP_BYTES_PER_LINE;
                }
                s = *cp++;
-               (void)ND_PRINT((ndo," %02x%02x", s, *cp++));
+               ND_PRINT((ndo," %02x%02x", s, *cp++));
        }
        if (length & 1) {
                if ((i % 8) == 0)
-                  (void)ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
-               (void)ND_PRINT((ndo," %02x", *cp));
+                       ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
+               ND_PRINT((ndo," %02x", *cp));
        }
 }
 
index 85b563012ae8370cc95a0a19aabe7bf8bb804ecd..c714f939e778513b34aea5a13db01b03c1ee89dd 100644 (file)
@@ -132,21 +132,21 @@ bootp_print(netdissect_options *ndo,
        if (*bp->bp_sname) {
                ND_PRINT((ndo, "\n\t  sname \""));
                if (fn_print(bp->bp_sname, ndo->ndo_snapend)) {
-                       putchar('"');
-                       fputs(tstr + 1, stdout);
+                       ND_PRINT((ndo, "\""));
+                       ND_PRINT((ndo, tstr + 1));
                        return;
                }
-               putchar('"');
+               ND_PRINT((ndo, "\""));
        }
        ND_TCHECK2(bp->bp_file[0], 1);          /* check first char only */
        if (*bp->bp_file) {
                ND_PRINT((ndo, "\n\t  file \""));
                if (fn_print(bp->bp_file, ndo->ndo_snapend)) {
-                       putchar('"');
-                       fputs(tstr + 1, stdout);
+                       ND_PRINT((ndo, "\""));
+                       ND_PRINT((ndo, tstr + 1));
                        return;
                }
-               putchar('"');
+               ND_PRINT((ndo, "\""));
        }
 
        /* Decode the vendor buffer */
@@ -167,7 +167,7 @@ bootp_print(netdissect_options *ndo,
 
        return;
 trunc:
-       fputs(tstr, stdout);
+       ND_PRINT((ndo, tstr));
 }
 
 /*
@@ -452,7 +452,7 @@ rfc1048_print(netdissect_options *ndo,
                                bp += 2;
                                cp = tok2str(xtag2str, "?xT%u", us);
                                if (!first)
-                                       putchar('+');
+                                       ND_PRINT((ndo, "+"));
                                ND_PRINT((ndo, "%s", cp + 1));
                                first = 0;
                        }
@@ -474,12 +474,12 @@ rfc1048_print(netdissect_options *ndo,
 
                case 'a':
                        /* ascii strings */
-                       putchar('"');
+                       ND_PRINT((ndo, "\""));
                        if (fn_printn(bp, len, ndo->ndo_snapend)) {
-                               putchar('"');
+                               ND_PRINT((ndo, "\""));
                                goto trunc;
                        }
-                       putchar('"');
+                       ND_PRINT((ndo, "\""));
                        bp += len;
                        len = 0;
                        break;
@@ -490,7 +490,7 @@ rfc1048_print(netdissect_options *ndo,
                        /* ip addresses/32-bit words */
                        while (len >= sizeof(ul)) {
                                if (!first)
-                                       putchar(',');
+                                       ND_PRINT((ndo, ","));
                                ul = EXTRACT_32BITS(bp);
                                if (c == 'i') {
                                        ul = htonl(ul);
@@ -509,7 +509,7 @@ rfc1048_print(netdissect_options *ndo,
                        /* IP address pairs */
                        while (len >= 2*sizeof(ul)) {
                                if (!first)
-                                       putchar(',');
+                                       ND_PRINT((ndo, ","));
                                memcpy((char *)&ul, (const char *)bp, sizeof(ul));
                                ND_PRINT((ndo, "(%s:", ipaddr_string(&ul)));
                                bp += sizeof(ul);
@@ -525,7 +525,7 @@ rfc1048_print(netdissect_options *ndo,
                        /* shorts */
                        while (len >= sizeof(us)) {
                                if (!first)
-                                       putchar(',');
+                                       ND_PRINT((ndo, ","));
                                us = EXTRACT_16BITS(bp);
                                ND_PRINT((ndo, "%u", us));
                                bp += sizeof(us);
@@ -538,13 +538,13 @@ rfc1048_print(netdissect_options *ndo,
                        /* boolean */
                        while (len > 0) {
                                if (!first)
-                                       putchar(',');
+                                       ND_PRINT((ndo, ","));
                                switch (*bp) {
                                case 0:
-                                       putchar('N');
+                                       ND_PRINT((ndo, "N"));
                                        break;
                                case 1:
-                                       putchar('Y');
+                                       ND_PRINT((ndo, "Y"));
                                        break;
                                default:
                                        ND_PRINT((ndo, "%u?", *bp));
@@ -562,7 +562,7 @@ rfc1048_print(netdissect_options *ndo,
                        /* Bytes */
                        while (len > 0) {
                                if (!first)
-                                       putchar(c == 'x' ? ':' : '.');
+                                       ND_PRINT((ndo, c == 'x' ? ":" : "."));
                                if (c == 'x')
                                        ND_PRINT((ndo, "%02x", *bp));
                                else
@@ -586,7 +586,7 @@ rfc1048_print(netdissect_options *ndo,
                                }
                                tag = *bp++;
                                --len;
-                               fputs(tok2str(nbo2str, NULL, tag), stdout);
+                               ND_PRINT((ndo, tok2str(nbo2str, NULL, tag)));
                                break;
 
                        case TAG_OPT_OVERLOAD:
@@ -598,7 +598,7 @@ rfc1048_print(netdissect_options *ndo,
                                }
                                tag = *bp++;
                                --len;
-                               fputs(tok2str(oo2str, NULL, tag), stdout);
+                               ND_PRINT((ndo, tok2str(oo2str, NULL, tag)));
                                break;
 
                        case TAG_CLIENT_FQDN:
@@ -616,12 +616,12 @@ rfc1048_print(netdissect_options *ndo,
                                if (*bp || *(bp+1))
                                        ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1)));
                                bp += 2;
-                               putchar('"');
+                               ND_PRINT((ndo, "\""));
                                if (fn_printn(bp, len - 3, ndo->ndo_snapend)) {
-                                       putchar('"');
+                                       ND_PRINT((ndo, "\""));
                                        goto trunc;
                                }
-                               putchar('"');
+                               ND_PRINT((ndo, "\""));
                                bp += len - 3;
                                len = 0;
                                break;
@@ -638,12 +638,12 @@ rfc1048_print(netdissect_options *ndo,
                                type = *bp++;
                                len--;
                                if (type == 0) {
-                                       putchar('"');
+                                       ND_PRINT((ndo, "\""));
                                        if (fn_printn(bp, len, ndo->ndo_snapend)) {
-                                               putchar('"');
+                                               ND_PRINT((ndo, "\""));
                                                goto trunc;
                                        }
-                                       putchar('"');
+                                       ND_PRINT((ndo, "\""));
                                        bp += len;
                                        len = 0;
                                        break;
@@ -651,7 +651,7 @@ rfc1048_print(netdissect_options *ndo,
                                        ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type)));
                                        while (len > 0) {
                                                if (!first)
-                                                       putchar(':');
+                                                       ND_PRINT((ndo, ":"));
                                                ND_PRINT((ndo, "%02x", *bp));
                                                ++bp;
                                                --len;
@@ -711,7 +711,7 @@ rfc1048_print(netdissect_options *ndo,
                                }
                                while (len > 0) {
                                        if (!first)
-                                               putchar(',');
+                                               ND_PRINT((ndo, ","));
                                        mask_width = *bp++;
                                        len--;
                                        /* mask_width <= 32 */
@@ -729,13 +729,13 @@ rfc1048_print(netdissect_options *ndo,
                                                len = 0;
                                                break;
                                        }
-                                       putchar('(');
+                                       ND_PRINT((ndo, "("));
                                        if (mask_width == 0)
                                                ND_PRINT((ndo, "default"));
                                        else {
                                                for (i = 0; i < significant_octets ; i++) {
                                                        if (i > 0)
-                                                               putchar('.');
+                                                               ND_PRINT((ndo, "."));
                                                        ND_PRINT((ndo, "%d", *bp++));
                                                }
                                                for (i = significant_octets ; i < 4 ; i++)
@@ -799,7 +799,7 @@ cmu_print(netdissect_options *ndo,
        return;
 
 trunc:
-       fputs(tstr, stdout);
+       ND_PRINT((ndo, tstr));
 #undef PRINTCMUADDR
 }
 
index 07163e3835dd612805e5f384ea180daecd0c254b..e9b246b01a1ec7960fa1330cef37de48ac0d30f6 100644 (file)
@@ -312,7 +312,6 @@ void dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2,
                             ipaddr_string(&ip->ip_src), sport,
                             ipaddr_string(&ip->ip_dst), dport));
        }
-       fflush(stdout);
 
        if (ndo->ndo_qflag) {
                ND_PRINT((ndo, " %d", len - hlen));
index 70c0e15c158697f23317ede4bcc0160f05e7f4e9..28b304510c75972f4a0f21440bcc0ed9f74d6ade 100644 (file)
@@ -606,7 +606,7 @@ dhcp6opt_print(netdissect_options *ndo,
                case DH6OPT_DOMAIN_LIST:
                        tp = (u_char *)(dh6o + 1);
                        while (tp < cp + sizeof(*dh6o) + optlen) {
-                               putchar(' ');
+                               ND_PRINT((ndo, " "));
                                if ((tp = ns_nprint(ndo, tp, cp + sizeof(*dh6o) + optlen)) == NULL)
                                        goto trunc;
                        }
@@ -759,7 +759,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                        ND_PRINT((ndo, " %s", ip6addr_string(&tp[0])));
                                        break;
                                case DH6OPT_NTP_SUBOPTION_SRV_FQDN:
-                                       putchar(' ');
+                                       ND_PRINT((ndo, " "));
                                        if (ns_nprint(ndo, tp, tp + subopt_len) == NULL)
                                                goto trunc;
                                        break;
index 5e000ae1c141dec578857d741305f7fd51627748..78f3253bb7c8a055d4194d91ab26e049fb848410 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <string.h>
-
 #include <tcpdump-stdinc.h>
 
+#include <string.h>
 #include <stdlib.h>
 
 /* Any code in this file that depends on HAVE_LIBCRYPTO depends on
 #endif
 #endif
 
-#include <stdio.h>
-
 #include "ip.h"
 #ifdef INET6
 #include "ip6.h"
 #endif
 
-#include "netdissect.h"
+#include "interface.h"
 #include "extract.h"
 
 /*
index 231c072842b343cea7b115de5bf4db4bf176c2b8..09b9babab6ba01eb5578f7faa66bc1cdb071e37f 100644 (file)
@@ -93,26 +93,26 @@ ether_hdr_print(netdissect_options *ndo,
 
        ep = (const struct ether_header *)bp;
 
-       (void)ND_PRINT((ndo, "%s > %s",
+       ND_PRINT((ndo, "%s > %s",
                     etheraddr_string(ESRC(ep)),
                     etheraddr_string(EDST(ep))));
 
        ether_type = EXTRACT_16BITS(&ep->ether_type);
        if (!ndo->ndo_qflag) {
                if (ether_type <= ETHERMTU)
-                         (void)ND_PRINT((ndo, ", 802.3"));
+                         ND_PRINT((ndo, ", 802.3"));
                 else
-                         (void)ND_PRINT((ndo, ", ethertype %s (0x%04x)",
+                         ND_PRINT((ndo, ", ethertype %s (0x%04x)",
                                       tok2str(ethertype_values,"Unknown", ether_type),
                                        ether_type));
         } else {
                 if (ether_type <= ETHERMTU)
-                          (void)ND_PRINT((ndo, ", 802.3"));
+                          ND_PRINT((ndo, ", 802.3"));
                 else
-                          (void)ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
+                          ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
         }
 
-       (void)ND_PRINT((ndo, ", length %u: ", length));
+       ND_PRINT((ndo, ", length %u: ", length));
 }
 
 /*
@@ -341,7 +341,7 @@ ethertype_print(netdissect_options *ndo,
 
        case ETHERTYPE_ATALK:
                if (ndo->ndo_vflag)
-                       fputs("et1 ", stdout);
+                       ND_PRINT((ndo, "et1 "));
                atalk_print(/*ndo,*/p, length);
                return (1);
 
index e680c01c5f5d57828b80e219e140cd5629641b2b..c22d92b8b778e29cbcf5ddfc5989f523555ea65f 100644 (file)
@@ -688,7 +688,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
 
        return;
 trunc:
-       fputs("[|icmp]", stdout);
+       ND_PRINT((ndo, "[|icmp]"));
 }
 /*
  * Local Variables:
index 9024225c8fb2b05ad5a6f72bb5012a69fbacf3b7..7b5f3f3c2de6511677f9d7b702eacab95ee37b2b 100644 (file)
@@ -909,11 +909,11 @@ icmp6_print(netdissect_options *ndo,
                        udp_sum = EXTRACT_16BITS(&dp->icmp6_cksum);
                        sum = icmp6_cksum(ip, dp, length);
                        if (sum != 0)
-                               (void)ND_PRINT((ndo,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
+                               ND_PRINT((ndo,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
                                                 udp_sum,
                                                 in_cksum_shouldbe(udp_sum, sum)));
                        else
-                          (void)ND_PRINT((ndo,"[icmp6 sum ok] "));
+                               ND_PRINT((ndo,"[icmp6 sum ok] "));
                }
        }
 
@@ -1456,13 +1456,13 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
                     ND_PRINT((ndo,", %d source(s)", nsrcs));
             else {
                /* Print the sources */
-                    (void)ND_PRINT((ndo," {"));
+                    ND_PRINT((ndo," {"));
                 for (j = 0; j < nsrcs; j++) {
                     ND_TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
                             sizeof(struct in6_addr));
                    ND_PRINT((ndo," %s", ip6addr_string(&bp[group + 20 + j * sizeof(struct in6_addr)])));
                }
-                (void)ND_PRINT((ndo," }"));
+                ND_PRINT((ndo," }"));
             }
            /* Next group record */
             group += 20 + nsrcs * sizeof(struct in6_addr);
@@ -1471,7 +1471,7 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
     }
     return;
 trunc:
-    (void)ND_PRINT((ndo,"[|icmp6]"));
+    ND_PRINT((ndo,"[|icmp6]"));
     return;
 }
 
@@ -1497,7 +1497,7 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
         mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
     }
     if (ndo->ndo_vflag) {
-            (void)ND_PRINT((ndo," [max resp delay=%d]", mrt));
+            ND_PRINT((ndo," [max resp delay=%d]", mrt));
     }
     ND_TCHECK2(bp[8], sizeof(struct in6_addr));
     ND_PRINT((ndo," [gaddr %s", ip6addr_string(&bp[8])));
@@ -1537,7 +1537,7 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
     ND_PRINT((ndo,"]"));
     return;
 trunc:
-    (void)ND_PRINT((ndo,"[|icmp6]"));
+    ND_PRINT((ndo,"[|icmp6]"));
     return;
 }
 
index f341d7ee9977518f9515ee0420713d347a7118e8..dbebc4fbbc1c4cd1d12839c4b97844cde1852e51 100644 (file)
@@ -88,7 +88,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
        ND_TCHECK(*ip6);
        if (length < sizeof (struct ip6_hdr)) {
-               (void)ND_PRINT((ndo, "truncated-ip6 %u", length));
+               ND_PRINT((ndo, "truncated-ip6 %u", length));
                return;
        }
 
@@ -103,7 +103,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
        payload_len = EXTRACT_16BITS(&ip6->ip6_plen);
        len = payload_len + sizeof(struct ip6_hdr);
        if (length < len)
-               (void)ND_PRINT((ndo, "truncated-ip6 - %u bytes missing!",
+               ND_PRINT((ndo, "truncated-ip6 - %u bytes missing!",
                        len - length));
 
         if (ndo->ndo_vflag) {
@@ -112,18 +112,18 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
 #if 0
             /* rfc1883 */
             if (flow & 0x0f000000)
-               (void)ND_PRINT((ndo, "pri 0x%02x, ", (flow & 0x0f000000) >> 24));
+               ND_PRINT((ndo, "pri 0x%02x, ", (flow & 0x0f000000) >> 24));
             if (flow & 0x00ffffff)
-               (void)ND_PRINT((ndo, "flowlabel 0x%06x, ", flow & 0x00ffffff));
+               ND_PRINT((ndo, "flowlabel 0x%06x, ", flow & 0x00ffffff));
 #else
             /* RFC 2460 */
             if (flow & 0x0ff00000)
-               (void)ND_PRINT((ndo, "class 0x%02x, ", (flow & 0x0ff00000) >> 20));
+               ND_PRINT((ndo, "class 0x%02x, ", (flow & 0x0ff00000) >> 20));
             if (flow & 0x000fffff)
-               (void)ND_PRINT((ndo, "flowlabel 0x%05x, ", flow & 0x000fffff));
+               ND_PRINT((ndo, "flowlabel 0x%05x, ", flow & 0x000fffff));
 #endif
 
-            (void)ND_PRINT((ndo, "hlim %u, next-header %s (%u) payload length: %u) ",
+            ND_PRINT((ndo, "hlim %u, next-header %s (%u) payload length: %u) ",
                          ip6->ip6_hlim,
                          tok2str(ipproto_values,"unknown",ip6->ip6_nxt),
                          ip6->ip6_nxt,
@@ -147,7 +147,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                if (cp == (const u_char *)(ip6 + 1) &&
                    nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
                    nh != IPPROTO_DCCP && nh != IPPROTO_SCTP) {
-                       (void)ND_PRINT((ndo, "%s > %s: ", ip6addr_string(&ip6->ip6_src),
+                       ND_PRINT((ndo, "%s > %s: ", ip6addr_string(&ip6->ip6_src),
                                     ip6addr_string(&ip6->ip6_dst)));
                }
 
@@ -252,18 +252,18 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        return;
 
                case IPPROTO_NONE:
-                       (void)ND_PRINT((ndo, "no next header"));
+                       ND_PRINT((ndo, "no next header"));
                        return;
 
                default:
-                       (void)ND_PRINT((ndo, "ip-proto-%d %d", nh, len));
+                       ND_PRINT((ndo, "ip-proto-%d %d", nh, len));
                        return;
                }
        }
 
        return;
 trunc:
-       (void)ND_PRINT((ndo, "[|ip6]"));
+       ND_PRINT((ndo, "[|ip6]"));
 }
 
 #endif /* INET6 */
index e6493842b94774e0a9ad2be0340221bb3cfaa790..835fe4117a01cf15ec304a616f852eee29f52e6a 100644 (file)
@@ -186,7 +186,7 @@ hbhopt_print(netdissect_options *ndo, register const u_char *bp)
     return(hbhlen);
 
   trunc:
-    fputs("[|HBH]", stdout);
+    ND_PRINT((ndo, "[|HBH]"));
     return(-1);
 }
 
@@ -208,7 +208,7 @@ dstopt_print(netdissect_options *ndo, register const u_char *bp)
     return(dstoptlen);
 
   trunc:
-    fputs("[|DSTOPT]", stdout);
+    ND_PRINT((ndo, "[|DSTOPT]"));
     return(-1);
 }
 #endif /* INET6 */
index 97653efd6d52078bd4c1bdb9898edfe005391dc9..c8d919e148ee82c3f05cb8999b2a284a0d7df4cd 100644 (file)
@@ -68,7 +68,7 @@ static const struct tok lecop2str[] = {
 static void
 lane_hdr_print(netdissect_options *ndo, const u_char *bp)
 {
-       (void)ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
+       ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
 }
 
 /*