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/>.
19 # define DHCPD_POOLS_H 1
24 /* Feature test switches */
25 #define _POSIX_SOURCE 1
26 #define POSIXLY_CORRECT 1
31 extern char *malloc();
32 #define EXIT_FAILURE 1
33 #define EXIT_SUCCESS 0
34 #endif /* STDC_HEADERS */
36 #ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
37 # ifdef HAVE___PROGNAME
38 extern char *__progname;
39 # define program_invocation_short_name __progname
40 # else /* HAVE___PROGNAME */
41 # ifdef HAVE_GETEXECNAME
43 # define program_invocation_short_name \
44 prog_inv_sh_nm_from_file(getexecname(), 0)
45 # else /* HAVE_GETEXECNAME */
46 # define program_invocation_short_name \
47 prog_inv_sh_nm_from_file(__FILE__, 1)
48 # endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
49 static char prog_inv_sh_nm_buf[256];
50 static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
53 if ((t = strrchr(f, '/')) != NULL) {
58 strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
59 prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
61 if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) {
64 return prog_inv_sh_nm_buf;
69 /* Structures and unions */
70 struct configuration_t {
72 char *dhcpdlease_file;
73 char output_format[2];
79 struct shared_network_t {
81 unsigned long int available;
82 unsigned long int used;
83 unsigned long int touched;
84 unsigned long int backups;
87 struct shared_network_t *shared_net;
88 unsigned long int first_ip;
89 unsigned long int last_ip;
90 unsigned long int count;
91 unsigned long int touched;
92 unsigned long int backups;
97 struct macaddr_t *next;
100 /* Global variables */
101 static int const true = 1;
102 static int const false = 0;
104 struct configuration_t config;
106 static int const output_limit_bit_1 = 1;
107 static int const output_limit_bit_2 = 2;
108 static int const output_limit_bit_3 = 4;
109 unsigned int fullhtml;
111 struct shared_network_t *shared_networks;
112 unsigned int num_shared_networks;
114 struct range_t *ranges;
115 unsigned int num_ranges;
117 unsigned long int *leases;
118 unsigned long int num_leases;
120 unsigned long int *touches;
121 unsigned long int num_touches;
123 unsigned long int *backups;
124 unsigned long int num_backups;
126 struct macaddr_t *macaddr;
128 /* Function prototypes */
129 int prepare_memory(void);
130 int parse_leases(void);
131 void parse_config(int, char *, struct shared_network_t *)
132 __attribute__ ((nonnull(2, 3)));
133 int nth_field(int n, char *dest, const char *src)
134 __attribute__ ((nonnull(2, 3)))
135 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
136 __attribute__ ((__hot__))
139 int prepare_data(void);
140 int do_counting(void);
141 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
142 __attribute__ ((nonnull(1, 2)));
143 /* General support functions */
144 void *safe_malloc(const size_t size)
146 __attribute__ ((__malloc__))
147 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
148 __attribute__ ((__alloc_size__((1))))
152 void *safe_realloc(void *ptr, const size_t size);
153 char *safe_strdup(const char *str) __attribute__ ((nonnull(1)));
154 void print_version(void) __attribute__ ((noreturn));
155 void usage(int status) __attribute__ ((noreturn));
156 /* qsort required functions... */
157 /* ...for ranges and... */
158 int intcomp(const void *x, const void *y) __attribute__ ((nonnull(1, 2)));
159 int rangecomp(const void *r1, const void *r2)
160 __attribute__ ((nonnull(1, 2)));
161 /* sort function pointer and functions */
163 unsigned long int (*returner) (struct range_t r);
164 unsigned long int ret_ip(struct range_t r);
165 unsigned long int ret_cur(struct range_t r);
166 unsigned long int ret_max(struct range_t r);
167 unsigned long int ret_percent(struct range_t r);
168 unsigned long int ret_touched(struct range_t r);
169 unsigned long int ret_tc(struct range_t r);
170 unsigned long int ret_tcperc(struct range_t r);
171 void field_selector(char c);
172 int get_order(struct range_t *left, struct range_t *right)
173 __attribute__ ((nonnull(1, 2)));
174 void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp)
175 __attribute__ ((nonnull(1, 3)));
176 /* output function pointer and functions */
177 int (*output_analysis) (void);
178 int output_txt(void);
179 int output_html(void);
180 int output_xml(void);
181 int output_csv(void);
182 /* Memory release, file closing etc */
185 #endif /* DHCPD_POOLS_H */