reindent all files

And update the indent.pro to match with the style I like.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2014-07-20 18:05:00 +01:00
parent 9090cfb1d7
commit 4392a5b917
10 changed files with 156 additions and 241 deletions

12
src/.indent.pro vendored
View file

@ -1,2 +1,10 @@
-linux -Tuintmax_t -TFILE -Tsize_t -Toff_t -Ttime_t -ppi1 -linux
-TFILE
-Tipaddr_t
-Toff_t
-Trange_t
-Tsize_t
-Ttime_t
-Tuintmax_t
-l100
-ppi1

View file

@ -69,13 +69,11 @@ int do_counting(void)
/* Walk through ranges */ /* Walk through ranges */
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
for (; l != NULL && ipcomp(&range_p->first_ip, &l->ip) < 0; for (; l != NULL && ipcomp(&range_p->first_ip, &l->ip) < 0; l = l->hh.prev)
l = l->hh.prev)
/* rewind */ ; /* rewind */ ;
if (l == NULL) if (l == NULL)
l = leases; l = leases;
for (; l != NULL && ipcomp(&l->ip, &range_p->last_ip) <= 0; for (; l != NULL && ipcomp(&l->ip, &range_p->last_ip) <= 0; l = l->hh.next) {
l = l->hh.next) {
if (ipcomp(&l->ip, &range_p->first_ip) < 0) { if (ipcomp(&l->ip, &range_p->first_ip) < 0) {
/* should not be necessary */ /* should not be necessary */
continue; continue;

View file

@ -41,7 +41,7 @@
#ifndef DEFAULTS_H #ifndef DEFAULTS_H
# define DEFAULTS_H 1 # define DEFAULTS_H 1
#include "dhcpd-pools.h" # include "dhcpd-pools.h"
/*! \var MAXLEN /*! \var MAXLEN
* \brief Maximum expected line length in dhcpd.conf and dhcpd.leases * \brief Maximum expected line length in dhcpd.conf and dhcpd.leases

View file

@ -129,8 +129,7 @@ int main(int argc, char **argv)
/* Parse command line options */ /* Parse command line options */
while (1) { while (1) {
int c; int c;
c = getopt_long(argc, argv, "c:l:f:o:s:rL:vh", c = getopt_long(argc, argv, "c:l:f:o:s:rL:vh", long_options, &option_index);
long_options, &option_index);
if (c == EOF) if (c == EOF)
break; break;
@ -152,8 +151,7 @@ int main(int argc, char **argv)
/* Output sorting option */ /* Output sorting option */
sorts = strlen(optarg); sorts = strlen(optarg);
if (5 < sorts) { if (5 < sorts) {
warnx warnx("main: only first 5 sort orders will be used");
("main: only first 5 sort orders will be used");
strncpy(config.sort, optarg, (size_t)5); strncpy(config.sort, optarg, (size_t)5);
sorts = 5; sorts = 5;
} else { } else {
@ -175,29 +173,24 @@ int main(int argc, char **argv)
/* Specification what will be printed */ /* Specification what will be printed */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (optarg[i] >= '0' && optarg[i] < '8') { if (optarg[i] >= '0' && optarg[i] < '8') {
config.output_limit[i] = config.output_limit[i] = optarg[i] - '0';
optarg[i] - '0';
} else { } else {
clean_up(); clean_up();
errx(EXIT_FAILURE, errx(EXIT_FAILURE,
"main: output mask `%s' is illegal", "main: output mask `%s' is illegal", optarg);
optarg);
} }
} }
break; break;
case OPT_WARN: case OPT_WARN:
strcpy(config.output_format, "a"); strcpy(config.output_format, "a");
config.warning = config.warning = strtod_or_err(optarg, "illegal argument");
strtod_or_err(optarg, "illegal argument");
break; break;
case OPT_CRIT: case OPT_CRIT:
strcpy(config.output_format, "a"); strcpy(config.output_format, "a");
config.critical = config.critical = strtod_or_err(optarg, "illegal argument");
strtod_or_err(optarg, "illegal argument");
break; break;
case OPT_MINSIZE: case OPT_MINSIZE:
config.minsize = config.minsize = strtod_or_err(optarg, "illegal argument");
strtod_or_err(optarg, "illegal argument");
break; break;
case 'v': case 'v':
/* Print version */ /* Print version */
@ -206,9 +199,7 @@ int main(int argc, char **argv)
/* Print help */ /* Print help */
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
default: default:
errx(EXIT_FAILURE, errx(EXIT_FAILURE, "Try `%s --help' for more information.", program_name);
"Try `%s --help' for more information.",
program_name);
} }
} }
@ -244,8 +235,7 @@ int main(int argc, char **argv)
break; break;
default: default:
clean_up(); clean_up();
errx(EXIT_FAILURE, "main: unknown output format `%c'", errx(EXIT_FAILURE, "main: unknown output format `%c'", config.output_format[0]);
config.output_format[0]);
} }
/* Do the job */ /* Do the job */
@ -278,8 +268,7 @@ int prepare_memory(void)
config.dhcp_version = VERSION_UNKNOWN; config.dhcp_version = VERSION_UNKNOWN;
RANGES = 64; RANGES = 64;
num_ranges = num_shared_networks = 0; num_ranges = num_shared_networks = 0;
shared_networks = shared_networks = xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
ranges = xmalloc(sizeof(struct range_t) * RANGES); ranges = xmalloc(sizeof(struct range_t) * RANGES);

View file

@ -194,9 +194,9 @@ enum limbits {
/*! \def STATE_OK /*! \def STATE_OK
* \brief Nagios alarm exit value. * \brief Nagios alarm exit value.
*/ */
#define STATE_OK 0 # define STATE_OK 0
#define STATE_WARNING 1 # define STATE_WARNING 1
#define STATE_CRITICAL 2 # define STATE_CRITICAL 2
/* Global variables */ /* Global variables */
/* \var prefix_length Length of each prefix. */ /* \var prefix_length Length of each prefix. */
@ -220,50 +220,53 @@ unsigned int RANGES;
int prepare_memory(void); int prepare_memory(void);
void set_ipv_functions(int version); void set_ipv_functions(int version);
int parse_leases(void); int parse_leases(void);
void parse_config(int, const char *__restrict, void parse_config(int, const char *__restrict, struct shared_network_t *__restrict)
struct shared_network_t *__restrict)
__attribute__ ((nonnull(2, 3))); __attribute__ ((nonnull(2, 3)));
int prepare_data(void); int prepare_data(void);
int do_counting(void); int do_counting(void);
void flip_ranges(struct range_t *__restrict ranges, void flip_ranges(struct range_t *__restrict ranges, struct range_t *__restrict tmp_ranges)
struct range_t *__restrict tmp_ranges)
__attribute__ ((nonnull(1, 2))); __attribute__ ((nonnull(1, 2)));
/* support functions */ /* support functions */
int (*parse_ipaddr)(const char *restrict src, union ipaddr_t *restrict dst); int (*parse_ipaddr) (const char *restrict src, union ipaddr_t *restrict dst);
int parse_ipaddr_init(const char *restrict src, union ipaddr_t *restrict dst) _DP_ATTRIBUTE_CONST; int parse_ipaddr_init(const char *restrict src, union ipaddr_t *restrict dst) _DP_ATTRIBUTE_CONST;
int parse_ipaddr_v4(const char *restrict src, union ipaddr_t *restrict dst); int parse_ipaddr_v4(const char *restrict src, union ipaddr_t *restrict dst);
int parse_ipaddr_v6(const char *restrict src, union ipaddr_t *restrict dst); int parse_ipaddr_v6(const char *restrict src, union ipaddr_t *restrict dst);
void (*copy_ipaddr)(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); void (*copy_ipaddr) (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src);
void copy_ipaddr_init(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) _DP_ATTRIBUTE_CONST; void copy_ipaddr_init(union ipaddr_t *restrict dst,
const union ipaddr_t *restrict src) _DP_ATTRIBUTE_CONST;
void copy_ipaddr_v4(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); void copy_ipaddr_v4(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src);
void copy_ipaddr_v6(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); void copy_ipaddr_v6(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src);
const char *(*ntop_ipaddr)(const union ipaddr_t *ip); const char *(*ntop_ipaddr) (const union ipaddr_t *ip);
const char *ntop_ipaddr_init(const union ipaddr_t *ip) _DP_ATTRIBUTE_CONST; const char *ntop_ipaddr_init(const union ipaddr_t *ip) _DP_ATTRIBUTE_CONST;
const char *ntop_ipaddr_v4(const union ipaddr_t *ip); const char *ntop_ipaddr_v4(const union ipaddr_t *ip);
const char *ntop_ipaddr_v6(const union ipaddr_t *ip); const char *ntop_ipaddr_v6(const union ipaddr_t *ip);
double (*get_range_size)(const struct range_t *r); double (*get_range_size) (const struct range_t *r);
double get_range_size_init(const struct range_t *r) _DP_ATTRIBUTE_CONST; double get_range_size_init(const struct range_t *r) _DP_ATTRIBUTE_CONST;
double get_range_size_v4(const struct range_t *r) _DP_ATTRIBUTE_PURE; double get_range_size_v4(const struct range_t *r) _DP_ATTRIBUTE_PURE;
double get_range_size_v6(const struct range_t *r) _DP_ATTRIBUTE_PURE; double get_range_size_v6(const struct range_t *r) _DP_ATTRIBUTE_PURE;
int (*xstrstr)(const char *__restrict str); int (*xstrstr) (const char *__restrict str);
int xstrstr_init(const char *__restrict str) _DP_ATTRIBUTE_CONST; int xstrstr_init(const char *__restrict str) _DP_ATTRIBUTE_CONST;
int xstrstr_v4(const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE; int xstrstr_v4(const char *__restrict str)
int xstrstr_v6(const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE; _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE;
int xstrstr_v6(const char *__restrict str)
_DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE;
double strtod_or_err(const char *__restrict str, double strtod_or_err(const char *__restrict str, const char *__restrict errmesg);
const char *__restrict errmesg);
void print_version(void) __attribute__ ((noreturn)); void print_version(void) __attribute__ ((noreturn));
void usage(int status) __attribute__ ((noreturn)); void usage(int status) __attribute__ ((noreturn));
/* qsort required functions... */ /* qsort required functions... */
/* ...for ranges and... */ /* ...for ranges and... */
int (*ipcomp)(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b); int (*ipcomp) (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b);
int ipcomp_init(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_CONST; int ipcomp_init(const union ipaddr_t *restrict a,
int ipcomp_v4(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE; const union ipaddr_t *restrict b) _DP_ATTRIBUTE_CONST;
int ipcomp_v6(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE; int ipcomp_v4(const union ipaddr_t *restrict a,
const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE;
int ipcomp_v6(const union ipaddr_t *restrict a,
const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE;
int comp_cur(struct range_t *r1, struct range_t *r2) _DP_ATTRIBUTE_PURE; int comp_cur(struct range_t *r1, struct range_t *r2) _DP_ATTRIBUTE_PURE;
int comp_double(double f1, double f2) _DP_ATTRIBUTE_CONST; int comp_double(double f1, double f2) _DP_ATTRIBUTE_CONST;
@ -281,8 +284,7 @@ comparer_t field_selector(char c);
double ret_percent(struct range_t r); double ret_percent(struct range_t r);
double ret_tc(struct range_t r) _DP_ATTRIBUTE_CONST; double ret_tc(struct range_t r) _DP_ATTRIBUTE_CONST;
double ret_tcperc(struct range_t r); double ret_tcperc(struct range_t r);
void mergesort_ranges(struct range_t *__restrict orig, int size, void mergesort_ranges(struct range_t *__restrict orig, int size, struct range_t *__restrict temp)
struct range_t *__restrict temp)
__attribute__ ((nonnull(1, 3))); __attribute__ ((nonnull(1, 3)));
/* output function pointer and functions */ /* output function pointer and functions */
int (*output_analysis) (void); int (*output_analysis) (void);
@ -295,12 +297,12 @@ int output_alarming(void);
/* Memory release, file closing etc */ /* Memory release, file closing etc */
void clean_up(void); void clean_up(void);
/* Hash functions */ /* Hash functions */
void (*add_lease)(union ipaddr_t *ip, enum ltype type); void (*add_lease) (union ipaddr_t *ip, enum ltype type);
void add_lease_init(union ipaddr_t *ip, enum ltype type) _DP_ATTRIBUTE_CONST; void add_lease_init(union ipaddr_t *ip, enum ltype type) _DP_ATTRIBUTE_CONST;
void add_lease_v4(union ipaddr_t *ip, enum ltype type); void add_lease_v4(union ipaddr_t *ip, enum ltype type);
void add_lease_v6(union ipaddr_t *ip, enum ltype type); void add_lease_v6(union ipaddr_t *ip, enum ltype type);
struct leases_t *(*find_lease)(union ipaddr_t *ip); struct leases_t *(*find_lease) (union ipaddr_t *ip);
struct leases_t *find_lease_init(union ipaddr_t *ip) _DP_ATTRIBUTE_CONST; struct leases_t *find_lease_init(union ipaddr_t *ip) _DP_ATTRIBUTE_CONST;
struct leases_t *find_lease_v4(union ipaddr_t *ip) _DP_ATTRIBUTE_PURE; struct leases_t *find_lease_v4(union ipaddr_t *ip) _DP_ATTRIBUTE_PURE;
struct leases_t *find_lease_v6(union ipaddr_t *ip) _DP_ATTRIBUTE_PURE; struct leases_t *find_lease_v6(union ipaddr_t *ip) _DP_ATTRIBUTE_PURE;

View file

@ -75,14 +75,12 @@ int parse_leases(void)
#ifdef HAVE_POSIX_FADVISE #ifdef HAVE_POSIX_FADVISE
# ifdef POSIX_FADV_NOREUSE # ifdef POSIX_FADV_NOREUSE
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_NOREUSE) != 0) { if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_NOREUSE) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s", err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file);
config.dhcpdlease_file);
} }
# endif /* POSIX_FADV_NOREUSE */ # endif /* POSIX_FADV_NOREUSE */
# ifdef POSIX_FADV_SEQUENTIAL # ifdef POSIX_FADV_SEQUENTIAL
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) { if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s", err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file);
config.dhcpdlease_file);
} }
# endif /* POSIX_FADV_SEQUENTIAL */ # endif /* POSIX_FADV_SEQUENTIAL */
#endif /* HAVE_POSIX_FADVISE */ #endif /* HAVE_POSIX_FADVISE */
@ -103,13 +101,15 @@ int parse_leases(void)
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)) {
err(EXIT_FAILURE, "parse_leases: %s", err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
config.dhcpdlease_file);
} }
switch(xstrstr(line)) { switch (xstrstr(line)) {
/* It's a lease, save IP */ /* It's a lease, save IP */
case PREFIX_LEASE: case PREFIX_LEASE:
stop = memccpy(ipstring, line + (config.dhcp_version == VERSION_4 ? 6 : 9), ' ', strlen(line)); stop =
memccpy(ipstring,
line + (config.dhcp_version ==
VERSION_4 ? 6 : 9), ' ', strlen(line));
if (stop != NULL) { if (stop != NULL) {
--stop; --stop;
*stop = '\0'; *stop = '\0';
@ -150,7 +150,7 @@ int parse_leases(void)
} }
break; break;
default: default:
/* do nothing */; /* do nothing */ ;
} }
} }
#undef HAS_PREFIX #undef HAS_PREFIX
@ -204,14 +204,14 @@ void parse_config(int is_include, const char *restrict config_file,
} }
#ifdef HAVE_POSIX_FADVISE #ifdef HAVE_POSIX_FADVISE
# ifdef POSIX_FADV_NOREUSE # ifdef POSIX_FADV_NOREUSE
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_NOREUSE) != 0) { if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_NOREUSE) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file); err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
} }
# endif /* POSIX_FADV_NOREUSE */ # endif /* POSIX_FADV_NOREUSE */
# ifdef POSIX_FADV_SEQUENTIAL # ifdef POSIX_FADV_SEQUENTIAL
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) { if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file); err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
} }
# endif /* POSIX_FADV_SEQUENTIAL */ # endif /* POSIX_FADV_SEQUENTIAL */
#endif /* HAVE_POSIX_FADVISE */ #endif /* HAVE_POSIX_FADVISE */
@ -248,8 +248,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
} }
if (comment == false if (comment == false
&& argument != ITS_A_RANGE_FIRST_IP && argument != ITS_A_RANGE_FIRST_IP
&& argument != ITS_A_RANGE_SECOND_IP && argument != ITS_A_RANGE_SECOND_IP && argument != ITS_AN_INCLUCE) {
&& argument != ITS_AN_INCLUCE) {
newclause = true; newclause = true;
i = 0; i = 0;
} else if (argument == ITS_A_RANGE_FIRST_IP && one_ip_range == true) { } else if (argument == ITS_A_RANGE_FIRST_IP && one_ip_range == true) {
@ -308,9 +307,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
} }
/* Either inside comment or Nth word of clause. */ /* Either inside comment or Nth word of clause. */
if (comment == true if (comment == true || (newclause == false && argument == ITS_NOTHING_INTERESTING)) {
|| (newclause == false
&& argument == ITS_NOTHING_INTERESTING)) {
continue; continue;
} }
/* Strip white spaces before new clause word. */ /* Strip white spaces before new clause word. */
@ -370,10 +367,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
num_ranges++; num_ranges++;
if (RANGES < num_ranges + 1) { if (RANGES < num_ranges + 1) {
RANGES *= 2; RANGES *= 2;
ranges = ranges = xrealloc(ranges, sizeof(struct range_t) * RANGES);
xrealloc(ranges,
sizeof(struct
range_t) * RANGES);
range_p = ranges + num_ranges; range_p = ranges + num_ranges;
} }
newclause = true; newclause = true;
@ -393,8 +387,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
case ITS_A_SHAREDNET: case ITS_A_SHAREDNET:
/* printf ("shared-network named: %s\n", word); */ /* printf ("shared-network named: %s\n", word); */
num_shared_networks++; num_shared_networks++;
shared_p = shared_p = shared_networks + num_shared_networks;
shared_networks + num_shared_networks;
shared_p->name = xstrdup(word); shared_p->name = xstrdup(word);
shared_p->available = 0; shared_p->available = 0;
shared_p->used = 0; shared_p->used = 0;

