Add typedefs and organize code.

This commit is contained in:
Christian Deacon
2025-02-22 10:24:21 -05:00
parent 1b9e805207
commit 09491e1462
12 changed files with 72 additions and 72 deletions

View File

@@ -22,7 +22,7 @@ const struct option opts[] =
*
* @return Void
*/
void ParseCommandLine(struct cmdline *cmd, int argc, char *argv[])
void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[])
{
int c;

View File

@@ -8,6 +8,6 @@ struct cmdline
unsigned int time;
unsigned int list : 1;
unsigned int help : 1;
};
} typedef cmdline_t;
void ParseCommandLine(struct cmdline *cmd, int argc, char *argv[]);
void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[]);

View File

@@ -11,7 +11,7 @@ FILE *file;
*
* @return Void
*/
void SetCfgDefaults(struct config *cfg)
void SetCfgDefaults(config__t *cfg)
{
cfg->updatetime = 0;
cfg->interface = NULL;
@@ -111,7 +111,7 @@ int OpenCfg(const char *filename)
*
* @return 0 on success or 1/-1 on error.
*/
int ReadCfg(struct config *cfg)
int ReadCfg(config__t *cfg)
{
// Not sure why this would be set to NULL after checking for it in OpenConfig(), but just for safety.
if (file == NULL)
@@ -225,7 +225,7 @@ int ReadCfg(struct config *cfg)
if (config_setting_lookup_string(filter, "src_ip", &sip))
{
struct ip ip = ParseIp(sip);
ip_range_t ip = ParseIpCidr(sip);
cfg->filters[i].src_ip = ip.ip;
cfg->filters[i].src_cidr = ip.cidr;
@@ -236,7 +236,7 @@ int ReadCfg(struct config *cfg)
if (config_setting_lookup_string(filter, "dst_ip", &dip))
{
struct ip ip = ParseIp(dip);
ip_range_t ip = ParseIpCidr(dip);
cfg->filters[i].dst_ip = ip.ip;
cfg->filters[i].dst_cidr = ip.cidr;

View File

@@ -16,9 +16,9 @@ struct config
u16 updatetime;
unsigned int nostats : 1;
int stdout_update_time;
struct filter filters[MAX_FILTERS];
};
filter_t filters[MAX_FILTERS];
} typedef config__t; // config_t is taken by libconfig -.-
void SetCfgDefaults(struct config *cfg);
void SetCfgDefaults(config__t *cfg);
int OpenCfg(const char *filename);
int ReadCfg(struct config *cfg);
int ReadCfg(config__t *cfg);

View File

@@ -7,9 +7,9 @@
*
* @return Returns an IP structure with IP and CIDR.
*/
struct ip ParseIp(const char *ip)
ip_range_t ParseIpCidr(const char *ip)
{
struct ip ret = {0};
ip_range_t ret = {0};
ret.cidr = 32;
char *token = strtok((char *) ip, "/");

View File

@@ -7,10 +7,10 @@
#include <stdio.h>
#include <stdlib.h>
struct ip
struct ip_range
{
u32 ip;
u32 cidr;
};
} typedef ip_range_t;
struct ip ParseIp(const char *ip);
ip_range_t ParseIpCidr(const char *ip);