Revision: 1882
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1882&view=rev
Author: hweiss
Date: 2007-12-21 05:25:28 -0800 (Fri, 21 Dec 2007)
Log Message:
-----------
New "-s" option to specify the source IP address (thanks to Harald Jenny
for providing the patch and to Patrick Cervicek for looking into it!)
Modified Paths:
--------------
nagiosplug/trunk/NEWS
nagiosplug/trunk/THANKS.in
nagiosplug/trunk/plugins-root/check_icmp.c
Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS 2007-12-21 04:23:44 UTC (rev 1881)
+++ nagiosplug/trunk/NEWS 2007-12-21 13:25:28 UTC (rev 1882)
@@ -3,6 +3,7 @@
1.4.12 or 1.5 ??
Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)
check_tcp now returns UNKNOWN with invalid hostname
+ New check_icmp -s option to specify the source IP address
1.4.11 13th December 2007
Fixed check_http regression in 1.4.10 where following redirects to
Modified: nagiosplug/trunk/THANKS.in
===================================================================
--- nagiosplug/trunk/THANKS.in 2007-12-21 04:23:44 UTC (rev 1881)
+++ nagiosplug/trunk/THANKS.in 2007-12-21 13:25:28 UTC (rev 1882)
@@ -230,3 +230,4 @@
fabiodds
Tom Payerle
Alessandro Ren
+Harald Jenny
Modified: nagiosplug/trunk/plugins-root/check_icmp.c
===================================================================
--- nagiosplug/trunk/plugins-root/check_icmp.c 2007-12-21 04:23:44 UTC (rev 1881)
+++ nagiosplug/trunk/plugins-root/check_icmp.c 2007-12-21 13:25:28 UTC (rev 1882)
@@ -54,6 +54,7 @@
#include "netutils.h"
#include "utils.h"
+#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
@@ -66,6 +67,7 @@
#include <ctype.h>
#include <netdb.h>
#include <sys/socket.h>
+#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
@@ -178,11 +180,13 @@
void print_usage (void);
static u_int get_timevar(const char *);
static u_int get_timevaldiff(struct timeval *, struct timeval *);
+static in_addr_t get_ip_address(const char *);
static int wait_for_reply(int, u_int);
static int recvfrom_wto(int, char *, unsigned int, struct sockaddr *, u_int *);
static int send_icmp_ping(int, struct rta_host *);
static int get_threshold(char *str, threshold *th);
static void run_checks(void);
+static void set_source_ip(char *);
static int add_target(char *);
static int add_target_ip(char *, struct in_addr *);
static int handle_random_icmp(struct icmp *, struct sockaddr_in *);
@@ -446,7 +450,7 @@
/* parse the arguments */
for(i = 1; i < argc; i++) {
- while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:i:b:I:l:m:")) != EOF) {
+ while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) {
switch(arg) {
case 'v':
debug++;
@@ -489,6 +493,9 @@
crit_down = (unsigned char)strtoul(ptr + 1, NULL, 0);
}
break;
+ case 's': /* specify source IP address */
+ set_source_ip(optarg);
+ break;
case 'V': /* version */
/*print_revision (progname, revision);*/ /* FIXME: Why? */
exit (STATE_OK);
@@ -1109,6 +1116,38 @@
return 0;
}
+
+static void
+set_source_ip(char *arg)
+{
+ struct sockaddr_in src;
+
+ memset(&src, 0, sizeof(src));
+ src.sin_family = AF_INET;
+ if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE)
+ src.sin_addr.s_addr = get_ip_address(arg);
+ if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1)
+ crash("Cannot bind to IP address %s", arg);
+}
+
+/* TODO: Move this to netutils.c and also change check_dhcp to use that. */
+static in_addr_t
+get_ip_address(const char *ifname)
+{
+#if defined(SIOCGIFADDR)
+ struct ifreq ifr;
+
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+ ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
+ crash("Cannot determine IP address of interface %s", ifname);
+ return ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
+#else
+ errno = 0;
+ crash("Cannot get interface IP address on this platform.");
+#endif
+}
+
/*
* u = micro
* m = milli
@@ -1231,6 +1270,8 @@
printf (" %s\n", "-c");
printf (" %s", _("critical threshold (currently "));
printf ("%0.3fms,%u%%)\n", (float)crit.rta, crit.pl);
+ printf (" %s\n", "-s");
+ printf (" %s\n", _("specify a source IP address or device name"));
printf (" %s\n", "-n");
printf (" %s", _("number of packets to send (currently "));
printf ("%u)\n",packets);
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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.