mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 08:16:59 +00:00
fix improve variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
49835cccb5
commit
f5cd7383e4
5 changed files with 48 additions and 52 deletions
|
|
@ -100,7 +100,7 @@ int main(int argc, char **argv)
|
||||||
int i;
|
int i;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
char const *tmp;
|
char const *tmp;
|
||||||
char *output_format_tmp;
|
char *print_mac_addreses_tmp;
|
||||||
struct range_t *tmp_ranges;
|
struct range_t *tmp_ranges;
|
||||||
enum {
|
enum {
|
||||||
OPT_SNET_ALARMS = CHAR_MAX + 1,
|
OPT_SNET_ALARMS = CHAR_MAX + 1,
|
||||||
|
|
@ -155,7 +155,7 @@ int main(int argc, char **argv)
|
||||||
tmp++;
|
tmp++;
|
||||||
config.number_limit = (*tmp - '0');
|
config.number_limit = (*tmp - '0');
|
||||||
/* Make sure some output format is selected by default */
|
/* Make sure some output format is selected by default */
|
||||||
output_format_tmp = OUTPUT_FORMAT;
|
print_mac_addreses_tmp = OUTPUT_FORMAT;
|
||||||
/* Default sort order is by IPs small to big */
|
/* Default sort order is by IPs small to big */
|
||||||
config.reverse_order = false;
|
config.reverse_order = false;
|
||||||
config.backups_found = false;
|
config.backups_found = false;
|
||||||
|
|
@ -178,7 +178,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
/* Output format */
|
/* Output format */
|
||||||
output_format_tmp = optarg;
|
print_mac_addreses_tmp = optarg;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
|
|
@ -216,19 +216,19 @@ int main(int argc, char **argv)
|
||||||
config.snet_alarms = true;
|
config.snet_alarms = true;
|
||||||
break;
|
break;
|
||||||
case OPT_WARN:
|
case OPT_WARN:
|
||||||
output_format_tmp = "a";
|
print_mac_addreses_tmp = "a";
|
||||||
config.warning = strtod_or_err(optarg, "illegal argument");
|
config.warning = strtod_or_err(optarg, "illegal argument");
|
||||||
break;
|
break;
|
||||||
case OPT_CRIT:
|
case OPT_CRIT:
|
||||||
output_format_tmp = "a";
|
print_mac_addreses_tmp = "a";
|
||||||
config.critical = strtod_or_err(optarg, "illegal argument");
|
config.critical = strtod_or_err(optarg, "illegal argument");
|
||||||
break;
|
break;
|
||||||
case OPT_WARN_COUNT:
|
case OPT_WARN_COUNT:
|
||||||
output_format_tmp = "a";
|
print_mac_addreses_tmp = "a";
|
||||||
config.warn_count = strtod_or_err(optarg, "illegal argument");
|
config.warn_count = strtod_or_err(optarg, "illegal argument");
|
||||||
break;
|
break;
|
||||||
case OPT_CRIT_COUNT:
|
case OPT_CRIT_COUNT:
|
||||||
output_format_tmp = "a";
|
print_mac_addreses_tmp = "a";
|
||||||
config.crit_count = strtod_or_err(optarg, "illegal argument");
|
config.crit_count = strtod_or_err(optarg, "illegal argument");
|
||||||
break;
|
break;
|
||||||
case OPT_MINSIZE:
|
case OPT_MINSIZE:
|
||||||
|
|
@ -246,48 +246,48 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Output function selection */
|
/* Output function selection */
|
||||||
switch (output_format_tmp[0]) {
|
switch (print_mac_addreses_tmp[0]) {
|
||||||
case 't':
|
case 't':
|
||||||
output_analysis = output_txt;
|
output_analysis = output_txt;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
output_analysis = output_alarming;
|
output_analysis = output_alarming;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
error(EXIT_FAILURE, 0, "html table only output format is deprecated");
|
error(EXIT_FAILURE, 0, "html table only output format is deprecated");
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
output_analysis = output_html;
|
output_analysis = output_html;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
output_analysis = output_xml;
|
output_analysis = output_xml;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
output_analysis = output_xml;
|
output_analysis = output_xml;
|
||||||
config.output_format = OUTPUT_ETHERNETS;
|
config.print_mac_addreses = 1;
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
output_analysis = output_json;
|
output_analysis = output_json;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
case 'J':
|
case 'J':
|
||||||
output_analysis = output_json;
|
output_analysis = output_json;
|
||||||
config.output_format = OUTPUT_ETHERNETS;
|
config.print_mac_addreses = 1;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
output_analysis = output_csv;
|
output_analysis = output_csv;
|
||||||
config.output_format = OUTPUT_SHORT;
|
config.print_mac_addreses = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
clean_up();
|
clean_up();
|
||||||
error(EXIT_FAILURE, 0, "main: unknown output format '%c'", output_format_tmp[0]);
|
error(EXIT_FAILURE, 0, "main: unknown output format '%c'", print_mac_addreses_tmp[0]);
|
||||||
}
|
}
|
||||||
/* Do the job */
|
/* Do the job */
|
||||||
set_ipv_functions(VERSION_UNKNOWN);
|
set_ipv_functions(IPvUNKNOWN);
|
||||||
parse_config(true, config.dhcpdconf_file, shared_networks);
|
parse_config(true, config.dhcpdconf_file, shared_networks);
|
||||||
parse_leases();
|
parse_leases();
|
||||||
prepare_data();
|
prepare_data();
|
||||||
|
|
@ -307,7 +307,7 @@ int main(int argc, char **argv)
|
||||||
* initializations, etc are here. */
|
* initializations, etc are here. */
|
||||||
void prepare_memory(void)
|
void prepare_memory(void)
|
||||||
{
|
{
|
||||||
config.dhcp_version = VERSION_UNKNOWN;
|
config.ip_version = IPvUNKNOWN;
|
||||||
RANGES = 64;
|
RANGES = 64;
|
||||||
num_ranges = num_shared_networks = 0;
|
num_ranges = num_shared_networks = 0;
|
||||||
shared_networks = xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
|
shared_networks = xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,12 @@ union ipaddr_t {
|
||||||
unsigned char v6[16];
|
unsigned char v6[16];
|
||||||
};
|
};
|
||||||
/*! \enum dhcp_version
|
/*! \enum dhcp_version
|
||||||
* \brief Indicator which IP version is in use.
|
* \brief The IP version, IPv4 or IPv6, served by the dhcpd.
|
||||||
*/
|
*/
|
||||||
enum dhcp_version {
|
enum dhcp_version {
|
||||||
VERSION_4,
|
IPvUNKNOWN,
|
||||||
VERSION_6,
|
IPv4,
|
||||||
VERSION_UNKNOWN
|
IPv6
|
||||||
};
|
};
|
||||||
/*! \enum prefix_t
|
/*! \enum prefix_t
|
||||||
* \brief Enumeration of interesting data in dhcpd.leases file, that has
|
* \brief Enumeration of interesting data in dhcpd.leases file, that has
|
||||||
|
|
@ -114,13 +114,6 @@ enum prefix_t {
|
||||||
PREFIX_HARDWARE_ETHERNET,
|
PREFIX_HARDWARE_ETHERNET,
|
||||||
NUM_OF_PREFIX
|
NUM_OF_PREFIX
|
||||||
};
|
};
|
||||||
/*! \enum dhcp_version
|
|
||||||
* \brief Indicator which IP version is in use.
|
|
||||||
*/
|
|
||||||
enum output_formats {
|
|
||||||
OUTPUT_SHORT,
|
|
||||||
OUTPUT_ETHERNETS
|
|
||||||
};
|
|
||||||
/*! \struct shared_network_t
|
/*! \struct shared_network_t
|
||||||
* \brief Counters for an individual shared network.
|
* \brief Counters for an individual shared network.
|
||||||
*/
|
*/
|
||||||
|
|
@ -173,18 +166,21 @@ struct leases_t {
|
||||||
* \brief Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all.
|
* \brief Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all.
|
||||||
*/
|
*/
|
||||||
enum limbits {
|
enum limbits {
|
||||||
R_BIT = 0x1,
|
R_BIT = (1 << 0),
|
||||||
S_BIT = 0x2,
|
S_BIT = (1 << 1),
|
||||||
A_BIT = 0x4
|
A_BIT = (1 << 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \def STATE_OK
|
/*! \def STATE_OK
|
||||||
* \brief Nagios alarm exit value.
|
* \brief Nagios alarm exit values.
|
||||||
*/
|
*/
|
||||||
# define STATE_OK 0
|
# define STATE_OK 0
|
||||||
# define STATE_WARNING 1
|
# define STATE_WARNING 1
|
||||||
# define STATE_CRITICAL 2
|
# define STATE_CRITICAL 2
|
||||||
|
|
||||||
|
/*! \var comparer_t
|
||||||
|
* \brief Function pointer holding sort algorithm.
|
||||||
|
*/
|
||||||
typedef int (*comparer_t) (struct range_t *r1, struct range_t *r2);
|
typedef int (*comparer_t) (struct range_t *r1, struct range_t *r2);
|
||||||
|
|
||||||
/*! \struct output_sort
|
/*! \struct output_sort
|
||||||
|
|
@ -199,7 +195,7 @@ struct output_sort {
|
||||||
*/
|
*/
|
||||||
struct configuration_t {
|
struct configuration_t {
|
||||||
char dhcpv6;
|
char dhcpv6;
|
||||||
enum dhcp_version dhcp_version;
|
enum dhcp_version ip_version;
|
||||||
char *dhcpdconf_file;
|
char *dhcpdconf_file;
|
||||||
char *dhcpdlease_file;
|
char *dhcpdlease_file;
|
||||||
struct output_sort *sorts;
|
struct output_sort *sorts;
|
||||||
|
|
@ -213,7 +209,7 @@ struct configuration_t {
|
||||||
reverse_order:1,
|
reverse_order:1,
|
||||||
backups_found:1,
|
backups_found:1,
|
||||||
snet_alarms:1,
|
snet_alarms:1,
|
||||||
output_format:1,
|
print_mac_addreses:1,
|
||||||
header_limit:3,
|
header_limit:3,
|
||||||
number_limit:3;
|
number_limit:3;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ int parse_leases(void)
|
||||||
line[0] = '\0';
|
line[0] = '\0';
|
||||||
ipstring = xmalloc(sizeof(char) * MAXLEN);
|
ipstring = xmalloc(sizeof(char) * MAXLEN);
|
||||||
ipstring[0] = '\0';
|
ipstring[0] = '\0';
|
||||||
if (config.output_format == OUTPUT_ETHERNETS)
|
if (config.print_mac_addreses == 1)
|
||||||
ethernets = true;
|
ethernets = true;
|
||||||
while (!feof(dhcpd_leases)) {
|
while (!feof(dhcpd_leases)) {
|
||||||
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases))
|
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases))
|
||||||
|
|
@ -102,8 +102,8 @@ int parse_leases(void)
|
||||||
case PREFIX_LEASE:
|
case PREFIX_LEASE:
|
||||||
stop =
|
stop =
|
||||||
memccpy(ipstring,
|
memccpy(ipstring,
|
||||||
line + (config.dhcp_version ==
|
line + (config.ip_version ==
|
||||||
VERSION_4 ? 6 : 9), ' ', strlen(line));
|
IPv4 ? 6 : 9), ' ', strlen(line));
|
||||||
if (stop != NULL) {
|
if (stop != NULL) {
|
||||||
--stop;
|
--stop;
|
||||||
*stop = '\0';
|
*stop = '\0';
|
||||||
|
|
|
||||||
20
src/other.c
20
src/other.c
|
|
@ -62,8 +62,8 @@ void set_ipv_functions(int version)
|
||||||
{
|
{
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
|
||||||
case VERSION_4:
|
case IPv4:
|
||||||
config.dhcp_version = version;
|
config.ip_version = version;
|
||||||
add_lease = add_lease_v4;
|
add_lease = add_lease_v4;
|
||||||
copy_ipaddr = copy_ipaddr_v4;
|
copy_ipaddr = copy_ipaddr_v4;
|
||||||
find_lease = find_lease_v4;
|
find_lease = find_lease_v4;
|
||||||
|
|
@ -75,8 +75,8 @@ void set_ipv_functions(int version)
|
||||||
xstrstr = xstrstr_v4;
|
xstrstr = xstrstr_v4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VERSION_6:
|
case IPv6:
|
||||||
config.dhcp_version = version;
|
config.ip_version = version;
|
||||||
add_lease = add_lease_v6;
|
add_lease = add_lease_v6;
|
||||||
copy_ipaddr = copy_ipaddr_v6;
|
copy_ipaddr = copy_ipaddr_v6;
|
||||||
find_lease = find_lease_v6;
|
find_lease = find_lease_v6;
|
||||||
|
|
@ -88,8 +88,8 @@ void set_ipv_functions(int version)
|
||||||
xstrstr = xstrstr_v6;
|
xstrstr = xstrstr_v6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VERSION_UNKNOWN:
|
case IPvUNKNOWN:
|
||||||
config.dhcp_version = version;
|
config.ip_version = version;
|
||||||
add_lease = add_lease_init;
|
add_lease = add_lease_init;
|
||||||
copy_ipaddr = copy_ipaddr_init;
|
copy_ipaddr = copy_ipaddr_init;
|
||||||
find_lease = find_lease_init;
|
find_lease = find_lease_init;
|
||||||
|
|
@ -119,9 +119,9 @@ int parse_ipaddr_init(const char *restrict src, union ipaddr_t *restrict dst)
|
||||||
struct in6_addr addr6;
|
struct in6_addr addr6;
|
||||||
|
|
||||||
if (inet_aton(src, &addr) == 1)
|
if (inet_aton(src, &addr) == 1)
|
||||||
set_ipv_functions(VERSION_4);
|
set_ipv_functions(IPv4);
|
||||||
else if (inet_pton(AF_INET6, src, &addr6) == 1)
|
else if (inet_pton(AF_INET6, src, &addr6) == 1)
|
||||||
set_ipv_functions(VERSION_6);
|
set_ipv_functions(IPv6);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
return parse_ipaddr(src, dst);
|
return parse_ipaddr(src, dst);
|
||||||
|
|
@ -244,10 +244,10 @@ int
|
||||||
xstrstr_init(const char *restrict str)
|
xstrstr_init(const char *restrict str)
|
||||||
{
|
{
|
||||||
if (memcmp("lease ", str, 6)) {
|
if (memcmp("lease ", str, 6)) {
|
||||||
set_ipv_functions(VERSION_4);
|
set_ipv_functions(IPv4);
|
||||||
return PREFIX_LEASE;
|
return PREFIX_LEASE;
|
||||||
} else if (memcmp(" iaaddr ", str, 9)) {
|
} else if (memcmp(" iaaddr ", str, 9)) {
|
||||||
set_ipv_functions(VERSION_6);
|
set_ipv_functions(IPv6);
|
||||||
return PREFIX_LEASE;
|
return PREFIX_LEASE;
|
||||||
}
|
}
|
||||||
return NUM_OF_PREFIX;
|
return NUM_OF_PREFIX;
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ int output_txt(void)
|
||||||
struct shared_network_t *shared_p;
|
struct shared_network_t *shared_p;
|
||||||
int ret;
|
int ret;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
int max_ipaddr_length = config.dhcp_version == VERSION_6 ? 39 : 16;
|
int max_ipaddr_length = config.ip_version == IPv6 ? 39 : 16;
|
||||||
|
|
||||||
if (config.output_file[0]) {
|
if (config.output_file[0]) {
|
||||||
outfile = fopen(config.output_file, "w+");
|
outfile = fopen(config.output_file, "w+");
|
||||||
|
|
@ -237,7 +237,7 @@ int output_xml(void)
|
||||||
|
|
||||||
fprintf(outfile, "<dhcpstatus>\n");
|
fprintf(outfile, "<dhcpstatus>\n");
|
||||||
|
|
||||||
if (config.output_format == OUTPUT_ETHERNETS) {
|
if (config.print_mac_addreses == 1) {
|
||||||
struct leases_t *l;
|
struct leases_t *l;
|
||||||
|
|
||||||
for (l = leases; l != NULL; l = l->hh.next) {
|
for (l = leases; l != NULL; l = l->hh.next) {
|
||||||
|
|
@ -342,7 +342,7 @@ int output_json(void)
|
||||||
|
|
||||||
fprintf(outfile, "{\n");
|
fprintf(outfile, "{\n");
|
||||||
|
|
||||||
if (config.output_format == OUTPUT_ETHERNETS) {
|
if (config.print_mac_addreses == 1) {
|
||||||
struct leases_t *l;
|
struct leases_t *l;
|
||||||
|
|
||||||
fprintf(outfile, " \"active_leases\": [");
|
fprintf(outfile, " \"active_leases\": [");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue