a17c6b87a19a3010bb4c6a19d8fd1569e8c96b65
[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
23 /* Feature test switches */
24 #define _POSIX_SOURCE 1
25 #define POSIXLY_CORRECT 1
26
27 #ifdef  HAVE_STDLIB_H
28 #include <stdlib.h>
29 #else /* Not STDC_HEADERS */
30 extern void exit ();
31 extern char *malloc ();
32 #endif /* STDC_HEADERS */
33
34 /* Structures and unions */
35 struct configuration_t
36 {
37   char *dhcpdconf_file;
38   char *dhcpdlease_file;
39   char output_format[2];
40   char sort[6];
41   int reverse_order;
42   char *output_file;
43   int output_limit[2];
44 };
45 struct shared_network_t
46 {
47   char *name;
48   unsigned long int available;
49   unsigned long int used;
50   unsigned long int touched;
51   unsigned long int backups;
52 };
53 struct range_t
54 {
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;
61 };
62 struct macaddr_t
63 {
64   char *ethernet;
65   char *ip;
66   struct macaddr_t *next;
67 };
68
69 /* Global variables */
70 static int const true = 1;
71 static int const false = 0;
72
73 struct configuration_t config;
74
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;
79
80 struct shared_network_t *shared_networks;
81 char *shared_net_names;
82 unsigned int num_shared_networks;
83
84 struct range_t *ranges;
85 unsigned int num_ranges;
86
87 unsigned long int *leases;
88 unsigned long int num_leases;
89
90 unsigned long int *touches;
91 unsigned long int num_touches;
92
93 unsigned long int *backups;
94 unsigned long int num_backups;
95
96 struct macaddr_t *macaddr;
97
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 int nth_field (int n, char *dest, const char *src);
103 int prepare_data (void);
104 int do_counting (void);
105 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges);
106 /* General support functions */
107 void *safe_malloc (const size_t size);
108 inline char *safe_strdup(const char *str);
109 void print_version (void);
110 void usage (int status);
111 /* qsort required functions... */
112 /* ...for ranges and... */
113 int intcomp (const void *x, const void *y);
114 int rangecomp (const void *r1, const void *r2);
115 /* sort function pointer and functions */
116 int sort_name (void);
117 unsigned long int (*returner) (struct range_t r);
118 unsigned long int ret_ip(struct range_t r);
119 unsigned long int ret_cur(struct range_t r);
120 unsigned long int ret_max(struct range_t r);
121 unsigned long int ret_percent(struct range_t r);
122 unsigned long int ret_touched(struct range_t r);
123 unsigned long int ret_tc(struct range_t r);
124 unsigned long int ret_tcperc(struct range_t r);
125 void field_selector(char c);
126 int get_order(struct range_t *left, struct range_t *right);
127 void mergesort_ranges (struct range_t *orig, int size, struct range_t *temp);
128 /* output function pointer and functions */
129 int (*output_analysis) (void);
130 int output_txt (void);
131 int output_html (void);
132 int output_xml (void);
133 int output_csv (void);
134 /* Memory release, file closing etc */
135 void clean_up (void);
136
137 #endif /* DHCPD_POOLS_H */