2 ** Copyright (C) 2006- Sami Kerola <kerolasa@iki.fi>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "dhcpd-pools.h"
28 #else /* Not STDC_HEADERS */
30 extern char *malloc();
31 #endif /* STDC_HEADERS */
40 /* Simple memory allocation wrapper */
41 void *safe_malloc(size_t size)
43 void *ret = malloc(size);
45 eprintf("safe_malloc: malloc: ");
51 /* Copyright (C) 1999 Lucent Technologies
52 * Excerpted from 'The Practice of Programming'
53 * by Brian W. Kernighan and Rob Pike
54 * slight modifications by Sami Kerola.
55 * eprintf: print error message and exit */
56 void eprintf(char *fmt, ...)
61 fprintf(stderr, "%s: ", program_name);
64 vfprintf(stderr, fmt, args);
67 if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':')
68 fprintf(stderr, " %s", strerror(errno));
69 /* Should be safe, after all dhcpd-pools has only one
73 fprintf(stderr, "\n");
77 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
79 unsigned int i = num_ranges - 1, j;
81 for (j = 0; j < num_ranges; j++) {
82 *(tmp_ranges + j) = *(ranges + i);
86 memcpy(ranges, tmp_ranges, num_ranges * sizeof(struct range_t));
90 /* Free memory, flush buffers etc */
96 ("clean_up: errno (%d) set but not checked in correct place; if this is repeatable send strace output as a bug report:",
99 /* Just in case there something in buffers */
100 ret = fflush(stdout);
102 eprintf("clean_up: stdout:");
104 ret = fflush(stderr);
106 eprintf("clean_up: stderr:");
108 free(config.dhcpdconf_file);
109 free(config.dhcpdlease_file);
110 free(config.output_file);
112 free(shared_net_names);
113 free(shared_networks);
116 void print_version(void)
118 fprintf(stdout, "%s\n", PACKAGE_STRING);
120 "Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
122 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
124 "This is free software: you are free to change and redistribute it.\n");
126 "There is NO WARRANTY, to the extent permitted by law.\n");
129 void usage(int status)
132 out = status != 0 ? stderr : stdout;
135 Usage: %s [OPTIONS]\n", program_name);
137 This is ISC dhcpd pools usage analyzer.\n\
140 -c --config file path to the dhcpd.conf file\n\
141 -l --leases file path to the dhcpd.leases file\n\
142 -f --format [thcxX] output format\n");
146 H for full html page\n\
148 X for xml with active lease details\n\
149 c for comma separated values\n");
154 -s --sort [nimcptTe] sort ranges by\n\
164 -r --reverse reverse order sort\n\
165 -o --output file output into a file\n\
166 -L --limit nr output limit mask 77 - 00\n\
167 -v --version version information\n\
168 -h --help this screen\n\
170 Report bugs to <%s>\n\
171 Homepage: %s\n", PACKAGE_BUGREPORT, PACKAGE_URL);
173 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);