Skip to content

libwifi_get_epoch returns wrong timestamp #23

@solsticedhiver

Description

@solsticedhiver

If I am not wrong, there is an error in the formula used by libwifi_get_epoch() in src/libwifi/core/misc/epoch.c

It shoould be instead

spec.tv_sec * 1000 + spec.tv_nsec / 1000000

to return value in milliseconds.

Because the actual formula mixes milliseconds in the first half, and microsecond in the second half.

The result is that the timestamp returned is erratic, and when coorect, jumps several minutes in the future, and back to present and so on.

You can check that by using the patch below:

--- utils/src/test_generation.c	2023-07-22 05:07:29.000000000 +0200
+++ utils/src/test_generation.c.new	2024-11-02 00:30:03.757922709 +0100
@@ -12,6 +12,8 @@
 #include <string.h>
 #include <sys/time.h>
 #include <unistd.h>
+#include <math.h>
+#include <time.h>
 
 #include "helpers.h"
 
@@ -168,6 +170,11 @@
             printf("\tSource: " MACSTR "\n", MAC2STR(txmac));
             printf("\tDestination: " MACSTR "\n", MAC2STR(bcast));
 
+            time_t t = floor(beacon.fixed_parameters.timestamp/1000);
+            struct tm *tm = localtime(&t);
+            char buffer[20];
+            strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm);
+            printf("\tTimeStamp (localtime): %s\n", buffer);
             libwifi_dump_beacon(&beacon, buf, buf_sz);
             inject_frame(buf, buf_sz);

and run ./test_generation --file beacon.pcap --beacon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions