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);
105 free(shared_networks);
108 void print_version(void)
110 fprintf(stdout, "%s\n", PACKAGE_STRING);
112 "Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
114 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
116 "This is free software: you are free to change and redistribute it.\n");
118 "There is NO WARRANTY, to the extent permitted by law.\n");
122 void usage(int status)
125 out = status != 0 ? stderr : stdout;
128 Usage: %s [OPTIONS]\n\n", program_invocation_short_name);
130 This is ISC dhcpd pools usage analyzer.\n\
133 -c, --config=FILE path to the dhcpd.conf file\n\
134 -l, --leases=FILE path to the dhcpd.leases file\n\
135 -f, --format=[thHcxX] output format\n");
139 H for full html page\n\
141 X for xml with active lease details\n\
142 c for comma separated values\n");
144 -s, --sort=[nimcptTe] sort ranges by\n\
154 -r, --reverse reverse order sort\n\
155 -o, --output=FILE output into a file\n\
156 -L, --limit=NR output limit mask 77 - 00\n\
157 -v, --version version information\n\
158 -h, --help this screen\n\
160 Report bugs to <%s>\n\
161 Homepage: %s\n", PACKAGE_BUGREPORT, PACKAGE_URL);
163 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);