diff options
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_dhcp.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index 657ddc13..6802232e 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c | |||
@@ -105,7 +105,7 @@ static int put_ctrl(int, int, int); | |||
105 | static int put_both(int, int, int, int); | 105 | static int put_both(int, int, int, int); |
106 | static int dl_open(const char *, int, int *); | 106 | static int dl_open(const char *, int, int *); |
107 | static int dl_bind(int, int, u_char *); | 107 | static int dl_bind(int, int, u_char *); |
108 | long mac_addr_dlpi(const char *, int, u_char *); | 108 | static long mac_addr_dlpi(const char *, int, u_char *); |
109 | 109 | ||
110 | #endif // __sun__ || __solaris__ || __hpux | 110 | #endif // __sun__ || __solaris__ || __hpux |
111 | 111 | ||
@@ -186,60 +186,60 @@ typedef struct requested_server_struct { | |||
186 | #define ETHERNET_HARDWARE_ADDRESS 1 /* used in htype field of dhcp packet */ | 186 | #define ETHERNET_HARDWARE_ADDRESS 1 /* used in htype field of dhcp packet */ |
187 | #define ETHERNET_HARDWARE_ADDRESS_LENGTH 6 /* length of Ethernet hardware addresses */ | 187 | #define ETHERNET_HARDWARE_ADDRESS_LENGTH 6 /* length of Ethernet hardware addresses */ |
188 | 188 | ||
189 | bool unicast = false; /* unicast mode: mimic a DHCP relay */ | 189 | static bool unicast = false; /* unicast mode: mimic a DHCP relay */ |
190 | bool exclusive = false; /* exclusive mode aka "rogue DHCP server detection" */ | 190 | static bool exclusive = false; /* exclusive mode aka "rogue DHCP server detection" */ |
191 | struct in_addr my_ip; /* our address (required for relay) */ | 191 | static struct in_addr my_ip; /* our address (required for relay) */ |
192 | struct in_addr dhcp_ip; /* server to query (if in unicast mode) */ | 192 | static struct in_addr dhcp_ip; /* server to query (if in unicast mode) */ |
193 | unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH] = ""; | 193 | static unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH] = ""; |
194 | unsigned char *user_specified_mac = NULL; | 194 | static unsigned char *user_specified_mac = NULL; |
195 | 195 | ||
196 | char network_interface_name[IFNAMSIZ] = "eth0"; | 196 | static char network_interface_name[IFNAMSIZ] = "eth0"; |
197 | 197 | ||
198 | uint32_t packet_xid = 0; | 198 | static uint32_t packet_xid = 0; |
199 | 199 | ||
200 | uint32_t dhcp_lease_time = 0; | 200 | static uint32_t dhcp_lease_time = 0; |
201 | uint32_t dhcp_renewal_time = 0; | 201 | static uint32_t dhcp_renewal_time = 0; |
202 | uint32_t dhcp_rebinding_time = 0; | 202 | static uint32_t dhcp_rebinding_time = 0; |
203 | 203 | ||
204 | int dhcpoffer_timeout = 2; | 204 | static int dhcpoffer_timeout = 2; |
205 | 205 | ||
206 | dhcp_offer *dhcp_offer_list = NULL; | 206 | static dhcp_offer *dhcp_offer_list = NULL; |
207 | requested_server *requested_server_list = NULL; | 207 | static requested_server *requested_server_list = NULL; |
208 | 208 | ||
209 | int valid_responses = 0; /* number of valid DHCPOFFERs we received */ | 209 | static int valid_responses = 0; /* number of valid DHCPOFFERs we received */ |
210 | int requested_servers = 0; | 210 | static int requested_servers = 0; |
211 | int requested_responses = 0; | 211 | static int requested_responses = 0; |
212 | 212 | ||
213 | bool request_specific_address = false; | 213 | static bool request_specific_address = false; |
214 | bool received_requested_address = false; | 214 | static bool received_requested_address = false; |
215 | int verbose = 0; | 215 | static int verbose = 0; |
216 | struct in_addr requested_address; | 216 | static struct in_addr requested_address; |
217 | 217 | ||
218 | int process_arguments(int, char **); | 218 | static int process_arguments(int, char **); |
219 | int call_getopt(int, char **); | 219 | static int call_getopt(int, char **); |
220 | int validate_arguments(int); | 220 | static int validate_arguments(int); |
221 | void print_usage(void); | 221 | void print_usage(void); |
222 | void print_help(void); | 222 | static void print_help(void); |
223 | 223 | ||
224 | void resolve_host(const char *in, struct in_addr *out); | 224 | static void resolve_host(const char *in, struct in_addr *out); |
225 | unsigned char *mac_aton(const char *); | 225 | static unsigned char *mac_aton(const char *); |
226 | void print_hardware_address(const unsigned char *); | 226 | static void print_hardware_address(const unsigned char *); |
227 | int get_hardware_address(int, char *); | 227 | static int get_hardware_address(int, char *); |
228 | int get_ip_address(int, char *); | 228 | static int get_ip_address(int, char *); |
229 | 229 | ||
230 | int send_dhcp_discover(int); | 230 | static int send_dhcp_discover(int); |
231 | int get_dhcp_offer(int); | 231 | static int get_dhcp_offer(int); |
232 | 232 | ||
233 | int get_results(void); | 233 | static int get_results(void); |
234 | 234 | ||
235 | int add_dhcp_offer(struct in_addr, dhcp_packet *); | 235 | static int add_dhcp_offer(struct in_addr, dhcp_packet *); |
236 | int free_dhcp_offer_list(void); | 236 | static int free_dhcp_offer_list(void); |
237 | int free_requested_server_list(void); | 237 | static int free_requested_server_list(void); |
238 | 238 | ||
239 | int create_dhcp_socket(void); | 239 | static int create_dhcp_socket(void); |
240 | int close_dhcp_socket(int); | 240 | static int close_dhcp_socket(int); |
241 | int send_dhcp_packet(void *, int, int, struct sockaddr_in *); | 241 | static int send_dhcp_packet(void *, int, int, struct sockaddr_in *); |
242 | int receive_dhcp_packet(void *, int, int, int, struct sockaddr_in *); | 242 | static int receive_dhcp_packet(void *, int, int, int, struct sockaddr_in *); |
243 | 243 | ||
244 | int main(int argc, char **argv) { | 244 | int main(int argc, char **argv) { |
245 | int dhcp_socket; | 245 | int dhcp_socket; |
@@ -288,7 +288,7 @@ int main(int argc, char **argv) { | |||
288 | } | 288 | } |
289 | 289 | ||
290 | /* determines hardware address on client machine */ | 290 | /* determines hardware address on client machine */ |
291 | int get_hardware_address(int sock, char *interface_name) { | 291 | static int get_hardware_address(int sock, char *interface_name) { |
292 | 292 | ||
293 | #if defined(__linux__) | 293 | #if defined(__linux__) |
294 | struct ifreq ifr; | 294 | struct ifreq ifr; |
@@ -400,7 +400,7 @@ int get_hardware_address(int sock, char *interface_name) { | |||
400 | } | 400 | } |
401 | 401 | ||
402 | /* determines IP address of the client interface */ | 402 | /* determines IP address of the client interface */ |
403 | int get_ip_address(int sock, char *interface_name) { | 403 | static int get_ip_address(int sock, char *interface_name) { |
404 | #if defined(SIOCGIFADDR) | 404 | #if defined(SIOCGIFADDR) |
405 | struct ifreq ifr; | 405 | struct ifreq ifr; |
406 | 406 | ||
@@ -426,7 +426,7 @@ int get_ip_address(int sock, char *interface_name) { | |||
426 | } | 426 | } |
427 | 427 | ||
428 | /* sends a DHCPDISCOVER broadcast message in an attempt to find DHCP servers */ | 428 | /* sends a DHCPDISCOVER broadcast message in an attempt to find DHCP servers */ |
429 | int send_dhcp_discover(int sock) { | 429 | static int send_dhcp_discover(int sock) { |
430 | dhcp_packet discover_packet; | 430 | dhcp_packet discover_packet; |
431 | struct sockaddr_in sockaddr_broadcast; | 431 | struct sockaddr_in sockaddr_broadcast; |
432 | unsigned short opts; | 432 | unsigned short opts; |
@@ -515,7 +515,7 @@ int send_dhcp_discover(int sock) { | |||
515 | } | 515 | } |
516 | 516 | ||
517 | /* waits for a DHCPOFFER message from one or more DHCP servers */ | 517 | /* waits for a DHCPOFFER message from one or more DHCP servers */ |
518 | int get_dhcp_offer(int sock) { | 518 | static int get_dhcp_offer(int sock) { |
519 | dhcp_packet offer_packet; | 519 | dhcp_packet offer_packet; |
520 | struct sockaddr_in source; | 520 | struct sockaddr_in source; |
521 | struct sockaddr_in via; | 521 | struct sockaddr_in via; |
@@ -617,7 +617,7 @@ int get_dhcp_offer(int sock) { | |||
617 | } | 617 | } |
618 | 618 | ||
619 | /* sends a DHCP packet */ | 619 | /* sends a DHCP packet */ |
620 | int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest) { | 620 | static int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest) { |
621 | int result; | 621 | int result; |
622 | 622 | ||
623 | result = sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest)); | 623 | result = sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest)); |
@@ -632,7 +632,7 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in | |||
632 | } | 632 | } |
633 | 633 | ||
634 | /* receives a DHCP packet */ | 634 | /* receives a DHCP packet */ |
635 | int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address) { | 635 | static int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address) { |
636 | struct timeval tv; | 636 | struct timeval tv; |
637 | fd_set readfds; | 637 | fd_set readfds; |
638 | fd_set oobfds; | 638 | fd_set oobfds; |
@@ -685,7 +685,7 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st | |||
685 | } | 685 | } |
686 | 686 | ||
687 | /* creates a socket for DHCP communication */ | 687 | /* creates a socket for DHCP communication */ |
688 | int create_dhcp_socket(void) { | 688 | static int create_dhcp_socket(void) { |
689 | struct sockaddr_in myname; | 689 | struct sockaddr_in myname; |
690 | struct ifreq interface; | 690 | struct ifreq interface; |
691 | int sock; | 691 | int sock; |
@@ -746,7 +746,7 @@ int create_dhcp_socket(void) { | |||
746 | } | 746 | } |
747 | 747 | ||
748 | /* closes DHCP socket */ | 748 | /* closes DHCP socket */ |
749 | int close_dhcp_socket(int sock) { | 749 | static int close_dhcp_socket(int sock) { |
750 | 750 | ||
751 | close(sock); | 751 | close(sock); |
752 | 752 | ||
@@ -754,7 +754,7 @@ int close_dhcp_socket(int sock) { | |||
754 | } | 754 | } |
755 | 755 | ||
756 | /* adds a requested server address to list in memory */ | 756 | /* adds a requested server address to list in memory */ |
757 | int add_requested_server(struct in_addr server_address) { | 757 | static int add_requested_server(struct in_addr server_address) { |
758 | requested_server *new_server; | 758 | requested_server *new_server; |
759 | 759 | ||
760 | new_server = (requested_server *)malloc(sizeof(requested_server)); | 760 | new_server = (requested_server *)malloc(sizeof(requested_server)); |
@@ -776,7 +776,7 @@ int add_requested_server(struct in_addr server_address) { | |||
776 | } | 776 | } |
777 | 777 | ||
778 | /* adds a DHCP OFFER to list in memory */ | 778 | /* adds a DHCP OFFER to list in memory */ |
779 | int add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet) { | 779 | static int add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet) { |
780 | dhcp_offer *new_offer; | 780 | dhcp_offer *new_offer; |
781 | int x; | 781 | int x; |
782 | unsigned option_type; | 782 | unsigned option_type; |
@@ -878,7 +878,7 @@ int add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet) { | |||
878 | } | 878 | } |
879 | 879 | ||
880 | /* frees memory allocated to DHCP OFFER list */ | 880 | /* frees memory allocated to DHCP OFFER list */ |
881 | int free_dhcp_offer_list(void) { | 881 | static int free_dhcp_offer_list(void) { |
882 | dhcp_offer *this_offer; | 882 | dhcp_offer *this_offer; |
883 | dhcp_offer *next_offer; | 883 | dhcp_offer *next_offer; |
884 | 884 | ||
@@ -891,7 +891,7 @@ int free_dhcp_offer_list(void) { | |||
891 | } | 891 | } |
892 | 892 | ||
893 | /* frees memory allocated to requested server list */ | 893 | /* frees memory allocated to requested server list */ |
894 | int free_requested_server_list(void) { | 894 | static int free_requested_server_list(void) { |
895 | requested_server *this_server; | 895 | requested_server *this_server; |
896 | requested_server *next_server; | 896 | requested_server *next_server; |
897 | 897 | ||
@@ -904,7 +904,7 @@ int free_requested_server_list(void) { | |||
904 | } | 904 | } |
905 | 905 | ||
906 | /* gets state and plugin output to return */ | 906 | /* gets state and plugin output to return */ |
907 | int get_results(void) { | 907 | static int get_results(void) { |
908 | dhcp_offer *temp_offer, *undesired_offer = NULL; | 908 | dhcp_offer *temp_offer, *undesired_offer = NULL; |
909 | requested_server *temp_server; | 909 | requested_server *temp_server; |
910 | int result; | 910 | int result; |
@@ -1025,7 +1025,7 @@ int get_results(void) { | |||
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | /* process command-line arguments */ | 1027 | /* process command-line arguments */ |
1028 | int process_arguments(int argc, char **argv) { | 1028 | static int process_arguments(int argc, char **argv) { |
1029 | if (argc < 1) | 1029 | if (argc < 1) |
1030 | return ERROR; | 1030 | return ERROR; |
1031 | 1031 | ||
@@ -1033,7 +1033,7 @@ int process_arguments(int argc, char **argv) { | |||
1033 | return validate_arguments(argc); | 1033 | return validate_arguments(argc); |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | int call_getopt(int argc, char **argv) { | 1036 | static int call_getopt(int argc, char **argv) { |
1037 | extern int optind; | 1037 | extern int optind; |
1038 | int option_index = 0; | 1038 | int option_index = 0; |
1039 | static struct option long_options[] = {{"serverip", required_argument, 0, 's'}, | 1039 | static struct option long_options[] = {{"serverip", required_argument, 0, 's'}, |
@@ -1125,7 +1125,7 @@ int call_getopt(int argc, char **argv) { | |||
1125 | return optind; | 1125 | return optind; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | int validate_arguments(int argc) { | 1128 | static int validate_arguments(int argc) { |
1129 | 1129 | ||
1130 | if (argc - optind > 0) | 1130 | if (argc - optind > 0) |
1131 | usage(_("Got unexpected non-option argument")); | 1131 | usage(_("Got unexpected non-option argument")); |
@@ -1249,7 +1249,7 @@ static int dl_bind(int fd, int sap, u_char *addr) { | |||
1249 | * | 1249 | * |
1250 | ***********************************************************************/ | 1250 | ***********************************************************************/ |
1251 | 1251 | ||
1252 | long mac_addr_dlpi(const char *dev, int unit, u_char *addr) { | 1252 | static long mac_addr_dlpi(const char *dev, int unit, u_char *addr) { |
1253 | int fd; | 1253 | int fd; |
1254 | u_char mac_addr[25]; | 1254 | u_char mac_addr[25]; |
1255 | 1255 | ||
@@ -1268,7 +1268,7 @@ long mac_addr_dlpi(const char *dev, int unit, u_char *addr) { | |||
1268 | #endif | 1268 | #endif |
1269 | 1269 | ||
1270 | /* resolve host name or die (TODO: move this to netutils.c!) */ | 1270 | /* resolve host name or die (TODO: move this to netutils.c!) */ |
1271 | void resolve_host(const char *in, struct in_addr *out) { | 1271 | static void resolve_host(const char *in, struct in_addr *out) { |
1272 | struct addrinfo hints, *ai; | 1272 | struct addrinfo hints, *ai; |
1273 | 1273 | ||
1274 | memset(&hints, 0, sizeof(hints)); | 1274 | memset(&hints, 0, sizeof(hints)); |
@@ -1281,7 +1281,7 @@ void resolve_host(const char *in, struct in_addr *out) { | |||
1281 | } | 1281 | } |
1282 | 1282 | ||
1283 | /* parse MAC address string, return 6 bytes (unterminated) or NULL */ | 1283 | /* parse MAC address string, return 6 bytes (unterminated) or NULL */ |
1284 | unsigned char *mac_aton(const char *string) { | 1284 | static unsigned char *mac_aton(const char *string) { |
1285 | static unsigned char result[6]; | 1285 | static unsigned char result[6]; |
1286 | char tmp[3]; | 1286 | char tmp[3]; |
1287 | unsigned i, j; | 1287 | unsigned i, j; |
@@ -1301,7 +1301,7 @@ unsigned char *mac_aton(const char *string) { | |||
1301 | return (j == 6) ? result : NULL; | 1301 | return (j == 6) ? result : NULL; |
1302 | } | 1302 | } |
1303 | 1303 | ||
1304 | void print_hardware_address(const unsigned char *address) { | 1304 | static void print_hardware_address(const unsigned char *address) { |
1305 | int i; | 1305 | int i; |
1306 | 1306 | ||
1307 | printf(_("Hardware address: ")); | 1307 | printf(_("Hardware address: ")); |
@@ -1312,7 +1312,7 @@ void print_hardware_address(const unsigned char *address) { | |||
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | /* print usage help */ | 1314 | /* print usage help */ |
1315 | void print_help(void) { | 1315 | static void print_help(void) { |
1316 | 1316 | ||
1317 | print_revision(progname, NP_VERSION); | 1317 | print_revision(progname, NP_VERSION); |
1318 | 1318 | ||