Update and add helper functions.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user