maint: coding style fixes

Remove unnecessary type casting, move .gitignore file contents to
right location, reindent to use Linux coding style, fix few type
mismatches, clean up to help & version output and hint compiler
call to these functions will end program.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-07-08 20:49:49 +02:00
parent 68c2d7b8cc
commit 76915512b2
10 changed files with 148 additions and 189 deletions

5
.gitignore vendored
View file

@ -21,8 +21,5 @@ Makefile.in
man/Makefile
man/Makefile.in
missing
src/.deps/
src/Makefile
src/Makefile.in
src/*.o
stamp-h1
tags

6
src/.gitignore vendored
View file

@ -1 +1,7 @@
*~
*.o
.deps/
dhcpd-pools
Makefile
Makefile.in
tags

View file

@ -73,8 +73,7 @@ int prepare_data(void)
qsort(touches, (size_t) num_touches, sizeof(uint32_t), &intcomp);
/* Sort ranges */
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t),
&rangecomp);
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t), &rangecomp);
/* Sort backups */
if (0 < num_backups) {
@ -89,15 +88,14 @@ int prepare_data(void)
int do_counting(void)
{
struct range_t *range_p;
unsigned int i, j, k, l, block_size;
unsigned long i, j, k, l, block_size;
range_p = ranges;
/* Walk through ranges */
for (i = j = k = l = 0; i < num_ranges; i++) {
/* Count IPs in use */
for (; leases[j] < range_p->last_ip
&& (unsigned long) j < num_leases; j++) {
for (; leases[j] < range_p->last_ip && j < num_leases; j++) {
if (leases[j] < range_p->first_ip) {
continue;
}
@ -109,8 +107,7 @@ int do_counting(void)
}
/* Count touched IPs */
for (; touches[k] < range_p->last_ip
&& (unsigned long) k < num_touches; k++) {
for (; touches[k] < range_p->last_ip && k < num_touches; k++) {
if (touches[k] < range_p->first_ip) {
continue;
}
@ -124,7 +121,7 @@ int do_counting(void)
/* Count backup IPs */
if (0 < num_backups) {
for (; backups[l] < range_p->last_ip
&& (unsigned long) l < num_touches; l++) {
&& l < num_touches; l++) {
if (touches[l] < range_p->first_ip) {
continue;
}
@ -138,8 +135,7 @@ int do_counting(void)
/* Size of range, shared net & all networks */
block_size =
(unsigned int) (range_p->last_ip - range_p->first_ip -
1);
(unsigned int)(range_p->last_ip - range_p->first_ip - 1);
if (range_p->shared_net) {
range_p->shared_net->available += block_size;
}

View file

@ -37,7 +37,7 @@
# define DEFAULTS_H 1
/* Maximum line length in dhcpd.conf and dhcpd.leases */
static const int MAXLEN = 1024;
static const size_t MAXLEN = 1024;
/* Maximum number of shared networks */
static const unsigned int SHARED_NETWORKS = 8192;

View file

@ -64,16 +64,16 @@ int main(int argc, char **argv)
/* Options for getopt_long */
static struct option const long_options[] = {
{"config", required_argument, 0, (int) 'c'},
{"leases", required_argument, 0, (int) 'l'},
{"format", required_argument, 0, (int) 'f'},
{"sort", required_argument, 0, (int) 's'},
{"reverse", no_argument, 0, (int) 'r'},
{"output", required_argument, 0, (int) 'o'},
{"limit", required_argument, 0, (int) 'L'},
{"version", no_argument, 0, (int) 'v'},
{"help", no_argument, 0, (int) 'h'},
{0, 0, 0, 0}
{"config", required_argument, NULL, 'c'},
{"leases", required_argument, NULL, 'l'},
{"format", required_argument, NULL, 'f'},
{"sort", required_argument, NULL, 's'},
{"reverse", no_argument, NULL, 'r'},
{"output", required_argument, NULL, 'o'},
{"limit", required_argument, NULL, 'L'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
/* FIXME: make these allocations dynamic up on need. */
@ -86,14 +86,12 @@ int main(int argc, char **argv)
config.output_file[0] = '\0';
/* File location defaults */
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE,
(size_t) MAXLEN - 1);
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE,
(size_t) MAXLEN - 1);
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1);
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1);
tmp = OUTPUT_LIMIT;
config.output_limit[0] = (int) (*tmp - '0');
config.output_limit[0] = (*tmp - '0');
tmp++;
config.output_limit[1] = (int) (*tmp - '0');
config.output_limit[1] = (*tmp - '0');
fullhtml = false;
/* Make sure some output format is selected by default */
@ -113,13 +111,11 @@ int main(int argc, char **argv)
switch (c) {
case 'c':
/* config file */
strncpy(config.dhcpdconf_file, optarg,
(size_t) MAXLEN - 1);
strncpy(config.dhcpdconf_file, optarg, MAXLEN - 1);
break;
case 'l':
/* lease file */
strncpy(config.dhcpdlease_file, optarg,
(size_t) MAXLEN - 1);
strncpy(config.dhcpdlease_file, optarg, MAXLEN - 1);
break;
case 'f':
/* Output format */
@ -134,8 +130,7 @@ int main(int argc, char **argv)
strncpy(config.sort, optarg, (size_t) 5);
sorts = 5;
} else {
strncpy(config.sort, optarg,
(size_t) sorts);
strncpy(config.sort, optarg, (size_t) sorts);
}
for (i = 0; i < sorts; i++) {
field_selector(config.sort[i]);
@ -147,15 +142,14 @@ int main(int argc, char **argv)
break;
case 'o':
/* Output file */
strncpy(config.output_file, optarg,
(size_t) MAXLEN - 1);
strncpy(config.output_file, optarg, MAXLEN - 1);
break;
case 'L':
/* Specification what will be printed */
for (i = 0; i < 2; i++) {
if (optarg[i] >= '0' && optarg[i] < '8') {
config.output_limit[i] =
(int) optarg[i] - '0';
optarg[i] - '0';
} else {
errx(EXIT_FAILURE,
"main: output mask `%s' is illegal",

View file

@ -65,8 +65,8 @@ extern char *__progname;
# define program_invocation_short_name \
prog_inv_sh_nm_from_file(__FILE__, 1)
# endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
static char prog_inv_sh_nm_buf[256];
static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
char prog_inv_sh_nm_buf[256];
inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
{
char *t;
if ((t = strrchr(f, '/')) != NULL) {
@ -119,29 +119,21 @@ struct macaddr_t {
/* Global variables */
static int const true = 1;
static int const false = 0;
struct configuration_t config;
static int const output_limit_bit_1 = 1;
static int const output_limit_bit_2 = 2;
static int const output_limit_bit_3 = 4;
unsigned int fullhtml;
struct shared_network_t *shared_networks;
unsigned int num_shared_networks;
struct range_t *ranges;
unsigned int num_ranges;
uint32_t *leases;
unsigned long int num_leases;
uint32_t *touches;
unsigned long int num_touches;
uint32_t *backups;
unsigned long int num_backups;
struct macaddr_t *macaddr;
/* Function prototypes */
@ -159,7 +151,7 @@ int prepare_data(void);
int do_counting(void);
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
__attribute__ ((nonnull(1, 2)));
/* General support functions */
/* support functions */
void *safe_malloc(const size_t size)
#if __GNUC__ >= 3
__attribute__ ((__malloc__))

View file

@ -86,18 +86,17 @@ int parse_leases(void)
dhcpd_leases = fopen(config.dhcpdlease_file, "r");
if (dhcpd_leases == NULL) {
err(EXIT_FAILURE, "parse_leases: %s",
config.dhcpdlease_file);
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
}
#ifdef POSIX_FADV_WILLNEED
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_WILLNEED);
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED);
if (errno) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
}
#endif /* POSIX_FADV_WILLNEED */
#ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL);
if (errno) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
@ -109,15 +108,13 @@ int parse_leases(void)
* If someone has higher density in lease file I'm interested to
* hear about that. */
if (stat(config.dhcpdlease_file, &lease_file_stats)) {
err(EXIT_FAILURE, "parse_leases: %s",
config.dhcpdlease_file);
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
}
leasesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
touchesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
backupsmallocsize = (lease_file_stats.st_size / 120) + MAXLEN - 2;
leases = safe_malloc(sizeof(long int) * leasesmallocsize);
touches =
safe_malloc((size_t) sizeof(long int) * touchesmallocsize);
touches = safe_malloc((size_t) sizeof(long int) * touchesmallocsize);
memset(leases, 0, sizeof(long int) * leasesmallocsize);
memset(touches, 0, sizeof(long int) * touchesmallocsize);
@ -133,11 +130,12 @@ 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);
}
/* It's a lease, save IP */
if (strstr(line, "lease") == line) {
strncpy(ipstring, line, (size_t) MAXLEN);
strncpy(ipstring, line, MAXLEN);
nth_field(2, ipstring, ipstring);
inet_aton(ipstring, &inp);
sw_active_lease = 0;
@ -187,8 +185,7 @@ int parse_leases(void)
macstring[17] = '\0';
macaddr_p->ethernet = safe_strdup(macstring);
macaddr_p->ip = safe_strdup(ipstring);
macaddr_p->next =
safe_malloc(sizeof(struct macaddr_t));
macaddr_p->next = safe_malloc(sizeof(struct macaddr_t));
macaddr_p = macaddr_p->next;
macaddr_p->next = NULL;
}
@ -251,8 +248,9 @@ void parse_config(int is_include, char *config_file,
struct shared_network_t *shared_p)
{
FILE *dhcpd_config;
int i = 0, newclause = true, argument = false, comment =
int newclause = true, argument = false, comment =
false, braces = 0, quote = false;
size_t i = 0;
char *word, c;
int braces_shared = 1000;
struct in_addr inp;
@ -271,13 +269,13 @@ void parse_config(int is_include, char *config_file,
err(EXIT_FAILURE, "parse_config: %s", config_file);
}
#ifdef POSIX_FADV_WILLNEED
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_WILLNEED);
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_WILLNEED);
if (errno) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
#endif /* POSIX_FADV_WILLNEED */
#ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL);
if (errno) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
@ -313,8 +311,7 @@ void parse_config(int is_include, char *config_file,
if (quote == true) {
break;
}
if (comment == false && argument != 2
&& argument != 4) {
if (comment == false && argument != 2 && argument != 4) {
newclause = true;
i = 0;
} else if (argument == 2) {
@ -364,8 +361,7 @@ void parse_config(int is_include, char *config_file,
}
/* Either inside comment or Nth word of clause. */
if (comment == true
|| (newclause == false && argument == 0)) {
if (comment == true || (newclause == false && argument == 0)) {
continue;
}
/* Strip white spaces before new clause word. */
@ -446,8 +442,7 @@ void parse_config(int is_include, char *config_file,
shared_p->used = 0;
shared_p->touched = 0;
shared_p->backups = 0;
if (SHARED_NETWORKS <
num_shared_networks + 2) {
if (SHARED_NETWORKS < num_shared_networks + 2) {
/* FIXME: make this
* away by reallocationg
* more space. */

View file

@ -123,38 +123,35 @@ void clean_up(void)
free(shared_networks);
}
void print_version(void)
void __attribute__ ((__noreturn__)) print_version(void)
{
fprintf(stdout, "%s\n", PACKAGE_STRING);
fprintf(stdout,
"Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
fprintf(stdout,
"The software has FreeBSD License.\n");
fprintf(stdout, "%s\n"
"Written by Sami Kerola.\n"
"XML support by Dominic Germain, Sogetel inc.\n\n"
"The software has FreeBSD License.\n", PACKAGE_STRING);
exit(EXIT_SUCCESS);
}
void usage(int status)
void __attribute__ ((__noreturn__)) usage(int status)
{
FILE *out;
out = status != 0 ? stderr : stdout;
fprintf(out, "\n\
fprintf(out, "\
Usage: %s [OPTIONS]\n\n", program_invocation_short_name);
fprintf(out, "\
This is ISC dhcpd pools usage analyzer.\n\
\n");
fprintf(out, "\
\n\
-c, --config=FILE path to the dhcpd.conf file\n\
-l, --leases=FILE path to the dhcpd.leases file\n\
-f, --format=[thHcxX] output format\n");
fprintf(out, "\
-f, --format=[thHcxX] output format\n\
t for text\n\
h for html table\n\
H for full html page\n\
x for xml\n\
X for xml with active lease details\n\
c for comma separated values\n");
fprintf(out, "\
c for comma separated values\n\
-s, --sort=[nimcptTe] sort ranges by\n\
n name\n\
i IP\n\
@ -163,8 +160,7 @@ This is ISC dhcpd pools usage analyzer.\n\
p percent\n\
t touched\n\
T t+c\n\
e t+c perc\n");
fprintf(out, "\
e t+c perc\n\
-r, --reverse reverse order sort\n\
-o, --output=FILE output into a file\n\
-L, --limit=NR output limit mask 77 - 00\n\

View file

@ -58,8 +58,7 @@ int output_txt(void)
if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+");
if (outfile == NULL) {
err(EXIT_FAILURE, "output_txt: %s",
config.output_file);
err(EXIT_FAILURE, "output_txt: %s", config.output_file);
}
} else {
outfile = stdout;
@ -91,23 +90,24 @@ int output_txt(void)
}
fprintf(outfile, "%-16s", inet_ntoa(first));
fprintf(outfile,
" - %-16s %5"PRIu32" %5lu %10.3f %5lu %5lu %9.3f",
" - %-16s %5" PRIu32
" %5lu %10.3f %5lu %5lu %9.3f",
inet_ntoa(last),
range_p->last_ip - range_p->first_ip - 1,
range_p->count,
(float) (100 * range_p->count) /
(float)(100 * range_p->count) /
(range_p->last_ip - range_p->first_ip - 1),
range_p->touched,
range_p->touched + range_p->count,
(float) (100 *
(range_p->touched +
range_p->count)) /
(range_p->last_ip - range_p->first_ip -
1));
(float)(100 *
(range_p->touched +
range_p->count)) / (range_p->last_ip -
range_p->first_ip -
1));
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
range_p->backups,
(float) (100 * range_p->backups) /
(float)(100 * range_p->backups) /
(range_p->last_ip -
range_p->first_ip - 1));
}
@ -135,17 +135,17 @@ int output_txt(void)
"%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
shared_p->name, shared_p->available,
shared_p->used,
(float) (100 * shared_p->used) /
(float)(100 * shared_p->used) /
shared_p->available, shared_p->touched,
shared_p->touched + shared_p->used,
(float) (100 *
(shared_p->touched +
shared_p->used)) /
(float)(100 *
(shared_p->touched +
shared_p->used)) /
shared_p->available);
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
shared_p->backups,
(float) (100 * shared_p->backups) /
(float)(100 * shared_p->backups) /
shared_p->available);
}
@ -171,19 +171,19 @@ int output_txt(void)
shared_networks->name,
shared_networks->available,
shared_networks->used,
(float) (100 * shared_networks->used) /
(float)(100 * shared_networks->used) /
shared_networks->available,
shared_networks->touched,
shared_networks->touched + shared_networks->used,
(float) (100 *
(shared_networks->touched +
shared_networks->used)) /
(float)(100 *
(shared_networks->touched +
shared_networks->used)) /
shared_networks->available);
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
shared_networks->backups,
(float) (100 * shared_networks->backups) /
(float)(100 * shared_networks->backups) /
shared_networks->available);
}
fprintf(outfile, "\n");
@ -216,8 +216,7 @@ int output_xml(void)
if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+");
if (outfile == NULL) {
err(EXIT_FAILURE, "output_xml: %s",
config.output_file);
err(EXIT_FAILURE, "output_xml: %s", config.output_file);
}
} else {
outfile = stdout;
@ -247,17 +246,15 @@ int output_xml(void)
"\t<location>%s</location>\n",
range_p->shared_net->name);
} else {
fprintf(outfile,
"\t<location></location>\n");
fprintf(outfile, "\t<location></location>\n");
}
fprintf(outfile, "\t<network></network>\n");
fprintf(outfile, "\t<netmask></netmask>\n");
fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
fprintf(outfile, "- %s</range>\n",
inet_ntoa(last));
fprintf(outfile, "- %s</range>\n", inet_ntoa(last));
fprintf(outfile, "\t<gateway></gateway>\n");
fprintf(outfile, "\t<defined>%"PRIu32"</defined>\n",
fprintf(outfile, "\t<defined>%" PRIu32 "</defined>\n",
range_p->last_ip - range_p->first_ip - 1);
fprintf(outfile, "\t<used>%lu</used>\n",
range_p->count);
@ -291,11 +288,9 @@ int output_xml(void)
shared_networks->name);
fprintf(outfile, "\t<defined>%lu</defined>\n",
shared_networks->available);
fprintf(outfile, "\t<used>%lu</used>\n",
shared_networks->used);
fprintf(outfile, "\t<used>%lu</used>\n", shared_networks->used);
fprintf(outfile, "\t<free>%lu</free>\n",
shared_networks->available -
shared_networks->used);
shared_networks->available - shared_networks->used);
fprintf(outfile, "</summary>\n");
}
@ -317,8 +312,7 @@ int output_xml(void)
void html_header(FILE * f)
{
fprintf(f,
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
fprintf(f, " \"http://www.w3.org/TR/html4/strict.dtd\">\n");
fprintf(f, "<html>\n");
fprintf(f, "<head>\n");
@ -381,7 +375,7 @@ void html_footer(FILE * f)
fprintf(f, "<hr>\n");
fprintf(f, "<p class=created>\nData generated by ");
fprintf(f, "<a href=\"%s\">", PACKAGE_URL);
fprintf(f, "dhcpd-pools</a>.\n</p>\n");
fprintf(f, "%s</a>.\n</p>\n", PACKAGE_NAME);
fprintf(f, "<p class=updated>\n");
fprintf(f, "<script type=\"text/javascript\">\n");
fprintf(f, " document.write(\"Last Updated On \" + ");
@ -419,7 +413,7 @@ void output_float(FILE * f, char *type, float fl)
void table_start(FILE * f)
{
fprintf(f, "<table width=\"75%%\" ");
fprintf(f, "class=\"dhcpd-pools\" ");
fprintf(f, "class=\"%s\" ", PACKAGE_NAME);
fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
}
@ -492,33 +486,29 @@ int output_html(void)
output_line(outfile, "td", "calign",
"not_defined");
}
output_line(outfile, "td", "calign",
inet_ntoa(first));
output_line(outfile, "td", "calign",
inet_ntoa(last));
output_line(outfile, "td", "calign", inet_ntoa(first));
output_line(outfile, "td", "calign", inet_ntoa(last));
output_long(outfile, "td",
range_p->last_ip - range_p->first_ip -
1);
range_p->last_ip - range_p->first_ip - 1);
output_long(outfile, "td", range_p->count);
output_float(outfile, "td",
(float) (100 * range_p->count) /
(float)(100 * range_p->count) /
(range_p->last_ip -
range_p->first_ip - 1));
output_long(outfile, "td", range_p->touched);
output_long(outfile, "td",
range_p->touched + range_p->count);
output_float(outfile, "td",
(float) (100 *
(range_p->touched +
range_p->count)) /
(float)(100 *
(range_p->touched +
range_p->count)) /
(range_p->last_ip -
range_p->first_ip - 1));
if (0 < num_backups) {
output_long(outfile, "td",
range_p->backups);
output_long(outfile, "td", range_p->backups);
output_float(outfile, "td",
(float) (100 *
range_p->backups) /
(float)(100 *
range_p->backups) /
(range_p->last_ip -
range_p->first_ip - 1));
}
@ -548,27 +538,25 @@ int output_html(void)
for (i = 0; i < num_shared_networks; i++) {
shared_p++;
newrow(outfile);
output_line(outfile, "td", "calign",
shared_p->name);
output_line(outfile, "td", "calign", shared_p->name);
output_long(outfile, "td", shared_p->available);
output_long(outfile, "td", shared_p->used);
output_float(outfile, "td",
(float) (100 * shared_p->used) /
(float)(100 * shared_p->used) /
shared_p->available);
output_long(outfile, "td", shared_p->touched);
output_long(outfile, "td",
shared_p->touched + shared_p->used);
output_float(outfile, "td",
(float) (100 *
(shared_p->touched +
shared_p->used)) /
(float)(100 *
(shared_p->touched +
shared_p->used)) /
shared_p->available);
if (0 < num_backups) {
output_long(outfile, "td",
shared_p->backups);
output_long(outfile, "td", shared_p->backups);
output_float(outfile, "td",
(float) (100 *
shared_p->backups) /
(float)(100 *
shared_p->backups) /
shared_p->available);
}
@ -594,28 +582,25 @@ int output_html(void)
}
if (config.output_limit[1] & output_limit_bit_3) {
newrow(outfile);
output_line(outfile, "td", "calign",
shared_networks->name);
output_line(outfile, "td", "calign", shared_networks->name);
output_long(outfile, "td", shared_networks->available);
output_long(outfile, "td", shared_networks->used);
output_float(outfile, "td",
(float) (100 * shared_networks->used) /
(float)(100 * shared_networks->used) /
shared_networks->available);
output_long(outfile, "td", shared_networks->touched);
output_long(outfile, "td",
shared_networks->touched +
shared_networks->used);
shared_networks->touched + shared_networks->used);
output_float(outfile, "td",
(float) (100 *
(shared_networks->touched +
shared_networks->used)) /
(float)(100 *
(shared_networks->touched +
shared_networks->used)) /
shared_networks->available);
if (0 < num_backups) {
output_long(outfile, "td",
shared_networks->backups);
output_long(outfile, "td", shared_networks->backups);
output_float(outfile, "td",
(float) (100 *
shared_networks->backups) /
(float)(100 *
shared_networks->backups) /
shared_networks->available);
}
endrow(outfile);
@ -649,8 +634,7 @@ int output_csv(void)
if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+");
if (outfile == NULL) {
err(EXIT_FAILURE, "output_csv: %s",
config.output_file);
err(EXIT_FAILURE, "output_csv: %s", config.output_file);
}
} else {
outfile = stdout;
@ -680,23 +664,24 @@ int output_csv(void)
}
fprintf(outfile, "\"%s\",", inet_ntoa(first));
fprintf(outfile,
"\"%s\",\"%"PRIu32"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
"\"%s\",\"%" PRIu32
"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
inet_ntoa(last),
range_p->last_ip - range_p->first_ip - 1,
range_p->count,
(float) (100 * range_p->count) /
(float)(100 * range_p->count) /
(range_p->last_ip - range_p->first_ip - 1),
range_p->touched,
range_p->touched + range_p->count,
(float) (100 *
(range_p->touched +
range_p->count)) /
(range_p->last_ip - range_p->first_ip -
1));
(float)(100 *
(range_p->touched +
range_p->count)) / (range_p->last_ip -
range_p->first_ip -
1));
if (0 < num_backups) {
fprintf(outfile, ",\"%lu\",\"%.3f\"",
range_p->backups,
(float) (100 * range_p->backups) /
(float)(100 * range_p->backups) /
(range_p->last_ip -
range_p->first_ip - 1));
}
@ -723,17 +708,17 @@ int output_csv(void)
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
shared_p->name, shared_p->available,
shared_p->used,
(float) (100 * shared_p->used) /
(float)(100 * shared_p->used) /
shared_p->available, shared_p->touched,
shared_p->touched + shared_p->used,
(float) (100 *
(shared_p->touched +
shared_p->used)) /
(float)(100 *
(shared_p->touched +
shared_p->used)) /
shared_p->available);
if (0 < num_backups) {
fprintf(outfile, ",\"%lu\",\"%.3f\"",
shared_p->backups,
(float) (100 * shared_p->backups) /
(float)(100 * shared_p->backups) /
shared_p->available);
}
@ -756,18 +741,18 @@ int output_csv(void)
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
shared_networks->name, shared_networks->available,
shared_networks->used,
(float) (100 * shared_networks->used) /
(float)(100 * shared_networks->used) /
shared_networks->available,
shared_networks->touched,
shared_networks->touched + shared_networks->used,
(float) (100 *
(shared_networks->touched +
shared_networks->used)) /
(float)(100 *
(shared_networks->touched +
shared_networks->used)) /
shared_networks->available);
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
shared_networks->backups,
(float) (100 * shared_networks->backups) /
(float)(100 * shared_networks->backups) /
shared_networks->available);
}
fprintf(outfile, "\n");
@ -777,13 +762,11 @@ int output_csv(void)
if (ret) {
warn("output_cvs: fflush");
}
} else {
ret = fclose(outfile);
if (ret) {
warn("output_cvs: fclose");
}
}
return 0;
}

