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
29 #else /* Not STDC_HEADERS */
31 extern char *malloc ();
32 #endif /* STDC_HEADERS */
34 /* Structures and unions */
35 struct configuration_t
38 char *dhcpdlease_file;
39 char output_format[2];
45 struct shared_network_t
48 unsigned long int available;
49 unsigned long int used;
50 unsigned long int touched;
51 unsigned long int backups;
55 struct shared_network_t *shared_net;
56 unsigned long int first_ip;
57 unsigned long int last_ip;
58 unsigned long int count;
59 unsigned long int touched;
60 unsigned long int backups;
66 struct macaddr_t *next;
69 /* Global variables */
70 static int const true = 1;
71 static int const false = 0;
73 struct configuration_t config;
75 static int const output_limit_bit_1 = 1;
76 static int const output_limit_bit_2 = 2;
77 static int const output_limit_bit_3 = 4;
78 unsigned int fullhtml;
80 struct shared_network_t *shared_networks;
81 char *shared_net_names;
82 unsigned int num_shared_networks;
84 struct range_t *ranges;
85 unsigned int num_ranges;
87 unsigned long int *leases;
88 unsigned long int num_leases;
90 unsigned long int *touches;
91 unsigned long int num_touches;
93 unsigned long int *backups;
94 unsigned long int num_backups;
96 struct macaddr_t *macaddr;
98 /* Function prototypes */
99 int prepare_memory (void);
100 int parse_leases (void);
101 char * parse_config (int, char *, char *, char *, struct shared_network_t *)
102 __attribute__((nonnull (2, 3, 4)));
103 int nth_field (int n, char *dest, const char *src)
104 __attribute__((nonnull (2, 3)))
105 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
106 __attribute__((__hot__))
109 int prepare_data (void);
110 int do_counting (void);
111 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
112 __attribute__((nonnull (1, 2)));
113 /* General support functions */
114 void *safe_malloc (const size_t size)
116 __attribute__ ((__malloc__))
117 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
118 __attribute__ ((__alloc_size__ ((1))))
122 char *safe_strdup(const char *str) __attribute__((nonnull (1)));
123 void print_version (void) __attribute__((noreturn));
124 void usage (int status) __attribute__((noreturn));
125 /* qsort required functions... */
126 /* ...for ranges and... */
127 int intcomp (const void *x, const void *y) __attribute__((nonnull (1, 2)));
128 int rangecomp (const void *r1, const void *r2) __attribute__((nonnull (1, 2)));
129 /* sort function pointer and functions */
130 int sort_name (void);
131 unsigned long int (*returner) (struct range_t r);
132 unsigned long int ret_ip(struct range_t r);
133 unsigned long int ret_cur(struct range_t r);
134 unsigned long int ret_max(struct range_t r);
135 unsigned long int ret_percent(struct range_t r);
136 unsigned long int ret_touched(struct range_t r);
137 unsigned long int ret_tc(struct range_t r);
138 unsigned long int ret_tcperc(struct range_t r);
139 void field_selector(char c);
140 int get_order(struct range_t *left, struct range_t *right) __attribute__((nonnull (1, 2)));
141 void mergesort_ranges (struct range_t *orig, int size, struct range_t *temp) __attribute__((nonnull (1, 3)));
142 /* output function pointer and functions */
143 int (*output_analysis) (void);
144 int output_txt (void);
145 int output_html (void);
146 int output_xml (void);
147 int output_csv (void);
148 /* Memory release, file closing etc */
149 void clean_up (void);
151 #endif /* DHCPD_POOLS_H */