summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxcommon
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-04-14 11:28:27 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-04-14 11:28:27 +0000
commite77f9ad3928b55a41898857f6ebb8a61cadeab75 (patch)
treed2baab46793cf4c516acc966f26139b4fdf3c752 /src/libs/zbxcommon
parent6ac30e45bc36b7122993ae192240c6b1f1f2f2c3 (diff)
downloadzabbix-e77f9ad3928b55a41898857f6ebb8a61cadeab75.tar.gz
zabbix-e77f9ad3928b55a41898857f6ebb8a61cadeab75.tar.xz
zabbix-e77f9ad3928b55a41898857f6ebb8a61cadeab75.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@4008 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxcommon')
-rw-r--r--src/libs/zbxcommon/misc.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index 5cd23756..57550ceb 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -235,6 +235,72 @@ int calculate_item_nextcheck(zbx_uint64_t itemid, int item_type, int delay, char
/******************************************************************************
* *
+ * Function: ip_in_list *
+ * *
+ * Purpose: check if ip matches range of ip addresses *
+ * *
+ * Parameters: list - IPs [192.168.1.1-244,192.168.1.250] *
+ * value- value *
+ * *
+ * Return value: FAIL - out of range, SUCCEED - within the range *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int ip_in_list(const char *list, char *ip)
+{
+ char tmp[MAX_STRING_LEN];
+ char tmp_ip[MAX_STRING_LEN];
+ char *s;
+ int i1,i2,i3,i4,i5;
+ int ret = FAIL;
+
+
+ zabbix_log( LOG_LEVEL_WARNING, "In ip_in_list(list:%s,ip:%s)",
+ list,
+ ip);
+
+ strscpy(tmp,list);
+ s=(char *)strtok(tmp,",");
+ while(s!=NULL)
+ {
+ zabbix_log(LOG_LEVEL_WARNING,"IP [%s]", s);
+
+ if(sscanf(s,"%d.%d.%d.%d-%d",&i1,&i2,&i3,&i4,&i5) == 5)
+ {
+ zbx_snprintf(tmp_ip,sizeof(tmp_ip)-1,"%d.%d.%d.%d",i1,i2,i3,i4);
+ if(strcmp(ip,tmp_ip)>=0)
+ {
+ zbx_snprintf(tmp_ip,sizeof(tmp_ip)-1,"%d.%d.%d.%d",i1,i2,i3,i5);
+ if(strcmp(ip,tmp_ip)<=0)
+ {
+ ret = SUCCEED;
+ break;
+ }
+ }
+ }
+ else if(sscanf(s,"%d.%d.%d.%d",&i1,&i2,&i3,&i4) == 4)
+ {
+ zbx_snprintf(tmp_ip,sizeof(tmp_ip)-1,"%d.%d.%d.%d",i1,i2,i3,i4);
+ if(strcmp(ip,tmp_ip) == 0)
+ {
+ ret = SUCCEED;
+ break;
+ }
+ }
+
+ s=(char *)strtok(NULL,",");
+ }
+
+ zabbix_log( LOG_LEVEL_WARNING, "End ip_in_list(ret:%s)", ret == SUCCEED?"SUCCEED":"FAIL");
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
* Function: int_in_list *
* *
* Purpose: check if integer matches a list of integers *