2 * The dhcpd-pools has BSD 2-clause license which also known as "Simplified
3 * BSD License" or "FreeBSD License".
5 * Copyright 2006- Sami Kerola. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
19 * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGE.
31 * The views and conclusions contained in the software and documentation are
32 * those of the authors and should not be interpreted as representing
33 * official policies, either expressed or implied, of Sami Kerola.
40 #include "dhcpd-pools.h"
45 #else /* Not STDC_HEADERS */
47 extern char *malloc();
48 #endif /* STDC_HEADERS */
58 /* Simple memory allocation wrapper */
59 void *safe_malloc(const size_t size)
61 void *ret = malloc(size);
64 "safe_malloc: cannot allocate %lu bytes: ", size);
70 /* Simple memory reallocation wrapper */
71 void *safe_realloc(void *ptr, const size_t size)
73 void *ret = realloc(ptr, size);
77 "safe_realloc: cannot allocate %zu bytes", size);
81 /* Simple strdup wrapper */
82 char *safe_strdup(const char *str)
84 char *ret = strdup(str);
87 err(EXIT_FAILURE, "cannot duplicate string");
91 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
93 unsigned int i = num_ranges - 1, j;
95 for (j = 0; j < num_ranges; j++) {
96 *(tmp_ranges + j) = *(ranges + i);
100 memcpy(ranges, tmp_ranges, num_ranges * sizeof(struct range_t));
103 /* Free memory, flush buffers etc */
108 /* Just in case there something in buffers */
110 warn("clean_up: fflush");
112 num_shared_networks++;
113 for (i = 0; i < num_shared_networks; i++) {
114 free((shared_networks + i)->name);
116 free(config.dhcpdconf_file);
117 free(config.dhcpdlease_file);
118 free(config.output_file);
123 free(shared_networks);
126 void print_version(void)
128 fprintf(stdout, "%s\n", PACKAGE_STRING);
130 "Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
132 "The software has FreeBSD License.\n");
136 void usage(int status)
139 out = status != 0 ? stderr : stdout;
142 Usage: %s [OPTIONS]\n\n", program_invocation_short_name);
144 This is ISC dhcpd pools usage analyzer.\n\
147 -c, --config=FILE path to the dhcpd.conf file\n\
148 -l, --leases=FILE path to the dhcpd.leases file\n\
149 -f, --format=[thHcxX] output format\n");
153 H for full html page\n\
155 X for xml with active lease details\n\
156 c for comma separated values\n");
158 -s, --sort=[nimcptTe] sort ranges by\n\
168 -r, --reverse reverse order sort\n\
169 -o, --output=FILE output into a file\n\
170 -L, --limit=NR output limit mask 77 - 00\n\
171 -v, --version version information\n\
172 -h, --help this screen\n\
174 Report bugs to <%s>\n\
175 Homepage: %s\n", PACKAGE_BUGREPORT, PACKAGE_URL);
177 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);