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 */
for (i = 0; i < num_ranges; i++) {
for (; l != NULL && ipcomp(&range_p->first_ip, &l->ip) < 0;
l = l->hh.prev)
for (; l != NULL && ipcomp(&range_p->first_ip, &l->ip) < 0; l = l->hh.prev)
/* rewind */ ;
if (l == NULL)
l = leases;
for (; l != NULL && ipcomp(&l->ip, &range_p->last_ip) <= 0;
l = l->hh.next) {
for (; l != NULL && ipcomp(&l->ip, &range_p->last_ip) <= 0; l = l->hh.next) {
if (ipcomp(&l->ip, &range_p->first_ip) < 0) {
/* should not be necessary */
continue;

View file

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

View file

@ -194,9 +194,9 @@ enum limbits {
/*! \def STATE_OK
* \brief Nagios alarm exit value.
*/
#define STATE_OK 0
#define STATE_WARNING 1
#define STATE_CRITICAL 2
# define STATE_OK 0
# define STATE_WARNING 1
# define STATE_CRITICAL 2
/* Global variables */
/* \var prefix_length Length of each prefix. */
@ -220,50 +220,53 @@ unsigned int RANGES;
int prepare_memory(void);
void set_ipv_functions(int version);
int parse_leases(void);
void parse_config(int, const char *__restrict,
struct shared_network_t *__restrict)
void parse_config(int, const char *__restrict, struct shared_network_t *__restrict)
__attribute__ ((nonnull(2, 3)));
int prepare_data(void);
int do_counting(void);
void flip_ranges(struct range_t *__restrict ranges,
struct range_t *__restrict tmp_ranges)
void flip_ranges(struct range_t *__restrict ranges, struct range_t *__restrict tmp_ranges)
__attribute__ ((nonnull(1, 2)));
/* 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_v4(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_init(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) _DP_ATTRIBUTE_CONST;
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_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);
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_v4(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_v4(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_v4(const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE;
int xstrstr_v6(const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE;
int xstrstr_v4(const char *__restrict str)
_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,
const char *__restrict errmesg);
double strtod_or_err(const char *__restrict str, const char *__restrict errmesg);
void print_version(void) __attribute__ ((noreturn));
void usage(int status) __attribute__ ((noreturn));
/* qsort required functions... */
/* ...for ranges and... */
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_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 (*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_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_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_tc(struct range_t r) _DP_ATTRIBUTE_CONST;
double ret_tcperc(struct range_t r);
void mergesort_ranges(struct range_t *__restrict orig, int size,
struct range_t *__restrict temp)
void mergesort_ranges(struct range_t *__restrict orig, int size, struct range_t *__restrict temp)
__attribute__ ((nonnull(1, 3)));
/* output function pointer and functions */
int (*output_analysis) (void);
@ -295,12 +297,12 @@ int output_alarming(void);
/* Memory release, file closing etc */
void clean_up(void);
/* 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_v4(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_v4(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 POSIX_FADV_NOREUSE
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_NOREUSE) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file);
}
# endif /* POSIX_FADV_NOREUSE */
# ifdef POSIX_FADV_SEQUENTIAL
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file);
}
# endif /* POSIX_FADV_SEQUENTIAL */
#endif /* HAVE_POSIX_FADVISE */
@ -103,13 +101,15 @@ int parse_leases(void)
while (!feof(dhcpd_leases)) {
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases)) {
err(EXIT_FAILURE, "parse_leases: %s",
config.dhcpdlease_file);
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
}
switch(xstrstr(line)) {
/* It's a lease, save IP */
switch (xstrstr(line)) {
/* It's a lease, save IP */
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) {
--stop;
*stop = '\0';
@ -150,7 +150,7 @@ int parse_leases(void)
}
break;
default:
/* do nothing */;
/* do nothing */ ;
}
}
#undef HAS_PREFIX
@ -204,14 +204,14 @@ void parse_config(int is_include, const char *restrict config_file,
}
#ifdef HAVE_POSIX_FADVISE
# ifdef POSIX_FADV_NOREUSE
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_NOREUSE) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_NOREUSE) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
# endif /* POSIX_FADV_NOREUSE */
# ifdef POSIX_FADV_SEQUENTIAL
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
# endif /* POSIX_FADV_SEQUENTIAL */
#endif /* HAVE_POSIX_FADVISE */
@ -248,8 +248,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
}
if (comment == false
&& argument != ITS_A_RANGE_FIRST_IP
&& argument != ITS_A_RANGE_SECOND_IP
&& argument != ITS_AN_INCLUCE) {
&& argument != ITS_A_RANGE_SECOND_IP && argument != ITS_AN_INCLUCE) {
newclause = true;
i = 0;
} 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. */
if (comment == true
|| (newclause == false
&& argument == ITS_NOTHING_INTERESTING)) {
if (comment == true || (newclause == false && argument == ITS_NOTHING_INTERESTING)) {
continue;
}
/* 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++;
if (RANGES < num_ranges + 1) {
RANGES *= 2;
ranges =
xrealloc(ranges,
sizeof(struct
range_t) * RANGES);
ranges = xrealloc(ranges, sizeof(struct range_t) * RANGES);
range_p = ranges + num_ranges;
}
newclause = true;
@ -393,8 +387,7 @@ if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
case ITS_A_SHAREDNET:
/* printf ("shared-network named: %s\n", word); */
num_shared_networks++;
shared_p =
shared_networks + num_shared_networks;
shared_p = shared_networks + num_shared_networks;
shared_p->name = xstrdup(word);
shared_p->available = 0;
shared_p->used = 0;

View file

@ -47,7 +47,8 @@
/*! \brief Add a lease to hash array.
* \param addr Binary IP to be added in leases hash.
* \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.
* \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;
}

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 src Sourse of an IP address. */
void copy_ipaddr_init(union ipaddr_t *restrict dst __attribute__((unused)),
const union ipaddr_t *restrict src __attribute__((unused)))
void copy_ipaddr_init(union ipaddr_t *restrict dst __attribute__ ((unused)),
const union ipaddr_t *restrict src __attribute__ ((unused)))
{
}
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)
{
dst->v4 = src->v4;
}
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)
{
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.
* \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';
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)
{
static char
buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
static char buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
struct in6_addr addr;
memcpy(addr.s6_addr, ip->v6, sizeof(addr.s6_addr));
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.
* \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;
}
@ -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 tmp_ranges Temporary memory area for the flip. */
void flip_ranges(struct range_t *restrict flip_me,
struct range_t *restrict tmp_ranges)
void flip_ranges(struct range_t *restrict flip_me, struct range_t *restrict tmp_ranges)
{
unsigned int i = num_ranges - 1, j;

View file

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

View file

@ -54,14 +54,13 @@
* \param b Binary IP address.
* \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)),
const union ipaddr_t *restrict b __attribute__((unused)))
int ipcomp_init(const union ipaddr_t *restrict a __attribute__ ((unused)),
const union ipaddr_t *restrict b __attribute__ ((unused)))
{
return 0;
}
int ipcomp_v4(const union ipaddr_t *restrict a,
const union ipaddr_t *restrict b)
int ipcomp_v4(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
{
if (a->v4 < b->v4)
return -1;
@ -70,8 +69,7 @@ int ipcomp_v4(const union ipaddr_t *restrict a,
return 0;
}
int ipcomp_v6(const union ipaddr_t *restrict a,
const union ipaddr_t *restrict b)
int ipcomp_v6(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
{
return memcmp(&a->v6, &b->v6, sizeof(a->v6));
}
@ -215,8 +213,7 @@ comparer_t field_selector(char c)
default:
clean_up();
warnx("field_selector: unknown sort order `%c'", c);
errx(EXIT_FAILURE, "Try `%s --help' for more information.",
program_name);
errx(EXIT_FAILURE, "Try `%s --help' for more information.", program_name);
}
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++) {
/* Handling strings is case of it's own */
if (config.sort[i] == 'n') {
ret =
strcmp(left->shared_net->name,
right->shared_net->name);
ret = strcmp(left->shared_net->name, right->shared_net->name);
if (0 < ret)
return (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
* flipped.
*/
void mergesort_ranges(struct range_t *restrict orig, int size,
struct range_t *restrict temp)
void mergesort_ranges(struct range_t *restrict orig, int size, struct range_t *restrict temp)
{
int left, right, i;
struct range_t hold;