headers: include-what-you-use fixes
[debian/dhcpd-pools.git] / src / dhcpd-pools.h
1 /* http://dhcpd-pools.sourceforge.net/
2 ** Copyright 2006- Sami Kerola <kerolasa@iki.fi>
3 **
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.
8 **
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.
13 **
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/>.   
16 */
17
18 #ifndef DHCPD_POOLS_H
19 # define DHCPD_POOLS_H 1
20
21 #include <config.h>
22 #include <stddef.h>
23
24 /* Feature test switches */
25 #define _POSIX_SOURCE 1
26 #define POSIXLY_CORRECT 1
27
28 #ifdef  HAVE_STDLIB_H
29 #else
30 extern void exit();
31 extern char *malloc();
32 #define EXIT_FAILURE    1
33 #define EXIT_SUCCESS    0
34 #endif                          /* STDC_HEADERS */
35
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
42 #      include <stdlib.h>
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)
51 {
52         char *t;
53         if ((t = strrchr(f, '/')) != NULL) {
54                 t++;
55         } else {
56                 t = f;
57         }
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';
60
61         if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) {
62                 *t = '\0';
63         }
64         return prog_inv_sh_nm_buf;
65 }
66 #  endif
67 #endif
68
69 /* Structures and unions */
70 struct configuration_t {
71         char *dhcpdconf_file;
72         char *dhcpdlease_file;
73         char output_format[2];
74         char sort[6];
75         int reverse_order;
76         char *output_file;
77         int output_limit[2];
78 };
79 struct shared_network_t {
80         char *name;
81         unsigned long int available;
82         unsigned long int used;
83         unsigned long int touched;
84         unsigned long int backups;
85 };
86 struct range_t {
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;
93 };
94 struct macaddr_t {
95         char *ethernet;
96         char *ip;
97         struct macaddr_t *next;
98 };
99
100 /* Global variables */
101 static int const true = 1;
102 static int const false = 0;
103
104 struct configuration_t config;
105
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;
110
111 struct shared_network_t *shared_networks;
112 unsigned int num_shared_networks;
113
114 struct range_t *ranges;
115 unsigned int num_ranges;
116
117 unsigned long int *leases;
118 unsigned long int num_leases;
119
120 unsigned long int *touches;
121 unsigned long int num_touches;
122
123 unsigned long int *backups;
124 unsigned long int num_backups;
125
126 struct macaddr_t *macaddr;
127
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__))
137 #endif
138     ;
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)
145 #if __GNUC__ >= 3
146     __attribute__ ((__malloc__))
147 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
148     __attribute__ ((__alloc_size__((1))))
149 #endif
150 #endif
151     ;
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 */
162 int sort_name(void);
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 */
183 void clean_up(void);
184
185 #endif                          /* DHCPD_POOLS_H */