summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_dhcp.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 657ddc1..6802232 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -105,7 +105,7 @@ static int put_ctrl(int, int, int);
105static int put_both(int, int, int, int); 105static int put_both(int, int, int, int);
106static int dl_open(const char *, int, int *); 106static int dl_open(const char *, int, int *);
107static int dl_bind(int, int, u_char *); 107static int dl_bind(int, int, u_char *);
108long mac_addr_dlpi(const char *, int, u_char *); 108static 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
189bool unicast = false; /* unicast mode: mimic a DHCP relay */ 189static bool unicast = false; /* unicast mode: mimic a DHCP relay */
190bool exclusive = false; /* exclusive mode aka "rogue DHCP server detection" */ 190static bool exclusive = false; /* exclusive mode aka "rogue DHCP server detection" */
191struct in_addr my_ip; /* our address (required for relay) */ 191static struct in_addr my_ip; /* our address (required for relay) */
192struct in_addr dhcp_ip; /* server to query (if in unicast mode) */ 192static struct in_addr dhcp_ip; /* server to query (if in unicast mode) */
193unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH] = ""; 193static unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH] = "";
194unsigned char *user_specified_mac = NULL; 194static unsigned char *user_specified_mac = NULL;
195 195
196char network_interface_name[IFNAMSIZ] = "eth0"; 196static char network_interface_name[IFNAMSIZ] = "eth0";
197 197
198uint32_t packet_xid = 0; 198static uint32_t packet_xid = 0;
199 199
200uint32_t dhcp_lease_time = 0; 200static uint32_t dhcp_lease_time = 0;
201uint32_t dhcp_renewal_time = 0; 201static uint32_t dhcp_renewal_time = 0;
202uint32_t dhcp_rebinding_time = 0; 202static uint32_t dhcp_rebinding_time = 0;
203 203
204int dhcpoffer_timeout = 2; 204static int dhcpoffer_timeout = 2;
205 205
206dhcp_offer *dhcp_offer_list = NULL; 206static dhcp_offer *dhcp_offer_list = NULL;
207requested_server *requested_server_list = NULL; 207static requested_server *requested_server_list = NULL;
208 208
209int valid_responses = 0; /* number of valid DHCPOFFERs we received */ 209static int valid_responses = 0; /* number of valid DHCPOFFERs we received */
210int requested_servers = 0; 210static int requested_servers = 0;
211int requested_responses = 0; 211static int requested_responses = 0;
212 212
213bool request_specific_address = false; 213static bool request_specific_address = false;
214bool received_requested_address = false; 214static bool received_requested_address = false;
215int verbose = 0; 215static int verbose = 0;
216struct in_addr requested_address; 216static struct in_addr requested_address;
217 217
218int process_arguments(int, char **); 218static int process_arguments(int, char **);
219int call_getopt(int, char **); 219static int call_getopt(int, char **);
220int validate_arguments(int); 220static int validate_arguments(int);
221void print_usage(void); 221void print_usage(void);
222void print_help(void); 222static void print_help(void);
223 223
224void resolve_host(const char *in, struct in_addr *out); 224static void resolve_host(const char *in, struct in_addr *out);
225unsigned char *mac_aton(const char *); 225static unsigned char *mac_aton(const char *);
226void print_hardware_address(const unsigned char *); 226static void print_hardware_address(const unsigned char *);
227int get_hardware_address(int, char *); 227static int get_hardware_address(int, char *);
228int get_ip_address(int, char *); 228static int get_ip_address(int, char *);
229 229
230int send_dhcp_discover(int); 230static int send_dhcp_discover(int);
231int get_dhcp_offer(int); 231static int get_dhcp_offer(int);
232 232
233int get_results(void); 233static int get_results(void);
234 234
235int add_dhcp_offer(struct in_addr, dhcp_packet *); 235static int add_dhcp_offer(struct in_addr, dhcp_packet *);
236int free_dhcp_offer_list(void); 236static int free_dhcp_offer_list(void);
237int free_requested_server_list(void); 237static int free_requested_server_list(void);
238 238
239int create_dhcp_socket(void); 239static int create_dhcp_socket(void);
240int close_dhcp_socket(int); 240static int close_dhcp_socket(int);
241int send_dhcp_packet(void *, int, int, struct sockaddr_in *); 241static int send_dhcp_packet(void *, int, int, struct sockaddr_in *);
242int receive_dhcp_packet(void *, int, int, int, struct sockaddr_in *); 242static int receive_dhcp_packet(void *, int, int, int, struct sockaddr_in *);
243 243
244int main(int argc, char **argv) { 244int 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 */
291int get_hardware_address(int sock, char *interface_name) { 291static 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 */
403int get_ip_address(int sock, char *interface_name) { 403static 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 */
429int send_dhcp_discover(int sock) { 429static 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 */
518int get_dhcp_offer(int sock) { 518static 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 */
620int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest) { 620static 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 */
635int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address) { 635static 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 */
688int create_dhcp_socket(void) { 688static 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 */
749int close_dhcp_socket(int sock) { 749static 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 */
757int add_requested_server(struct in_addr server_address) { 757static 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 */
779int add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet) { 779static 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 */
881int free_dhcp_offer_list(void) { 881static 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 */
894int free_requested_server_list(void) { 894static 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 */
907int get_results(void) { 907static 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 */
1028int process_arguments(int argc, char **argv) { 1028static 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
1036int call_getopt(int argc, char **argv) { 1036static 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
1128int validate_arguments(int argc) { 1128static 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
1252long mac_addr_dlpi(const char *dev, int unit, u_char *addr) { 1252static 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!) */
1271void resolve_host(const char *in, struct in_addr *out) { 1271static 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 */
1284unsigned char *mac_aton(const char *string) { 1284static 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
1304void print_hardware_address(const unsigned char *address) { 1304static 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 */
1315void print_help(void) { 1315static void print_help(void) {
1316 1316
1317 print_revision(progname, NP_VERSION); 1317 print_revision(progname, NP_VERSION);
1318 1318