View file

@ -47,7 +47,8 @@
/*! \brief Add a lease to hash array. /*! \brief Add a lease to hash array.
* \param addr Binary IP to be added in leases hash. * \param addr Binary IP to be added in leases hash.
* \param type Lease state of the IP. */ * \param type Lease state of the IP. */
void add_lease_init(union ipaddr_t *addr __attribute__((unused)), enum ltype type __attribute__((unused))) void add_lease_init(union ipaddr_t *addr
__attribute__ ((unused)), enum ltype type __attribute__ ((unused)))
{ {
} }
@ -75,7 +76,7 @@ void add_lease_v6(union ipaddr_t *addr, enum ltype type)
* \param addr Binary IP searched from leases hash. * \param addr Binary IP searched from leases hash.
* \return A lease structure about requested IP, or NULL. * \return A lease structure about requested IP, or NULL.
*/ */
struct leases_t *find_lease_init(union ipaddr_t *addr __attribute__((unused))) struct leases_t *find_lease_init(union ipaddr_t *addr __attribute__ ((unused)))
{ {
return NULL; return NULL;
} }

View file

@ -146,19 +146,17 @@ int parse_ipaddr_v6(const char *restrict src, union ipaddr_t *restrict dst)
* *
* \param dst Destination for a binary IP address. * \param dst Destination for a binary IP address.
* \param src Sourse of an IP address. */ * \param src Sourse of an IP address. */
void copy_ipaddr_init(union ipaddr_t *restrict dst __attribute__((unused)), void copy_ipaddr_init(union ipaddr_t *restrict dst __attribute__ ((unused)),
const union ipaddr_t *restrict src __attribute__((unused))) const union ipaddr_t *restrict src __attribute__ ((unused)))
{ {
} }
void copy_ipaddr_v4(union ipaddr_t *restrict dst, void copy_ipaddr_v4(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src)
const union ipaddr_t *restrict src)
{ {
dst->v4 = src->v4; dst->v4 = src->v4;
} }
void copy_ipaddr_v6(union ipaddr_t *restrict dst, void copy_ipaddr_v6(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src)
const union ipaddr_t *restrict src)
{ {
memcpy(&dst->v6, &src->v6, sizeof(src->v6)); memcpy(&dst->v6, &src->v6, sizeof(src->v6));
} }
@ -171,7 +169,7 @@ void copy_ipaddr_v6(union ipaddr_t *restrict dst,
* \param ip Binary IP address. * \param ip Binary IP address.
* \return Printable address. * \return Printable address.
*/ */
const char *ntop_ipaddr_init(const union ipaddr_t *ip __attribute__((unused))) const char *ntop_ipaddr_init(const union ipaddr_t *ip __attribute__ ((unused)))
{ {
static char buffer = '\0'; static char buffer = '\0';
return &buffer; return &buffer;
@ -187,8 +185,7 @@ const char *ntop_ipaddr_v4(const union ipaddr_t *ip)
const char *ntop_ipaddr_v6(const union ipaddr_t *ip) const char *ntop_ipaddr_v6(const union ipaddr_t *ip)
{ {
static char static char buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
struct in6_addr addr; struct in6_addr addr;
memcpy(addr.s6_addr, ip->v6, sizeof(addr.s6_addr)); memcpy(addr.s6_addr, ip->v6, sizeof(addr.s6_addr));
return inet_ntop(AF_INET6, &addr, buffer, sizeof(buffer)); return inet_ntop(AF_INET6, &addr, buffer, sizeof(buffer));
@ -200,7 +197,7 @@ const char *ntop_ipaddr_v6(const union ipaddr_t *ip)
* and last IP in the range. * and last IP in the range.
* \return Size of a range. * \return Size of a range.
*/ */
double get_range_size_init(const struct range_t *r __attribute__((unused))) double get_range_size_init(const struct range_t *r __attribute__ ((unused)))
{ {
return 0; return 0;
} }
@ -389,8 +386,7 @@ double strtod_or_err(const char *restrict str, const char *restrict errmesg)
* *
* \param flip_me The range that needs to be inverted. * \param flip_me The range that needs to be inverted.
* \param tmp_ranges Temporary memory area for the flip. */ * \param tmp_ranges Temporary memory area for the flip. */
void flip_ranges(struct range_t *restrict flip_me, void flip_ranges(struct range_t *restrict flip_me, struct range_t *restrict tmp_ranges)
struct range_t *restrict tmp_ranges)
{ {
unsigned int i = num_ranges - 1, j; unsigned int i = num_ranges - 1, j;

View file

@ -90,8 +90,7 @@ int output_txt(void)
max_ipaddr_length, max_ipaddr_length,
"first ip", "first ip",
max_ipaddr_length, max_ipaddr_length,
"last ip", "last ip", "max", "cur", "percent", "touch", "t+c", "t+c perc");
"max", "cur", "percent", "touch", "t+c", "t+c perc");
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, " bu bu perc"); fprintf(outfile, " bu bu perc");
} }
@ -100,8 +99,7 @@ int output_txt(void)
if (config.output_limit[1] & BIT1) { if (config.output_limit[1] & BIT1) {
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
if (range_p->shared_net) { if (range_p->shared_net) {
fprintf(outfile, "%-20s", fprintf(outfile, "%-20s", range_p->shared_net->name);
range_p->shared_net->name);
} else { } else {
fprintf(outfile, "not_defined "); fprintf(outfile, "not_defined ");
} }
@ -109,8 +107,7 @@ int output_txt(void)
* separate since ntop_ipaddr always returns the * separate since ntop_ipaddr always returns the
* same buffer */ * same buffer */
fprintf(outfile, "%-*s", fprintf(outfile, "%-*s",
max_ipaddr_length, max_ipaddr_length, ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip));
fprintf(outfile, fprintf(outfile,
" - %-*s %5g %5g %10.3f %5g %5g %9.3f", " - %-*s %5g %5g %10.3f %5g %5g %9.3f",
max_ipaddr_length, max_ipaddr_length,
@ -120,14 +117,11 @@ int output_txt(void)
(float)(100 * range_p->count) / range_size, (float)(100 * range_p->count) / range_size,
range_p->touched, range_p->touched,
range_p->touched + range_p->count, range_p->touched + range_p->count,
(float)(100 * (float)(100 * (range_p->touched + range_p->count)) / range_size);
(range_p->touched +
range_p->count)) / range_size);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f",
range_p->backups, range_p->backups,
(float)(100 * range_p->backups) / (float)(100 * range_p->backups) / range_size);
range_size);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
range_p++; range_p++;
@ -158,13 +152,11 @@ int output_txt(void)
shared_p->touched + shared_p->used, shared_p->touched + shared_p->used,
(float)(100 * (float)(100 *
(shared_p->touched + (shared_p->touched +
shared_p->used)) / shared_p->used)) / shared_p->available);
shared_p->available);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f",
shared_p->backups, shared_p->backups,
(float)(100 * shared_p->backups) / (float)(100 * shared_p->backups) / shared_p->available);
shared_p->available);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
@ -194,8 +186,7 @@ int output_txt(void)
shared_networks->touched + shared_networks->used, shared_networks->touched + shared_networks->used,
(float)(100 * (float)(100 *
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) / shared_networks->available);
shared_networks->available);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f",
@ -257,8 +248,7 @@ int output_xml(void)
if (l->ethernet != NULL) { if (l->ethernet != NULL) {
fputs(l->ethernet, outfile); fputs(l->ethernet, outfile);
} }
fputs("</macaddress>\n</active_lease>\n", fputs("</macaddress>\n</active_lease>\n", outfile);
outfile);
} }
} }
} }
@ -268,25 +258,19 @@ int output_xml(void)
fprintf(outfile, "<subnet>\n"); fprintf(outfile, "<subnet>\n");
if (range_p->shared_net) { if (range_p->shared_net) {
fprintf(outfile, fprintf(outfile,
"\t<location>%s</location>\n", "\t<location>%s</location>\n", range_p->shared_net->name);
range_p->shared_net->name);
} else { } else {
fprintf(outfile, "\t<location></location>\n"); fprintf(outfile, "\t<location></location>\n");
} }
fprintf(outfile, "\t<network></network>\n"); fprintf(outfile, "\t<network></network>\n");
fprintf(outfile, "\t<netmask></netmask>\n"); fprintf(outfile, "\t<netmask></netmask>\n");
fprintf(outfile, "\t<range>%s ", fprintf(outfile, "\t<range>%s ", ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip)); fprintf(outfile, "- %s</range>\n", ntop_ipaddr(&range_p->last_ip));
fprintf(outfile, "- %s</range>\n",
ntop_ipaddr(&range_p->last_ip));
fprintf(outfile, "\t<gateway></gateway>\n"); fprintf(outfile, "\t<gateway></gateway>\n");
fprintf(outfile, "\t<defined>%g</defined>\n", fprintf(outfile, "\t<defined>%g</defined>\n", range_size);
range_size); fprintf(outfile, "\t<used>%g</used>\n", range_p->count);
fprintf(outfile, "\t<used>%g</used>\n", fprintf(outfile, "\t<free>%g</free>\n", range_size - range_p->count);
range_p->count);
fprintf(outfile, "\t<free>%g</free>\n",
range_size - range_p->count);
range_p++; range_p++;
range_size = get_range_size(range_p); range_size = get_range_size(range_p);
fprintf(outfile, "</subnet>\n"); fprintf(outfile, "</subnet>\n");
@ -297,12 +281,9 @@ int output_xml(void)
for (i = 0; i < num_shared_networks; i++) { for (i = 0; i < num_shared_networks; i++) {
shared_p++; shared_p++;
fprintf(outfile, "<shared-network>\n"); fprintf(outfile, "<shared-network>\n");
fprintf(outfile, "\t<location>%s</location>\n", fprintf(outfile, "\t<location>%s</location>\n", shared_p->name);
shared_p->name); fprintf(outfile, "\t<defined>%g</defined>\n", shared_p->available);
fprintf(outfile, "\t<defined>%g</defined>\n", fprintf(outfile, "\t<used>%g</used>\n", shared_p->used);
shared_p->available);
fprintf(outfile, "\t<used>%g</used>\n",
shared_p->used);
fprintf(outfile, "\t<free>%g</free>\n", fprintf(outfile, "\t<free>%g</free>\n",
shared_p->available - shared_p->used); shared_p->available - shared_p->used);
fprintf(outfile, "</shared-network>\n"); fprintf(outfile, "</shared-network>\n");
@ -311,10 +292,8 @@ int output_xml(void)
if (config.output_limit[0] & BIT3) { if (config.output_limit[0] & BIT3) {
fprintf(outfile, "<summary>\n"); fprintf(outfile, "<summary>\n");
fprintf(outfile, "\t<location>%s</location>\n", fprintf(outfile, "\t<location>%s</location>\n", shared_networks->name);
shared_networks->name); fprintf(outfile, "\t<defined>%g</defined>\n", shared_networks->available);
fprintf(outfile, "\t<defined>%g</defined>\n",
shared_networks->available);
fprintf(outfile, "\t<used>%g</used>\n", shared_networks->used); fprintf(outfile, "\t<used>%g</used>\n", shared_networks->used);
fprintf(outfile, "\t<free>%g</free>\n", fprintf(outfile, "\t<free>%g</free>\n",
shared_networks->available - shared_networks->used); shared_networks->available - shared_networks->used);
@ -353,8 +332,7 @@ int output_json(void)
if (config.output_file[0]) { if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+"); outfile = fopen(config.output_file, "w+");
if (outfile == NULL) { if (outfile == NULL) {
err(EXIT_FAILURE, "output_json: %s", err(EXIT_FAILURE, "output_json: %s", config.output_file);
config.output_file);
} }
} else { } else {
outfile = stdout; outfile = stdout;
@ -400,20 +378,16 @@ int output_json(void)
fprintf(outfile, "{ "); fprintf(outfile, "{ ");
if (range_p->shared_net) { if (range_p->shared_net) {
fprintf(outfile, fprintf(outfile,
"\"location\":\"%s\", ", "\"location\":\"%s\", ", range_p->shared_net->name);
range_p->shared_net->name);
} else { } else {
fprintf(outfile, "\"location\":\"\", "); fprintf(outfile, "\"location\":\"\", ");
} }
fprintf(outfile, "\"range\":\"%s", fprintf(outfile, "\"range\":\"%s", ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip)); fprintf(outfile, " - %s\", ", ntop_ipaddr(&range_p->last_ip));
fprintf(outfile, " - %s\", ",
ntop_ipaddr(&range_p->last_ip));
fprintf(outfile, "\"defined\":%g, ", range_size); fprintf(outfile, "\"defined\":%g, ", range_size);
fprintf(outfile, "\"used\":%g, ", range_p->count); fprintf(outfile, "\"used\":%g, ", range_p->count);
fprintf(outfile, "\"free\":%g ", fprintf(outfile, "\"free\":%g ", range_size - range_p->count);
range_size - range_p->count);
range_p++; range_p++;
range_size = get_range_size(range_p); range_size = get_range_size(range_p);
if (i + 1 < num_ranges) if (i + 1 < num_ranges)
@ -434,13 +408,10 @@ int output_json(void)
fprintf(outfile, " "); fprintf(outfile, " ");
shared_p++; shared_p++;
fprintf(outfile, "{ "); fprintf(outfile, "{ ");
fprintf(outfile, "\"location\":\"%s\", ", fprintf(outfile, "\"location\":\"%s\", ", shared_p->name);
shared_p->name); fprintf(outfile, "\"defined\":%g, ", shared_p->available);
fprintf(outfile, "\"defined\":%g, ",
shared_p->available);
fprintf(outfile, "\"used\":%g, ", shared_p->used); fprintf(outfile, "\"used\":%g, ", shared_p->used);
fprintf(outfile, "\"free\":%g ", fprintf(outfile, "\"free\":%g ", shared_p->available - shared_p->used);
shared_p->available - shared_p->used);
if (i + 1 < num_shared_networks) if (i + 1 < num_shared_networks)
fprintf(outfile, "},\n"); fprintf(outfile, "},\n");
else else
@ -455,12 +426,9 @@ int output_json(void)
fprintf(outfile, ",\n"); fprintf(outfile, ",\n");
} }
fprintf(outfile, " \"summary\": {\n"); fprintf(outfile, " \"summary\": {\n");
fprintf(outfile, " \"location\":\"%s\",\n", fprintf(outfile, " \"location\":\"%s\",\n", shared_networks->name);
shared_networks->name); fprintf(outfile, " \"defined\":%g,\n", shared_networks->available);
fprintf(outfile, " \"defined\":%g,\n", fprintf(outfile, " \"used\":%g,\n", shared_networks->used);
shared_networks->available);
fprintf(outfile, " \"used\":%g,\n",
shared_networks->used);
fprintf(outfile, " \"free\":%g\n", fprintf(outfile, " \"free\":%g\n",
shared_networks->available - shared_networks->used); shared_networks->available - shared_networks->used);
fprintf(outfile, " }"); /* end of summary */ fprintf(outfile, " }"); /* end of summary */
@ -618,8 +586,7 @@ static void output_line(FILE *restrict f, char const *restrict type,
* \param type HMTL tag name. * \param type HMTL tag name.
* \param d Actual payload of the printout. * \param d Actual payload of the printout.
*/ */
static void output_double(FILE *restrict f, char const *restrict type, static void output_double(FILE *restrict f, char const *restrict type, double d)
double d)
{ {
fprintf(f, " <%s class=ralign>%g</%s>\n", type, d, type); fprintf(f, " <%s class=ralign>%g</%s>\n", type, d, type);
} }
@ -684,8 +651,7 @@ int output_html(void)
if (config.output_file[0]) { if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+"); outfile = fopen(config.output_file, "w+");
if (outfile == NULL) { if (outfile == NULL) {
err(EXIT_FAILURE, "output_html: %s", err(EXIT_FAILURE, "output_html: %s", config.output_file);
config.output_file);
} }
} else { } else {
outfile = stdout; outfile = stdout;
@ -720,34 +686,24 @@ int output_html(void)
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
newrow(outfile); newrow(outfile);
if (range_p->shared_net) { if (range_p->shared_net) {
output_line(outfile, "td", "calign", output_line(outfile, "td", "calign", range_p->shared_net->name);
range_p->shared_net->name);
} else { } else {
output_line(outfile, "td", "calign", output_line(outfile, "td", "calign", "not_defined");
"not_defined");
} }
output_line(outfile, "td", "calign", output_line(outfile, "td", "calign", ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip)); output_line(outfile, "td", "calign", ntop_ipaddr(&range_p->last_ip));
output_line(outfile, "td", "calign",
ntop_ipaddr(&range_p->last_ip));
output_double(outfile, "td", range_size); output_double(outfile, "td", range_size);
output_double(outfile, "td", range_p->count); output_double(outfile, "td", range_p->count);
output_float(outfile, "td", output_float(outfile, "td", (float)(100 * range_p->count) / range_size);
(float)(100 * range_p->count) /
range_size);
output_double(outfile, "td", range_p->touched); output_double(outfile, "td", range_p->touched);
output_double(outfile, "td", output_double(outfile, "td", range_p->touched + range_p->count);
range_p->touched + range_p->count);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * (float)(100 *
(range_p->touched + (range_p->touched + range_p->count)) / range_size);
range_p->count)) / range_size);
if (config.backups_found == true) { if (config.backups_found == true) {
output_double(outfile, "td", range_p->backups); output_double(outfile, "td", range_p->backups);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * (float)(100 * range_p->backups) / range_size);
range_p->backups) /
range_size);
} }
endrow(outfile); endrow(outfile);
range_p++; range_p++;
@ -780,22 +736,18 @@ int output_html(void)
output_double(outfile, "td", shared_p->available); output_double(outfile, "td", shared_p->available);
output_double(outfile, "td", shared_p->used); output_double(outfile, "td", shared_p->used);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * shared_p->used) / (float)(100 * shared_p->used) / shared_p->available);
shared_p->available);
output_double(outfile, "td", shared_p->touched); output_double(outfile, "td", shared_p->touched);
output_double(outfile, "td", output_double(outfile, "td", shared_p->touched + shared_p->used);
shared_p->touched + shared_p->used);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * (float)(100 *
(shared_p->touched + (shared_p->touched +
shared_p->used)) / shared_p->used)) / shared_p->available);
shared_p->available);
if (config.backups_found == true) { if (config.backups_found == true) {
output_double(outfile, "td", shared_p->backups); output_double(outfile, "td", shared_p->backups);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * (float)(100 *
shared_p->backups) / shared_p->backups) / shared_p->available);
shared_p->available);
} }
endrow(outfile); endrow(outfile);
@ -824,16 +776,13 @@ int output_html(void)
output_double(outfile, "td", shared_networks->available); output_double(outfile, "td", shared_networks->available);
output_double(outfile, "td", shared_networks->used); output_double(outfile, "td", shared_networks->used);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * shared_networks->used) / (float)(100 * shared_networks->used) / shared_networks->available);
shared_networks->available);
output_double(outfile, "td", shared_networks->touched); output_double(outfile, "td", shared_networks->touched);
output_double(outfile, "td", output_double(outfile, "td", shared_networks->touched + shared_networks->used);
shared_networks->touched + shared_networks->used);
output_float(outfile, "td", output_float(outfile, "td",
(float)(100 * (float)(100 *
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) / shared_networks->available);
shared_networks->available);
if (config.backups_found == true) { if (config.backups_found == true) {
output_double(outfile, "td", shared_networks->backups); output_double(outfile, "td", shared_networks->backups);
output_float(outfile, "td", output_float(outfile, "td",
@ -897,13 +846,11 @@ int output_csv(void)
if (config.output_limit[1] & BIT1) { if (config.output_limit[1] & BIT1) {
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
if (range_p->shared_net) { if (range_p->shared_net) {
fprintf(outfile, "\"%s\",", fprintf(outfile, "\"%s\",", range_p->shared_net->name);
range_p->shared_net->name);
} else { } else {
fprintf(outfile, "\"not_defined\","); fprintf(outfile, "\"not_defined\",");
} }
fprintf(outfile, "\"%s\",", fprintf(outfile, "\"%s\",", ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip));
fprintf(outfile, fprintf(outfile,
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"", "\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
ntop_ipaddr(&range_p->last_ip), range_size, ntop_ipaddr(&range_p->last_ip), range_size,
@ -911,14 +858,11 @@ int output_csv(void)
(float)(100 * range_p->count) / range_size, (float)(100 * range_p->count) / range_size,
range_p->touched, range_p->touched,
range_p->touched + range_p->count, range_p->touched + range_p->count,
(float)(100 * (float)(100 * (range_p->touched + range_p->count)) / range_size);
(range_p->touched +
range_p->count)) / range_size);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, ",\"%g\",\"%.3f\"", fprintf(outfile, ",\"%g\",\"%.3f\"",
range_p->backups, range_p->backups,
(float)(100 * range_p->backups) / (float)(100 * range_p->backups) / range_size);
range_size);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
@ -949,13 +893,11 @@ int output_csv(void)
shared_p->touched + shared_p->used, shared_p->touched + shared_p->used,
(float)(100 * (float)(100 *
(shared_p->touched + (shared_p->touched +
shared_p->used)) / shared_p->used)) / shared_p->available);
shared_p->available);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, ",\"%g\",\"%.3f\"", fprintf(outfile, ",\"%g\",\"%.3f\"",
shared_p->backups, shared_p->backups,
(float)(100 * shared_p->backups) / (float)(100 * shared_p->backups) / shared_p->available);
shared_p->available);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
@ -983,8 +925,7 @@ int output_csv(void)
shared_networks->touched + shared_networks->used, shared_networks->touched + shared_networks->used,
(float)(100 * (float)(100 *
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) / shared_networks->available);
shared_networks->available);
if (config.backups_found == true) { if (config.backups_found == true) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f",
shared_networks->backups, shared_networks->backups,
@ -1028,8 +969,7 @@ int output_alarming(void)
if (config.output_file[0]) { if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+"); outfile = fopen(config.output_file, "w+");
if (outfile == NULL) { if (outfile == NULL) {
err(EXIT_FAILURE, "output_alarming: %s", err(EXIT_FAILURE, "output_alarming: %s", config.output_file);
config.output_file);
} }
} else { } else {
outfile = stdout; outfile = stdout;
@ -1038,8 +978,7 @@ int output_alarming(void)
if (config.output_limit[1] & BIT1) { if (config.output_limit[1] & BIT1) {
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
if (config.minsize < range_size) { if (config.minsize < range_size) {
perc = perc = (float)(100 * range_p->count) / range_size;
(float)(100 * range_p->count) / range_size;
if (config.critical < perc) if (config.critical < perc)
rc++; rc++;
else if (config.warning < perc) else if (config.warning < perc)
@ -1056,8 +995,7 @@ int output_alarming(void)
if (config.output_limit[1] & BIT2) { if (config.output_limit[1] & BIT2) {
for (i = 0; i < num_shared_networks; i++) { for (i = 0; i < num_shared_networks; i++) {
if (config.minsize < shared_p->available) { if (config.minsize < shared_p->available) {
perc = (float)(100 * shared_p->used) / perc = (float)(100 * shared_p->used) / shared_p->available;
shared_p->available;
if (config.critical < perc) if (config.critical < perc)
sc++; sc++;
else if (config.warning < perc) else if (config.warning < perc)
@ -1078,12 +1016,12 @@ int output_alarming(void)
else else
ret_val = STATE_OK; ret_val = STATE_OK;
if ((0 < rc && config.output_limit[1] & BIT1) || (0 < sc && config.output_limit[1] & BIT2)) { if ((0 < rc && config.output_limit[1] & BIT1)
fprintf(outfile, "CRITICAL: %s:", || (0 < sc && config.output_limit[1] & BIT2)) {
program_name); fprintf(outfile, "CRITICAL: %s:", program_name);
} else if ((0 < rw && config.output_limit[1] & BIT1) || (0 < sw && config.output_limit[1] & BIT2)) { } else if ((0 < rw && config.output_limit[1] & BIT1)
fprintf(outfile, "WARNING: %s:", || (0 < sw && config.output_limit[1] & BIT2)) {
program_name); fprintf(outfile, "WARNING: %s:", program_name);
} else { } else {
if (config.output_limit[1] & BIT3) if (config.output_limit[1] & BIT3)
fprintf(outfile, "OK:"); fprintf(outfile, "OK:");
@ -1091,13 +1029,11 @@ int output_alarming(void)
return ret_val; return ret_val;
} }
if (config.output_limit[0] & BIT1) { if (config.output_limit[0] & BIT1) {
fprintf(outfile, " Ranges - crit: %d warn: %d ok: %d", rc, rw, fprintf(outfile, " Ranges - crit: %d warn: %d ok: %d", rc, rw, ro);
ro);
if (ri != 0) { if (ri != 0) {
fprintf(outfile, " ignored: %d", ri); fprintf(outfile, " ignored: %d", ri);
} }
fprintf(outfile, "; | range_crit=%d range_warn=%d range_ok=%d", rc, rw, fprintf(outfile, "; | range_crit=%d range_warn=%d range_ok=%d", rc, rw, ro);
ro);
if (ri != 0) { if (ri != 0) {
fprintf(outfile, " range_ignored=%d", ri); fprintf(outfile, " range_ignored=%d", ri);
} }
@ -1106,13 +1042,11 @@ int output_alarming(void)
fprintf(outfile, " "); fprintf(outfile, " ");
} }
if (config.output_limit[0] & BIT2) { if (config.output_limit[0] & BIT2) {
fprintf(outfile, "Shared nets - crit: %d warn: %d ok: %d", sc, fprintf(outfile, "Shared nets - crit: %d warn: %d ok: %d", sc, sw, so);
sw, so);
if (si != 0) { if (si != 0) {
fprintf(outfile, " ignored: %d", si); fprintf(outfile, " ignored: %d", si);
} }
fprintf(outfile, "; | snet_crit=%d snet_warn=%d snet_ok=%d", sc, fprintf(outfile, "; | snet_crit=%d snet_warn=%d snet_ok=%d", sc, sw, so);
sw, so);
if (si != 0) { if (si != 0) {
fprintf(outfile, " snet_ignored=%d\n", si); fprintf(outfile, " snet_ignored=%d\n", si);
} }

View file

@ -54,14 +54,13 @@
* \param b Binary IP address. * \param b Binary IP address.
* \return If a < b return -1, if a < b return 1, when they are equal return 0. * \return If a < b return -1, if a < b return 1, when they are equal return 0.
*/ */
int ipcomp_init(const union ipaddr_t *restrict a __attribute__((unused)), int ipcomp_init(const union ipaddr_t *restrict a __attribute__ ((unused)),
const union ipaddr_t *restrict b __attribute__((unused))) const union ipaddr_t *restrict b __attribute__ ((unused)))
{ {
return 0; return 0;
} }
int ipcomp_v4(const union ipaddr_t *restrict a, int ipcomp_v4(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
const union ipaddr_t *restrict b)
{ {
if (a->v4 < b->v4) if (a->v4 < b->v4)
return -1; return -1;
@ -70,8 +69,7 @@ int ipcomp_v4(const union ipaddr_t *restrict a,
return 0; return 0;
} }
int ipcomp_v6(const union ipaddr_t *restrict a, int ipcomp_v6(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
const union ipaddr_t *restrict b)
{ {
return memcmp(&a->v6, &b->v6, sizeof(a->v6)); return memcmp(&a->v6, &b->v6, sizeof(a->v6));
} }
@ -215,8 +213,7 @@ comparer_t field_selector(char c)
default: default:
clean_up(); clean_up();
warnx("field_selector: unknown sort order `%c'", c); warnx("field_selector: unknown sort order `%c'", c);
errx(EXIT_FAILURE, "Try `%s --help' for more information.", errx(EXIT_FAILURE, "Try `%s --help' for more information.", program_name);
program_name);
} }
return NULL; return NULL;
} }
@ -236,9 +233,7 @@ static int merge(struct range_t *restrict left, struct range_t *restrict right)
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
/* Handling strings is case of it's own */ /* Handling strings is case of it's own */
if (config.sort[i] == 'n') { if (config.sort[i] == 'n') {
ret = ret = strcmp(left->shared_net->name, right->shared_net->name);
strcmp(left->shared_net->name,
right->shared_net->name);
if (0 < ret) if (0 < ret)
return (0); return (0);
if (ret < 0) if (ret < 0)
@ -269,8 +264,7 @@ static int merge(struct range_t *restrict left, struct range_t *restrict right)
* \param temp Temporary memory space, needed when a values has to be * \param temp Temporary memory space, needed when a values has to be
* flipped. * flipped.
*/ */
void mergesort_ranges(struct range_t *restrict orig, int size, void mergesort_ranges(struct range_t *restrict orig, int size, struct range_t *restrict temp)
struct range_t *restrict temp)
{ {
int left, right, i; int left, right, i;
struct range_t hold; struct range_t hold;