]> The Tcpdump Group git mirrors - tcpdump/commitdiff
optional unit suffix on -C 916/head
authorSteve Kay <[email protected]>
Sat, 8 May 2021 18:32:24 +0000 (14:32 -0400)
committerSteve Kay <[email protected]>
Sat, 8 May 2021 18:32:24 +0000 (14:32 -0400)
tcpdump.1.in
tcpdump.c

index 355216d68d0f9782c7bde08488700a599a42d3c5..a6c00307356911abb09189e16d4173839bfc6afd 100644 (file)
@@ -265,8 +265,12 @@ savefile and open a new one.  Savefiles after the first savefile will
 have the name specified with the
 .B \-w
 flag, with a number after it, starting at 1 and continuing upward.
-The units of \fIfile_size\fP are millions of bytes (1,000,000 bytes,
+The default unit of \fIfile_size\fP is millions of bytes (1,000,000 bytes,
 not 1,048,576 bytes).
+.IP
+By adding a suffix of k, m or g to the value, the unit
+can be changed to 1,024 (KiB), 1,048,576 (MiB), or 1,073,741,824 (GiB)
+respectively.
 .TP
 .B \-d
 Dump the compiled packet-matching code in a human readable form to
index 0bde64682edd31e3d966626ad92f8c01922bf2ed..b9c02c1da7f75e64993d2447023a3c015054b13c 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1482,6 +1482,7 @@ main(int argc, char **argv)
        int yflag_dlt = -1;
        const char *yflag_dlt_name = NULL;
        int print = 0;
+       long Cflagmult = 1000000;
 
        netdissect_options Ndo;
        netdissect_options *ndo = &Ndo;
@@ -1558,6 +1559,18 @@ main(int argc, char **argv)
 
                case 'C':
                        errno = 0;
+                       if (optarg[strlen(optarg)-1] == 'k') {
+                               Cflagmult = 1024;
+                               optarg[strlen(optarg)-1] = '\0';
+                       }
+                       if (optarg[strlen(optarg)-1] == 'm') {
+                               Cflagmult = 1024*1024;
+                               optarg[strlen(optarg)-1] = '\0';
+                       }
+                       if (optarg[strlen(optarg)-1] == 'g') {
+                               Cflagmult = 1024*1024*1024;
+                               optarg[strlen(optarg)-1] = '\0';
+                       }
 #ifdef HAVE_PCAP_DUMP_FTELL64
                        Cflag = strtoint64_t(optarg, &endp, 10);
 #else
@@ -1567,15 +1580,15 @@ main(int argc, char **argv)
                            || Cflag <= 0)
                                error("invalid file size %s", optarg);
                        /*
-                        * Will multiplying it by 1000000 overflow?
+                        * Will multiplying it by multiplier overflow?
                         */
 #ifdef HAVE_PCAP_DUMP_FTELL64
-                       if (Cflag > INT64_T_CONSTANT(0x7fffffffffffffff) / 1000000)
+                       if (Cflag > INT64_T_CONSTANT(0x7fffffffffffffff) / Cflagmult)
 #else
-                       if (Cflag > LONG_MAX / 1000000)
+                       if (Cflag > LONG_MAX / Cflagmult)
 #endif
                                error("file size %s is too large", optarg);
-                       Cflag *= 1000000;
+                       Cflag *= Cflagmult;
                        break;
 
                case 'd':