From: Steve Kay Date: Sat, 8 May 2021 18:32:24 +0000 (-0400) Subject: optional unit suffix on -C X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/81e2588d2ba6290cc189923287f1c042275a0bc5 optional unit suffix on -C --- diff --git a/tcpdump.1.in b/tcpdump.1.in index 355216d6..a6c00307 100644 --- a/tcpdump.1.in +++ b/tcpdump.1.in @@ -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 diff --git a/tcpdump.c b/tcpdump.c index 0bde6468..b9c02c1d 100644 --- 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':