diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/uptime/uptime_bsd.c | |
Add the files
Diffstat (limited to 'src/detection/uptime/uptime_bsd.c')
| -rw-r--r-- | src/detection/uptime/uptime_bsd.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/detection/uptime/uptime_bsd.c b/src/detection/uptime/uptime_bsd.c new file mode 100644 index 0000000..46943b0 --- /dev/null +++ b/src/detection/uptime/uptime_bsd.c @@ -0,0 +1,27 @@ +#include "uptime.h" +#include "common/time.h" + +#include <sys/sysctl.h> +#include <sys/time.h> + +const char* ffDetectUptime(FFUptimeResult* result) { +#if __NetBSD__ + struct timespec bootTime; +#else + struct timeval bootTime; +#endif + size_t bootTimeSize = sizeof(bootTime); + if (sysctl( + (int[]) { CTL_KERN, KERN_BOOTTIME }, 2, &bootTime, &bootTimeSize, NULL, 0) != 0) { + return "sysctl({CTL_KERN, KERN_BOOTTIME}) failed"; + } + +#if __NetBSD__ + result->bootTime = (uint64_t) bootTime.tv_sec * 1000 + (uint64_t) bootTime.tv_nsec / 1000000; +#else + result->bootTime = (uint64_t) bootTime.tv_sec * 1000 + (uint64_t) bootTime.tv_usec / 1000; +#endif + result->uptime = ffTimeGetNow() - result->bootTime; + + return NULL; +} |