diff options
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_dhcp.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index a0f150fb..c6e5af8a 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c | |||
@@ -243,6 +243,7 @@ int validate_arguments(void); | |||
243 | void print_usage(void); | 243 | void print_usage(void); |
244 | void print_help(void); | 244 | void print_help(void); |
245 | 245 | ||
246 | void resolve_host(const char *in,struct in_addr *out); | ||
246 | unsigned char *mac_aton(const char *); | 247 | unsigned char *mac_aton(const char *); |
247 | void print_hardware_address(const unsigned char *); | 248 | void print_hardware_address(const unsigned char *); |
248 | int get_hardware_address(int,char *); | 249 | int get_hardware_address(int,char *); |
@@ -1089,7 +1090,6 @@ int process_arguments(int argc, char **argv){ | |||
1089 | int call_getopt(int argc, char **argv){ | 1090 | int call_getopt(int argc, char **argv){ |
1090 | int c=0; | 1091 | int c=0; |
1091 | int i=0; | 1092 | int i=0; |
1092 | struct in_addr ipaddress; | ||
1093 | 1093 | ||
1094 | int option_index = 0; | 1094 | int option_index = 0; |
1095 | static struct option long_options[] = | 1095 | static struct option long_options[] = |
@@ -1128,27 +1128,13 @@ int call_getopt(int argc, char **argv){ | |||
1128 | switch(c){ | 1128 | switch(c){ |
1129 | 1129 | ||
1130 | case 's': /* DHCP server address */ | 1130 | case 's': /* DHCP server address */ |
1131 | if(inet_aton(optarg,&ipaddress)){ | 1131 | resolve_host(optarg,&dhcp_ip); |
1132 | add_requested_server(ipaddress); | 1132 | add_requested_server(dhcp_ip); |
1133 | inet_aton(optarg, &dhcp_ip); | ||
1134 | if (verbose) | ||
1135 | printf("querying %s\n",inet_ntoa(dhcp_ip)); | ||
1136 | } | ||
1137 | /* | ||
1138 | else | ||
1139 | usage("Invalid server IP address\n"); | ||
1140 | */ | ||
1141 | break; | 1133 | break; |
1142 | 1134 | ||
1143 | case 'r': /* address we are requested from DHCP servers */ | 1135 | case 'r': /* address we are requested from DHCP servers */ |
1144 | if(inet_aton(optarg,&ipaddress)){ | 1136 | resolve_host(optarg,&requested_address); |
1145 | requested_address=ipaddress; | 1137 | request_specific_address=TRUE; |
1146 | request_specific_address=TRUE; | ||
1147 | } | ||
1148 | /* | ||
1149 | else | ||
1150 | usage("Invalid requested IP address\n"); | ||
1151 | */ | ||
1152 | break; | 1138 | break; |
1153 | 1139 | ||
1154 | case 't': /* timeout */ | 1140 | case 't': /* timeout */ |
@@ -1352,6 +1338,20 @@ long mac_addr_dlpi( const char *dev, int unit, u_char *addr){ | |||
1352 | #endif | 1338 | #endif |
1353 | 1339 | ||
1354 | 1340 | ||
1341 | /* resolve host name or die (TODO: move this to netutils.c!) */ | ||
1342 | void resolve_host(const char *in,struct in_addr *out){ | ||
1343 | struct addrinfo hints, *ai; | ||
1344 | |||
1345 | memset(&hints,0,sizeof(hints)); | ||
1346 | hints.ai_family=PF_INET; | ||
1347 | if (getaddrinfo(in,NULL,&hints,&ai) != 0) | ||
1348 | usage_va(_("Invalid hostname/address - %s"),optarg); | ||
1349 | |||
1350 | memcpy(out,&((struct sockaddr_in *)ai->ai_addr)->sin_addr,sizeof(*out)); | ||
1351 | freeaddrinfo(ai); | ||
1352 | } | ||
1353 | |||
1354 | |||
1355 | /* parse MAC address string, return 6 bytes (unterminated) or NULL */ | 1355 | /* parse MAC address string, return 6 bytes (unterminated) or NULL */ |
1356 | unsigned char *mac_aton(const char *string){ | 1356 | unsigned char *mac_aton(const char *string){ |
1357 | static unsigned char result[6]; | 1357 | static unsigned char result[6]; |