1 /* http://dhcpd-pools.sourceforge.net/
2 ** Copyright 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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "dhcpd-pools.h"
27 #else /* Not STDC_HEADERS */
29 extern char *malloc();
30 #endif /* STDC_HEADERS */
40 /* Simple memory allocation wrapper */
41 void *safe_malloc(const size_t size)
43 void *ret = malloc(size);
46 "safe_malloc: cannot allocate %lu bytes: ", size);
52 /* Simple memory reallocation wrapper */
53 void *safe_realloc(void *ptr, const size_t size)
55 void *ret = realloc(ptr, size);
59 "safe_realloc: cannot allocate %zu bytes", size);
63 /* Simple strdup wrapper */
64 char *safe_strdup(const char *str)
66 char *ret = strdup(str);
69 err(EXIT_FAILURE, "cannot duplicate string");
73 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
75 unsigned int i = num_ranges - 1, j;
77 for (j = 0; j < num_ranges; j++) {
78 *(tmp_ranges + j) = *(ranges + i);
82 memcpy(ranges, tmp_ranges, num_ranges * sizeof(struct range_t));
85 /* Free memory, flush buffers etc */
90 /* Just in case there something in buffers */
92 warn("clean_up: fflush");
94 num_shared_networks++;
95 for (i = 0; i < num_shared_networks; i++) {
96 free((shared_networks + i)->name);
98 free(config.dhcpdconf_file);
99 free(config.dhcpdlease_file);
100 free(config.output_file);
104 free(shared_networks);
107 void print_version(void)
109 fprintf(stdout, "%s\n", PACKAGE_STRING);
111 "Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
113 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
115 "This is free software: you are free to change and redistribute it.\n");
117 "There is NO WARRANTY, to the extent permitted by law.\n");
121 void usage(int status)
124 out = status != 0 ? stderr : stdout;
127 Usage: %s [OPTIONS]\n", program_invocation_short_name);
129 This is ISC dhcpd pools usage analyzer.\n\
132 -c --config file path to the dhcpd.conf file\n\
133 -l --leases file path to the dhcpd.leases file\n\
134 -f --format [thcxX] output format\n");
138 H for full html page\n\
140 X for xml with active lease details\n\
141 c for comma separated values\n");
143 -s --sort [nimcptTe] sort ranges by\n\
153 -r --reverse reverse order sort\n\
154 -o --output file output into a file\n\
155 -L --limit nr output limit mask 77 - 00\n\
156 -v --version version information\n\
157 -h --help this screen\n\
159 Report bugs to <%s>\n\
160 Homepage: %s\n", PACKAGE_BUGREPORT, PACKAGE_URL);
162 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);