summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
authorHolger Weiss <hweiss@users.sourceforge.net>2007-07-26 17:32:37 (GMT)
committerHolger Weiss <hweiss@users.sourceforge.net>2007-07-26 17:32:37 (GMT)
commit0a02314e8d520766a9a00712ab49c02f1ebb7a63 (patch)
tree342b042a94e467c55dd2921cf2d5af70bb4d61c7 /plugins-root
parentee33124028a0a5adb13123c0683b04323d26c3b3 (diff)
downloadmonitoring-plugins-0a02314e8d520766a9a00712ab49c02f1ebb7a63.tar.gz
The "--serverip" and "--requestedip" options now accept host names, too.
This doesn't quite fit the option names and so far I haven't changed the "--help" output which currently only talks about IP addresses. However, I don't see why resolving host names should not be supported. Also note that for the moment, I added a quick'n'dirty resolve_host() function which should really go into netutils.c. I just wanted to think about its interface a bit more before providing such a function globally. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1766 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_dhcp.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index a0f150f..c6e5af8 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -243,6 +243,7 @@ int validate_arguments(void);
243void print_usage(void); 243void print_usage(void);
244void print_help(void); 244void print_help(void);
245 245
246void resolve_host(const char *in,struct in_addr *out);
246unsigned char *mac_aton(const char *); 247unsigned char *mac_aton(const char *);
247void print_hardware_address(const unsigned char *); 248void print_hardware_address(const unsigned char *);
248int get_hardware_address(int,char *); 249int get_hardware_address(int,char *);
@@ -1089,7 +1090,6 @@ int process_arguments(int argc, char **argv){
1089int call_getopt(int argc, char **argv){ 1090int 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!) */
1342void 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 */
1356unsigned char *mac_aton(const char *string){ 1356unsigned char *mac_aton(const char *string){
1357 static unsigned char result[6]; 1357 static unsigned char result[6];