]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix plurals in packet count messages.
authorGuy Harris <[email protected]>
Tue, 8 Mar 2011 17:11:25 +0000 (09:11 -0800)
committerGuy Harris <[email protected]>
Tue, 8 Mar 2011 17:11:25 +0000 (09:11 -0800)
Based on a patch from [email protected], but with a macro
PLURAL_SUFFIX() defined to return either "s" or "" (rather than possibly
printing a NUL character with %c), and with that macro used in a couple
of cases where the equivalent had been done by hand, and with one case
the patch missed fixed as well.

netdissect.h
print-cdp.c
print-ospf.c
tcpdump.c

index 7d03b4c6e5f8e18d2869c457668fbf63824664bc..8bed55fcd6654fbedb92b53d189368c14a1803d5 100644 (file)
@@ -254,6 +254,9 @@ extern char *copy_argv(netdissect_options *, char **);
 extern void safeputchar(int);
 extern void safeputs(const char *, int);
 
+#define PLURAL_SUFFIX(n) \
+       (((n) != 1) ? "s" : "")
+
 #if 0
 extern const char *isonsap_string(netdissect_options *, const u_char *);
 extern const char *protoid_string(netdissect_options *, const u_char *);
index bef7f5eacadd701be847be9c2c5a6ff08d4289b6..7bc617a963570222e8a7c53932e06ef554290c68 100644 (file)
@@ -124,7 +124,7 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen)
                                tok2str(cdp_tlv_values,"unknown field type", type),
                                type,
                                len,
-                               len>1 ? "s" : ""); /* plural */
+                               PLURAL_SUFFIX(len)); /* plural */
 
                     switch (type) {
 
index 983c14f40e12d763dbf95d08ee439fb0b1556a7d..738a13c279244a45ed3c2e21903681555cfe98cf 100644 (file)
@@ -1028,7 +1028,7 @@ ospf_decode_v2(register const struct ospfhdr *op,
                 lsap = op->ospf_lsu.lsu_lsa;
                 TCHECK(op->ospf_lsu.lsu_count);
                 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
-                printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : "");
+                printf(", %d LSA%s",lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
                 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
                     printf("\n\t  LSA #%u",lsa_count);
                         lsap = (const struct lsa *)ospf_print_lsa(lsap);
index 19318047f33f0c3169f850a2df10515e50f0329d..5300d92024c51abf237f5e40a6d30b10efec6eda 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1493,24 +1493,27 @@ info(register int verbose)
        if (!verbose)
                fprintf(stderr, "%s: ", program_name);
 
-       (void)fprintf(stderr, "%u packets captured", packets_captured);
+       (void)fprintf(stderr, "%u packet%s captured", packets_captured,
+           PLURAL_SUFFIX(packets_captured));
        if (!verbose)
                fputs(", ", stderr);
        else
                putc('\n', stderr);
-       (void)fprintf(stderr, "%u packets received by filter", stat.ps_recv);
+       (void)fprintf(stderr, "%u packet%s received by filter", stat.ps_recv,
+           PLURAL_SUFFIX(stat.ps_recv));
        if (!verbose)
                fputs(", ", stderr);
        else
                putc('\n', stderr);
-       (void)fprintf(stderr, "%u packets dropped by kernel", stat.ps_drop);
+       (void)fprintf(stderr, "%u packet%s dropped by kernel", stat.ps_drop,
+           PLURAL_SUFFIX(stat.ps_drop));
        if (stat.ps_ifdrop != 0) {
                if (!verbose)
                        fputs(", ", stderr);
                else
                        putc('\n', stderr);
-               (void)fprintf(stderr, "%u packets dropped by interface\n",
-                   stat.ps_ifdrop);
+               (void)fprintf(stderr, "%u packet%s dropped by interface\n",
+                   stat.ps_ifdrop, PLURAL_SUFFIX(stat.ps_ifdrop));
        } else
                putc('\n', stderr);
        infoprint = 0;