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
23 /* Feature test switches */
24 #define _POSIX_SOURCE 1
25 #define POSIXLY_CORRECT 1
31 extern char *malloc();
32 #endif /* STDC_HEADERS */
34 #ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
35 # ifdef HAVE___PROGNAME
36 extern char *__progname;
37 # define program_invocation_short_name __progname
38 # else /* HAVE___PROGNAME */
39 # ifdef HAVE_GETEXECNAME
41 # define program_invocation_short_name \
42 prog_inv_sh_nm_from_file(getexecname(), 0)
43 # else /* HAVE_GETEXECNAME */
44 # define program_invocation_short_name \
45 prog_inv_sh_nm_from_file(__FILE__, 1)
46 # endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
47 static char prog_inv_sh_nm_buf[256];
48 static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
51 if ((t = strrchr(f, '/')) != NULL) {
56 strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
57 prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
59 if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) {
62 return prog_inv_sh_nm_buf;
67 /* Structures and unions */
68 struct configuration_t {
70 char *dhcpdlease_file;
71 char output_format[2];
77 struct shared_network_t {
79 unsigned long int available;
80 unsigned long int used;
81 unsigned long int touched;
82 unsigned long int backups;
85 struct shared_network_t *shared_net;
86 unsigned long int first_ip;
87 unsigned long int last_ip;
88 unsigned long int count;
89 unsigned long int touched;
90 unsigned long int backups;
95 struct macaddr_t *next;
98 /* Global variables */
99 static int const true = 1;
100 static int const false = 0;
102 struct configuration_t config;
104 static int const output_limit_bit_1 = 1;
105 static int const output_limit_bit_2 = 2;
106 static int const output_limit_bit_3 = 4;
107 unsigned int fullhtml;
109 struct shared_network_t *shared_networks;
110 unsigned int num_shared_networks;
112 struct range_t *ranges;
113 unsigned int num_ranges;
115 unsigned long int *leases;
116 unsigned long int num_leases;
118 unsigned long int *touches;
119 unsigned long int num_touches;
121 unsigned long int *backups;
122 unsigned long int num_backups;
124 struct macaddr_t *macaddr;
126 /* Function prototypes */
127 int prepare_memory(void);
128 int parse_leases(void);
129 void parse_config(int, char *, struct shared_network_t *)
130 __attribute__ ((nonnull(2, 3)));
131 int nth_field(int n, char *dest, const char *src)
132 __attribute__ ((nonnull(2, 3)))
133 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
134 __attribute__ ((__hot__))
137 int prepare_data(void);
138 int do_counting(void);
139 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
140 __attribute__ ((nonnull(1, 2)));
141 /* General support functions */
142 void *safe_malloc(const size_t size)
144 __attribute__ ((__malloc__))
145 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
146 __attribute__ ((__alloc_size__((1))))
150 void *safe_realloc(void *ptr, const size_t size);
151 char *safe_strdup(const char *str) __attribute__ ((nonnull(1)));
152 void print_version(void) __attribute__ ((noreturn));
153 void usage(int status) __attribute__ ((noreturn));
154 /* qsort required functions... */
155 /* ...for ranges and... */
156 int intcomp(const void *x, const void *y) __attribute__ ((nonnull(1, 2)));
157 int rangecomp(const void *r1, const void *r2)
158 __attribute__ ((nonnull(1, 2)));
159 /* sort function pointer and functions */
161 unsigned long int (*returner) (struct range_t r);
162 unsigned long int ret_ip(struct range_t r);
163 unsigned long int ret_cur(struct range_t r);
164 unsigned long int ret_max(struct range_t r);
165 unsigned long int ret_percent(struct range_t r);
166 unsigned long int ret_touched(struct range_t r);
167 unsigned long int ret_tc(struct range_t r);
168 unsigned long int ret_tcperc(struct range_t r);
169 void field_selector(char c);
170 int get_order(struct range_t *left, struct range_t *right)
171 __attribute__ ((nonnull(1, 2)));
172 void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp)
173 __attribute__ ((nonnull(1, 3)));
174 /* output function pointer and functions */
175 int (*output_analysis) (void);
176 int output_txt(void);
177 int output_html(void);
178 int output_xml(void);
179 int output_csv(void);
180 /* Memory release, file closing etc */
183 #endif /* DHCPD_POOLS_H */