summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxicmpping/icmpping.c
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-08-01 08:19:27 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-08-01 08:19:27 +0000
commitcca9b9f61d00f638b51ad9286da82865f63c4e08 (patch)
treef31f43477beebb3f1ad97a95d70e79584e05e0aa /src/libs/zbxicmpping/icmpping.c
parent4daf306cbcec1cc1eaf44c7b85b62e2e16f0e995 (diff)
downloadzabbix-cca9b9f61d00f638b51ad9286da82865f63c4e08.tar.gz
zabbix-cca9b9f61d00f638b51ad9286da82865f63c4e08.tar.xz
zabbix-cca9b9f61d00f638b51ad9286da82865f63c4e08.zip
- [DEV-195] added support of source ip address
git-svn-id: svn://svn.zabbix.com/trunk@5858 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxicmpping/icmpping.c')
-rw-r--r--src/libs/zbxicmpping/icmpping.c73
1 files changed, 61 insertions, 12 deletions
diff --git a/src/libs/zbxicmpping/icmpping.c b/src/libs/zbxicmpping/icmpping.c
index cbe62502..983bb16c 100644
--- a/src/libs/zbxicmpping/icmpping.c
+++ b/src/libs/zbxicmpping/icmpping.c
@@ -22,9 +22,10 @@
#include "log.h"
#include "zlog.h"
-extern char *CONFIG_FPING_LOCATION;
+extern char *CONFIG_SOURCE_IP;
+extern char *CONFIG_FPING_LOCATION;
#ifdef HAVE_IPV6
-extern char *CONFIG_FPING6_LOCATION;
+extern char *CONFIG_FPING6_LOCATION;
#endif /* HAVE_IPV6 */
/******************************************************************************
@@ -48,9 +49,14 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count)
FILE *f;
char filename[MAX_STRING_LEN];
char tmp[MAX_STRING_LEN];
- int i;
- char *c;
+ int i, res = FAIL;
+ char *c, source_ip[64];
ZBX_FPING_HOST *host;
+#ifdef HAVE_IPV6
+ struct addrinfo hints, *ai = NULL;
+ char *fping;
+ int e;
+#endif
zabbix_log(LOG_LEVEL_DEBUG, "In do_ping() [hosts_count:%d]",
hosts_count);
@@ -73,15 +79,51 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count)
fclose(f);
+ if (NULL != CONFIG_SOURCE_IP)
+ zbx_snprintf(source_ip, sizeof(source_ip), "-S%s ", CONFIG_SOURCE_IP);
+ else
+ *source_ip = '\0';
+
#ifdef HAVE_IPV6
- zbx_snprintf(tmp, sizeof(tmp), "%s -c3 2>/dev/null <%s;%s -c3 2>/dev/null <%s",
- CONFIG_FPING_LOCATION,
- filename,
- CONFIG_FPING6_LOCATION,
- filename);
+ if (NULL != CONFIG_SOURCE_IP)
+ {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_flags = AI_NUMERICHOST;
+ hints.ai_socktype = SOCK_STREAM;
+
+ if (0 != (e = getaddrinfo(CONFIG_SOURCE_IP, NULL, &hints, &ai)))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Cannot resolve address [%s], error %d: %s",
+ CONFIG_SOURCE_IP, e, gai_strerror(e));
+ goto out;
+ }
+
+ if (ai->ai_family == PF_INET)
+ fping = CONFIG_FPING_LOCATION;
+ else if (ai->ai_family == PF_INET6)
+ fping = CONFIG_FPING6_LOCATION;
+ else
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Unsupported address family [%s]", CONFIG_SOURCE_IP);
+ goto out;
+ }
+
+ zbx_snprintf(tmp, sizeof(tmp), "%s %s-c3 2>/dev/null <%s",
+ fping,
+ source_ip,
+ filename);
+ }
+ else
+ zbx_snprintf(tmp, sizeof(tmp), "%s -c3 2>/dev/null <%s;%s -c3 2>/dev/null <%s",
+ CONFIG_FPING_LOCATION,
+ filename,
+ CONFIG_FPING6_LOCATION,
+ filename);
#else /* HAVE_IPV6 */
- zbx_snprintf(tmp, sizeof(tmp), "%s -c3 2>/dev/null <%s",
+ zbx_snprintf(tmp, sizeof(tmp), "%s %s-c3 2>/dev/null <%s",
CONFIG_FPING_LOCATION,
+ source_ip,
filename);
#endif /* HAVE_IPV6 */
@@ -92,7 +134,7 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count)
zabbix_syslog("Cannot execute [%s] [%s]",
CONFIG_FPING_LOCATION,
strerror(errno));
- return FAIL;
+ goto out;
}
while (NULL != fgets(tmp, sizeof(tmp), f)) {
@@ -123,10 +165,17 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count)
}
pclose(f);
+ res = SUCCEED;
+out:
unlink(filename);
+#ifdef HAVE_IPV6
+ if (NULL != ai)
+ freeaddrinfo(ai);
+#endif
+
zabbix_log(LOG_LEVEL_DEBUG, "End of do_ping()");
- return SUCCEED;
+ return res;
}