summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxcommon
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-01 14:11:30 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-01 14:11:30 +0000
commitece7676a15f9e1f605ba673951d32c20b77d81cf (patch)
tree5013b0415a45dfdce92cb81ebff16fa5535275fa /src/libs/zbxcommon
parentd4ad33f2293ea6b8efb2f88b728b0835850e6085 (diff)
downloadzabbix-ece7676a15f9e1f605ba673951d32c20b77d81cf.tar.gz
zabbix-ece7676a15f9e1f605ba673951d32c20b77d81cf.tar.xz
zabbix-ece7676a15f9e1f605ba673951d32c20b77d81cf.zip
- [ZBX-182] ICMP using host names
[svn merge svn://svn.zabbix.com/branches/1.4 -r5304:5308] git-svn-id: svn://svn.zabbix.com/trunk@5309 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxcommon')
-rw-r--r--src/libs/zbxcommon/misc.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index 2f73cc41..56dceed9 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -233,6 +233,141 @@ int calculate_item_nextcheck(zbx_uint64_t itemid, int item_type, int delay, char
return i;
}
+/******************************************************************************
+ * *
+ * Function: is_ip4 *
+ * *
+ * Purpose: is string IPv4 address *
+ * *
+ * Parameters: ip - string *
+ * *
+ * Return value: SUCCEED - is IPv4 address *
+ * FAIL - otherwise *
+ * *
+ * Author: Alexei Vladishev, Aleksander Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int is_ip4(const char *ip)
+{
+ const char *p = ip;
+ int nums, dots, res = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In is_ip4() [%s]",
+ ip);
+
+ nums = 0;
+ dots = 0;
+ while ('\0' != *p) {
+ if (*p >= '0' && *p <= '9') {
+ nums++;
+ } else if (*p == '.') {
+ if (nums == 0 || nums > 3)
+ break;
+ nums = 0;
+ dots++;
+ } else {
+ nums = 0;
+ break;
+ }
+ p++;
+ }
+ if (dots == 3 && nums >= 1 && nums <= 3)
+ res = SUCCEED;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of is_ip4(result:%d)",
+ res);
+
+ return res;
+}
+
+#if defined(HAVE_IPV6)
+/******************************************************************************
+ * *
+ * Function: is_ip6 *
+ * *
+ * Purpose: is string IPv6 address *
+ * *
+ * Parameters: ip - string *
+ * *
+ * Return value: SUCCEED - is IPv6 address *
+ * FAIL - otherwise *
+ * *
+ * Author: Aleksader Vladishev *
+ * *
+ * Comments: could be improved (not supported x:x:x:x:x:x:d.d.d.d addresses) *
+ * *
+ ******************************************************************************/
+static int is_ip6(const char *ip)
+{
+ const char *p = ip;
+ int nums, is_nums, colons, dcolons, res = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In is_ip6() [%s]",
+ ip);
+
+ nums = 0;
+ is_nums = 0;
+ colons = 0;
+ dcolons = 0;
+ while ('\0' != *p) {
+ if ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'F') || (*p >= 'a' && *p <= 'f')) {
+ nums++;
+ is_nums = 1;
+ } else if (*p == ':') {
+ if (nums == 0 && colons > 0)
+ dcolons++;
+ if (nums > 4 || dcolons > 1)
+ break;
+ nums = 0;
+ colons++;
+ } else {
+ is_nums = 0;
+ break;
+ }
+ p++;
+ }
+ if (colons >= 2 && colons <= 7 && nums <= 4 && is_nums == 1)
+ res = SUCCEED;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of is_ip6(result:%d)",
+ res);
+
+ return res;
+}
+#endif /*HAVE_IPV6*/
+
+/******************************************************************************
+ * *
+ * Function: is_ip *
+ * *
+ * Purpose: is string IP address *
+ * *
+ * Parameters: ip - string *
+ * *
+ * Return value: SUCCEED - is IP address *
+ * FAIL - otherwise *
+ * *
+ * Author: Aleksader Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int is_ip(const char *ip)
+{
+ zabbix_log(LOG_LEVEL_DEBUG, "In is_ip() [%s]",
+ ip);
+
+ if (SUCCEED == is_ip4(ip))
+ return SUCCEED;
+#if defined(HAVE_IPV6)
+ if (SUCCEED == is_ip6(ip))
+ return SUCCEED;
+#endif /*HAVE_IPV6*/
+ return FAIL;
+}
+
#if defined(HAVE_IPV6)
/******************************************************************************
* *