Organize code.

This commit is contained in:
Christian Deacon
2025-03-01 12:59:38 -05:00
parent a410e928f2
commit bfbc1a7554
3 changed files with 16 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ const struct option opts[] =
{ "verbose", required_argument, NULL, 'v' },
{ "log-file", required_argument, NULL, 0 },
{ "interface", required_argument, NULL, 'i' },
{ "pin-maps", required_argument, NULL, 'p' },
{ "update-time", required_argument, NULL, 'u' },
{ "no-stats", required_argument, NULL, 'n' },
{ "stats-ps", required_argument, NULL, 1 },
@@ -31,7 +32,7 @@ void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[])
{
int c;
while ((c = getopt_long(argc, argv, "c:ost:lhv:i:u:n:", opts, NULL)) != -1)
while ((c = getopt_long(argc, argv, "c:ost:lhv:i:p:u:n:", opts, NULL)) != -1)
{
switch (c)
{
@@ -80,6 +81,11 @@ void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[])
break;
case 'p':
cmd->pin_maps = atoi(optarg);
break;
case 'u':
cmd->update_time = atoi(optarg);

View File

@@ -113,7 +113,7 @@ void PrintToolInfo()
/**
* Retrieves nanoseconds since system boot.
*
* @return The current nanoseconds since the system started.
* @return The current nanoseconds since the system last booted.
*/
u64 GetBootNanoTime()
{

View File

@@ -157,6 +157,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
printf("Using 'map_range_drop' FD => %d.\n", map_range_drop);
// Parse IP range.
ip_range_t range = ParseIpCidr(cmd.ip);
@@ -168,7 +170,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
printf("Removed IP range '%s' from BPF map.\n", cmd.ip);
printf("Removed IP range '%s'...\n", cmd.ip);
if (cmd.save)
{
@@ -216,6 +218,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
printf("Using 'map_block6' FD => %d.\n", map_block6);
struct in6_addr addr;
if ((ret = inet_pton(AF_INET6, cmd.ip, &addr)) != 1)
@@ -248,6 +252,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
printf("Using 'map_block' FD => %d.\n", map_block);
struct in_addr addr;
if ((ret = inet_pton(AF_INET, cmd.ip, &addr)) != 1)
@@ -264,7 +270,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
printf("Deleted '%s' from block map...\n", cmd.ip);
printf("Deleted IP '%s'...\n", cmd.ip);
}
}