From f5cd7383e41555d148cbcc736836c1b9c1e670c1 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 4 Dec 2015 19:32:50 +0000 Subject: [PATCH] fix improve variable names Signed-off-by: Sami Kerola --- src/dhcpd-pools.c | 38 +++++++++++++++++++------------------- src/dhcpd-pools.h | 30 +++++++++++++----------------- src/getdata.c | 6 +++--- src/other.c | 20 ++++++++++---------- src/output.c | 6 +++--- 5 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index fcf610a..46447e3 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) int i; int option_index = 0; char const *tmp; - char *output_format_tmp; + char *print_mac_addreses_tmp; struct range_t *tmp_ranges; enum { OPT_SNET_ALARMS = CHAR_MAX + 1, @@ -155,7 +155,7 @@ int main(int argc, char **argv) tmp++; config.number_limit = (*tmp - '0'); /* 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 */ config.reverse_order = false; config.backups_found = false; @@ -178,7 +178,7 @@ int main(int argc, char **argv) break; case 'f': /* Output format */ - output_format_tmp = optarg; + print_mac_addreses_tmp = optarg; break; case 's': { @@ -216,19 +216,19 @@ int main(int argc, char **argv) config.snet_alarms = true; break; case OPT_WARN: - output_format_tmp = "a"; + print_mac_addreses_tmp = "a"; config.warning = strtod_or_err(optarg, "illegal argument"); break; case OPT_CRIT: - output_format_tmp = "a"; + print_mac_addreses_tmp = "a"; config.critical = strtod_or_err(optarg, "illegal argument"); break; case OPT_WARN_COUNT: - output_format_tmp = "a"; + print_mac_addreses_tmp = "a"; config.warn_count = strtod_or_err(optarg, "illegal argument"); break; case OPT_CRIT_COUNT: - output_format_tmp = "a"; + print_mac_addreses_tmp = "a"; config.crit_count = strtod_or_err(optarg, "illegal argument"); break; case OPT_MINSIZE: @@ -246,48 +246,48 @@ int main(int argc, char **argv) } } /* Output function selection */ - switch (output_format_tmp[0]) { + switch (print_mac_addreses_tmp[0]) { case 't': output_analysis = output_txt; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; case 'a': output_analysis = output_alarming; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; case 'h': error(EXIT_FAILURE, 0, "html table only output format is deprecated"); break; case 'H': output_analysis = output_html; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; case 'x': output_analysis = output_xml; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; case 'X': output_analysis = output_xml; - config.output_format = OUTPUT_ETHERNETS; + config.print_mac_addreses = 1; break; case 'j': output_analysis = output_json; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; case 'J': output_analysis = output_json; - config.output_format = OUTPUT_ETHERNETS; + config.print_mac_addreses = 1; break; case 'c': output_analysis = output_csv; - config.output_format = OUTPUT_SHORT; + config.print_mac_addreses = 0; break; default: 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 */ - set_ipv_functions(VERSION_UNKNOWN); + set_ipv_functions(IPvUNKNOWN); parse_config(true, config.dhcpdconf_file, shared_networks); parse_leases(); prepare_data(); @@ -307,7 +307,7 @@ int main(int argc, char **argv) * initializations, etc are here. */ void prepare_memory(void) { - config.dhcp_version = VERSION_UNKNOWN; + config.ip_version = IPvUNKNOWN; RANGES = 64; num_ranges = num_shared_networks = 0; shared_networks = xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS); diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index f82a061..c20b72f 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -92,12 +92,12 @@ union ipaddr_t { unsigned char v6[16]; }; /*! \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 { - VERSION_4, - VERSION_6, - VERSION_UNKNOWN + IPvUNKNOWN, + IPv4, + IPv6 }; /*! \enum prefix_t * \brief Enumeration of interesting data in dhcpd.leases file, that has @@ -114,13 +114,6 @@ enum prefix_t { PREFIX_HARDWARE_ETHERNET, 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 * \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. */ enum limbits { - R_BIT = 0x1, - S_BIT = 0x2, - A_BIT = 0x4 + R_BIT = (1 << 0), + S_BIT = (1 << 1), + A_BIT = (1 << 2) }; /*! \def STATE_OK - * \brief Nagios alarm exit value. + * \brief Nagios alarm exit values. */ # define STATE_OK 0 # define STATE_WARNING 1 # 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); /*! \struct output_sort @@ -199,7 +195,7 @@ struct output_sort { */ struct configuration_t { char dhcpv6; - enum dhcp_version dhcp_version; + enum dhcp_version ip_version; char *dhcpdconf_file; char *dhcpdlease_file; struct output_sort *sorts; @@ -213,7 +209,7 @@ struct configuration_t { reverse_order:1, backups_found:1, snet_alarms:1, - output_format:1, + print_mac_addreses:1, header_limit:3, number_limit:3; }; diff --git a/src/getdata.c b/src/getdata.c index 6438b48..ba43cbe 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -92,7 +92,7 @@ int parse_leases(void) line[0] = '\0'; ipstring = xmalloc(sizeof(char) * MAXLEN); ipstring[0] = '\0'; - if (config.output_format == OUTPUT_ETHERNETS) + if (config.print_mac_addreses == 1) ethernets = true; while (!feof(dhcpd_leases)) { if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases)) @@ -102,8 +102,8 @@ int parse_leases(void) case PREFIX_LEASE: stop = memccpy(ipstring, - line + (config.dhcp_version == - VERSION_4 ? 6 : 9), ' ', strlen(line)); + line + (config.ip_version == + IPv4 ? 6 : 9), ' ', strlen(line)); if (stop != NULL) { --stop; *stop = '\0'; diff --git a/src/other.c b/src/other.c index 0226995..91cde58 100644 --- a/src/other.c +++ b/src/other.c @@ -62,8 +62,8 @@ void set_ipv_functions(int version) { switch (version) { - case VERSION_4: - config.dhcp_version = version; + case IPv4: + config.ip_version = version; add_lease = add_lease_v4; copy_ipaddr = copy_ipaddr_v4; find_lease = find_lease_v4; @@ -75,8 +75,8 @@ void set_ipv_functions(int version) xstrstr = xstrstr_v4; break; - case VERSION_6: - config.dhcp_version = version; + case IPv6: + config.ip_version = version; add_lease = add_lease_v6; copy_ipaddr = copy_ipaddr_v6; find_lease = find_lease_v6; @@ -88,8 +88,8 @@ void set_ipv_functions(int version) xstrstr = xstrstr_v6; break; - case VERSION_UNKNOWN: - config.dhcp_version = version; + case IPvUNKNOWN: + config.ip_version = version; add_lease = add_lease_init; copy_ipaddr = copy_ipaddr_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; if (inet_aton(src, &addr) == 1) - set_ipv_functions(VERSION_4); + set_ipv_functions(IPv4); else if (inet_pton(AF_INET6, src, &addr6) == 1) - set_ipv_functions(VERSION_6); + set_ipv_functions(IPv6); else return 0; return parse_ipaddr(src, dst); @@ -244,10 +244,10 @@ int xstrstr_init(const char *restrict str) { if (memcmp("lease ", str, 6)) { - set_ipv_functions(VERSION_4); + set_ipv_functions(IPv4); return PREFIX_LEASE; } else if (memcmp(" iaaddr ", str, 9)) { - set_ipv_functions(VERSION_6); + set_ipv_functions(IPv6); return PREFIX_LEASE; } return NUM_OF_PREFIX; diff --git a/src/output.c b/src/output.c index ef87910..2574d18 100644 --- a/src/output.c +++ b/src/output.c @@ -66,7 +66,7 @@ int output_txt(void) struct shared_network_t *shared_p; int ret; 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]) { outfile = fopen(config.output_file, "w+"); @@ -237,7 +237,7 @@ int output_xml(void) fprintf(outfile, "\n"); - if (config.output_format == OUTPUT_ETHERNETS) { + if (config.print_mac_addreses == 1) { struct leases_t *l; for (l = leases; l != NULL; l = l->hh.next) { @@ -342,7 +342,7 @@ int output_json(void) fprintf(outfile, "{\n"); - if (config.output_format == OUTPUT_ETHERNETS) { + if (config.print_mac_addreses == 1) { struct leases_t *l; fprintf(outfile, " \"active_leases\": [");