Update and add helper functions.

This commit is contained in:
Christian Deacon
2025-03-01 10:38:10 -05:00
parent e392b7355b
commit f261cf7199
2 changed files with 22 additions and 2 deletions

View File

@@ -48,7 +48,11 @@ ip_range_t ParseIpCidr(const char *ip)
ip_range_t ret = {0};
ret.cidr = 32;
char *token = strtok((char *) ip, "/");
char ip_copy[INET_ADDRSTRLEN + 3];
strncpy(ip_copy, ip, sizeof(ip_copy) - 1);
ip_copy[sizeof(ip_copy) - 1] = '\0';
char *token = strtok((char *) ip_copy, "/");
if (token)
{
@@ -105,3 +109,16 @@ void PrintToolInfo()
"\n\n"
);
}
/**
* Retrieves nanoseconds since system boot.
*
* @return The current nanoseconds since the system started.
*/
u64 GetBootNanoTime()
{
struct sysinfo sys;
sysinfo(&sys);
return sys.uptime * 1e9;
}

View File

@@ -7,6 +7,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
struct ip_range
{
u32 ip;
@@ -20,3 +22,4 @@ void SignalHndl(int code);
ip_range_t ParseIpCidr(const char* ip);
const char* GetProtocolStrById(int id);
void PrintToolInfo();
u64 GetBootNanoTime();