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);
47 "safe_malloc: cannot allocate %lu bytes: ", size);
53 /* Simple strdup wrapper */
54 char *safe_strdup(const char *str)
56 char *ret = strdup(str);
59 err(EXIT_FAILURE, "cannot duplicate string");
63 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
65 unsigned int i = num_ranges - 1, j;
67 for (j = 0; j < num_ranges; j++) {
68 *(tmp_ranges + j) = *(ranges + i);
72 memcpy(ranges, tmp_ranges, num_ranges * sizeof(struct range_t));
75 /* Free memory, flush buffers etc */
81 warn("clean_up: errno (%d) set but not checked in correct place.\nif this is repeatable send strace output as a bug report", errno);
83 /* Just in case there something in buffers */
86 warn("clean_up: stdout");
90 warn("clean_up: stderr");
93 free(config.dhcpdconf_file);
94 free(config.dhcpdlease_file);
95 free(config.output_file);
97 free(shared_net_names);
98 free(shared_networks);
101 void print_version(void)
103 fprintf(stdout, "%s\n", PACKAGE_STRING);
105 "Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
107 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
109 "This is free software: you are free to change and redistribute it.\n");
111 "There is NO WARRANTY, to the extent permitted by law.\n");
115 void usage(int status)
118 out = status != 0 ? stderr : stdout;
121 Usage: %s [OPTIONS]\n", program_invocation_short_name);
123 This is ISC dhcpd pools usage analyzer.\n\
126 -c --config file path to the dhcpd.conf file\n\
127 -l --leases file path to the dhcpd.leases file\n\
128 -f --format [thcxX] output format\n");
132 H for full html page\n\
134 X for xml with active lease details\n\
135 c for comma separated values\n");
137 -s --sort [nimcptTe] sort ranges by\n\
147 -r --reverse reverse order sort\n\
148 -o --output file output into a file\n\
149 -L --limit nr output limit mask 77 - 00\n\
150 -v --version version information\n\
151 -h --help this screen\n\
153 Report bugs to <%s>\n\
154 Homepage: %s\n", PACKAGE_BUGREPORT, PACKAGE_URL);
156 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);