View file

@ -56,11 +56,11 @@ int intcomp(const void *x, const void *y)
int rangecomp(const void *r1, const void *r2)
{
if ((((struct range_t *) r1)->first_ip) <
(((struct range_t *) r2)->first_ip))
if ((((struct range_t *)r1)->first_ip) <
(((struct range_t *)r2)->first_ip))
return -1;
else if ((((struct range_t *) r2)->first_ip) <
(((struct range_t *) r1)->first_ip))
else if ((((struct range_t *)r2)->first_ip) <
(((struct range_t *)r1)->first_ip))
return 1;
else
return 0;
@ -84,8 +84,8 @@ unsigned long int ret_max(struct range_t r)
unsigned long int ret_percent(struct range_t r)
{
float f;
f = (float) r.count / (r.last_ip - r.first_ip - 1);
return ((unsigned long int) (f * 100000));
f = (float)r.count / (r.last_ip - r.first_ip - 1);
return ((unsigned long int)(f * 100000));
}
unsigned long int ret_touched(struct range_t r)
@ -101,8 +101,8 @@ unsigned long int ret_tc(struct range_t r)
unsigned long int ret_tcperc(struct range_t r)
{
float f;
f = (float) (r.count + r.touched) / (r.last_ip - r.first_ip - 1);
return ((unsigned long int) (f * 10000));
f = (float)(r.count + r.touched) / (r.last_ip - r.first_ip - 1);
return ((unsigned long int)(f * 10000));
}
void field_selector(char c)