]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add --time-t-size option to print the size of time_t in bits
authorFrancois-Xavier Le Bail <[email protected]>
Wed, 25 Sep 2024 11:47:06 +0000 (13:47 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 30 Sep 2024 13:22:38 +0000 (15:22 +0200)
Have tests/TESTrun run "./tcpdump --time-t-size and set HAVE_TIME_T_64
key based on that.

This will permit to run tests based on time_t size (32-bit or 64-bit).

(backported from commit aacc29d06ccccd15b6b07bba0858e6fa32e97edd)

tcpdump.c
tests/TESTrun

index a4cdbe076d42c2770ea2585b6f5ec202c31f4b45..faabe0bfd8452f038fdeecf24d2a0600d8b7380c 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -701,6 +701,7 @@ show_remote_devices_and_exit(void)
 #define OPTION_TSTAMP_NANO             134
 #define OPTION_FP_TYPE                 135
 #define OPTION_COUNT                   136
 #define OPTION_TSTAMP_NANO             134
 #define OPTION_FP_TYPE                 135
 #define OPTION_COUNT                   136
+#define OPTION_TIME_T_SIZE             139
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
@@ -748,6 +749,7 @@ static const struct option longopts[] = {
        { "fp-type", no_argument, NULL, OPTION_FP_TYPE },
        { "number", no_argument, NULL, '#' },
        { "print", no_argument, NULL, OPTION_PRINT },
        { "fp-type", no_argument, NULL, OPTION_FP_TYPE },
        { "number", no_argument, NULL, '#' },
        { "print", no_argument, NULL, OPTION_PRINT },
+       { "time-t-size", no_argument, NULL, OPTION_TIME_T_SIZE },
        { "version", no_argument, NULL, OPTION_VERSION },
        { NULL, 0, NULL, 0 }
 };
        { "version", no_argument, NULL, OPTION_VERSION },
        { NULL, 0, NULL, 0 }
 };
@@ -1914,6 +1916,10 @@ main(int argc, char **argv)
                        ndo->ndo_packet_number = 1;
                        break;
 
                        ndo->ndo_packet_number = 1;
                        break;
 
+               case OPTION_TIME_T_SIZE:
+                       printf("%zu\n", sizeof(time_t) * 8);
+                       return 0;
+
                case OPTION_VERSION:
                        print_version(stdout);
                        exit_tcpdump(S_SUCCESS);
                case OPTION_VERSION:
                        print_version(stdout);
                        exit_tcpdump(S_SUCCESS);
index 0a1a255ccc82991d7da1b80d7e0bb8afd5761024..bf95e46077e1e9e761a5ce79977f6bf61903571d 100755 (executable)
@@ -386,6 +386,17 @@ sub loadconfighash {
     printf "$TCPDUMP --fp-type => %s\n", $have_fptype;
     $main::confighhash->{$have_fptype} = 1;
 
     printf "$TCPDUMP --fp-type => %s\n", $have_fptype;
     $main::confighhash->{$have_fptype} = 1;
 
+    # run tcpdump --time-t-size to get the size of size_t in bits
+    open(TIMETSIZE_PIPE, "$TCPDUMP --time-t-size |") or die("piping tcpdump --time-t-size failed\n");
+    my $time_t_size = <TIMETSIZE_PIPE>;
+    close(TIMETSIZE_PIPE);
+    my $have_time_t_64;
+    if($time_t_size == "64") {
+        $have_time_t_64 = "HAVE_TIME_T_64";
+    }
+    printf "$TCPDUMP --time-t-size => %s\n", $time_t_size;
+    $main::confighhash->{$have_time_t_64} = 1;
+
     # and check whether this is OpenBSD, as one test fails in OpenBSD
     # due to the sad hellscape of low-numbered DLT_ values, due to
     # 12 meaning "OpenBSD loopback" rather than "raw IP" on OpenBSD
     # and check whether this is OpenBSD, as one test fails in OpenBSD
     # due to the sad hellscape of low-numbered DLT_ values, due to
     # 12 meaning "OpenBSD loopback" rather than "raw IP" on OpenBSD