SF.net SVN: nagiosplug: [1766] nagiosplug/trunk

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 1766
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1766&view=rev
Author:   hweiss
Date:     2007-07-26 10:32:37 -0700 (Thu, 26 Jul 2007)

Log Message:
-----------
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.

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/plugins-root/check_dhcp.c

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2007-07-26 12:38:53 UTC (rev 1765)
+++ nagiosplug/trunk/NEWS	2007-07-26 17:32:37 UTC (rev 1766)
@@ -13,6 +13,7 @@
 	  to check DHCP servers on remote networks
 	New check_dhcp -m/--mac option which allows for specifying the MAC
 	  address to use in the DHCP request
+	The check_dhcp -r and -s options now accept host names, too
 
 1.4.9 4th June 2006
 	Inclusion of contrib/check_cluster2 as check_cluster with some improvements

Modified: nagiosplug/trunk/plugins-root/check_dhcp.c
===================================================================
--- nagiosplug/trunk/plugins-root/check_dhcp.c	2007-07-26 12:38:53 UTC (rev 1765)
+++ nagiosplug/trunk/plugins-root/check_dhcp.c	2007-07-26 17:32:37 UTC (rev 1766)
@@ -243,6 +243,7 @@
 void print_usage(void);
 void print_help(void);
 
+void resolve_host(const char *in,struct in_addr *out);
 unsigned char *mac_aton(const char *);
 void print_hardware_address(const unsigned char *);
 int get_hardware_address(int,char *);
@@ -1089,7 +1090,6 @@
 int call_getopt(int argc, char **argv){
 	int c=0;
 	int i=0;
-	struct in_addr ipaddress;
 
 	int option_index = 0;
 	static struct option long_options[] =
@@ -1128,27 +1128,13 @@
 		switch(c){
 
 		case 's': /* DHCP server address */
-			if(inet_aton(optarg,&ipaddress)){
-				add_requested_server(ipaddress);
-				inet_aton(optarg, &dhcp_ip);
-				if (verbose)
-					printf("querying %s\n",inet_ntoa(dhcp_ip));
-			}
-			/*
-			else
-				usage("Invalid server IP address\n");
-			*/
+			resolve_host(optarg,&dhcp_ip);
+			add_requested_server(dhcp_ip);
 			break;
 
 		case 'r': /* address we are requested from DHCP servers */
-			if(inet_aton(optarg,&ipaddress)){
-				requested_address=ipaddress;
-				request_specific_address=TRUE;
-			        }
-			/*
-			else
-				usage("Invalid requested IP address\n");
-			*/
+			resolve_host(optarg,&requested_address);
+			request_specific_address=TRUE;
 			break;
 
 		case 't': /* timeout */
@@ -1352,6 +1338,20 @@
 #endif
 
 
+/* resolve host name or die (TODO: move this to netutils.c!) */
+void resolve_host(const char *in,struct in_addr *out){
+	struct addrinfo hints, *ai;
+
+	memset(&hints,0,sizeof(hints));
+	hints.ai_family=PF_INET;
+	if (getaddrinfo(in,NULL,&hints,&ai) != 0)
+		usage_va(_("Invalid hostname/address - %s"),optarg);
+
+	memcpy(out,&((struct sockaddr_in *)ai->ai_addr)->sin_addr,sizeof(*out));
+	freeaddrinfo(ai);
+	}
+
+
 /* parse MAC address string, return 6 bytes (unterminated) or NULL */
 unsigned char *mac_aton(const char *string){
 	static unsigned char result[6];


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.