]> The Tcpdump Group git mirrors - tcpdump/commitdiff
optional unit suffix on -C
authorSteve Kay <[email protected]>
Sat, 8 May 2021 18:32:24 +0000 (14:32 -0400)
committerfxlb <[email protected]>
Fri, 28 Mar 2025 14:44:07 +0000 (14:44 +0000)
(cherry picked from commit 81e2588d2ba6290cc189923287f1c042275a0bc5)

tcpdump.1.in
tcpdump.c

index 6ebc27047b72c166b1176d507d9ffd052970880f..82983e63b84127eb2c579e45ecb22dee9488f058 100644 (file)
@@ -271,8 +271,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 05b319b757a9c011bf2b8839f6455da64aacfe31..17f6487039464e0808e90ea3e77a43b493981635 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1522,6 +1522,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;
@@ -1756,6 +1757,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
@@ -1765,15 +1778,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':