summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-01-22 10:22:46 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-01-22 10:22:46 +0000
commit0dcb4e9f403253a308b088c145e7404c28de2008 (patch)
treebf43806b346e24fdf47ef7045d9b023f71a6462e /src
parent621cd1669477fe40dfcb023bd48cdff267be84df (diff)
downloadzabbix-0dcb4e9f403253a308b088c145e7404c28de2008.tar.gz
zabbix-0dcb4e9f403253a308b088c145e7404c28de2008.tar.xz
zabbix-0dcb4e9f403253a308b088c145e7404c28de2008.zip
- added possibility of hostname using (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3746 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/alphacode/poller/poller.c6
-rw-r--r--src/alphacode/poller/poller_epoll.c6
-rw-r--r--src/libs/zbxcomms/comms.c4
-rw-r--r--src/libs/zbxemail/email.c7
-rw-r--r--src/libs/zbxnet/security.c6
-rw-r--r--src/libs/zbxnet/zbxsock.c2
-rw-r--r--src/libs/zbxsysinfo/common/common.c35
-rw-r--r--src/libs/zbxsysinfo/common/http.c13
-rw-r--r--src/libs/zbxsysinfo/common/ntp.c7
-rw-r--r--src/zabbix_agent/active.c19
-rw-r--r--src/zabbix_get/Makefile.am2
-rw-r--r--src/zabbix_get/zabbix_get.c7
-rw-r--r--src/zabbix_sender/Makefile.am2
-rw-r--r--src/zabbix_server/nodewatcher/nodecomms.c4
-rw-r--r--src/zabbix_server/poller/checks_agent.c11
-rw-r--r--src/zabbix_snmptrapper/zabbix_snmptrapper.c3
16 files changed, 38 insertions, 96 deletions
diff --git a/src/alphacode/poller/poller.c b/src/alphacode/poller/poller.c
index f39e9518..ad24290f 100644
--- a/src/alphacode/poller/poller.c
+++ b/src/alphacode/poller/poller.c
@@ -171,11 +171,9 @@ int main()
for(i=0;i<NUM;i++)
{
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(ip);
-
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(ip)))
{
- perror("gethostbyname() failed");
+ perror("gethost() failed");
}
servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
diff --git a/src/alphacode/poller/poller_epoll.c b/src/alphacode/poller/poller_epoll.c
index 99df8cfb..bf2e9bb9 100644
--- a/src/alphacode/poller/poller_epoll.c
+++ b/src/alphacode/poller/poller_epoll.c
@@ -91,11 +91,9 @@ int main()
for(i=0;i<NUM;i++)
{
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(ip);
-
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(ip)))
{
- perror("gethostbyname() failed");
+ perror("gethost() failed");
}
servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
diff --git a/src/libs/zbxcomms/comms.c b/src/libs/zbxcomms/comms.c
index 7cbd8583..08ac0019 100644
--- a/src/libs/zbxcomms/comms.c
+++ b/src/libs/zbxcomms/comms.c
@@ -45,6 +45,7 @@
#include "common.h"
#include "comms.h"
+#include "zbxsock.h"
void zbx_tcp_init(zbx_sock_t *s)
{
@@ -76,9 +77,8 @@ int zbx_tcp_connect(zbx_sock_t *s, char *ip, int port)
memset(s, 0, sizeof(zbx_sock_t));
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(ip);
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(ip)))
{
// zabbix_log( LOG_LEVEL_WARNING, "Cannot resolve [%s]", ip);
return FAIL;
diff --git a/src/libs/zbxemail/email.c b/src/libs/zbxemail/email.c
index 7e1c9edf..4d745bdd 100644
--- a/src/libs/zbxemail/email.c
+++ b/src/libs/zbxemail/email.c
@@ -37,6 +37,7 @@
#include "common.h"
#include "log.h"
#include "zlog.h"
+#include "zbxsock.h"
#include "email.h"
@@ -65,15 +66,15 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL");
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(smtp_server);
- zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL2");
- if(hp==NULL)
+
+ if(NULL == (hp = zbx_gethost(smtp_server)))
{
zabbix_log(LOG_LEVEL_DEBUG, "Cannot get IP for mailserver [%s]",smtp_server);
zabbix_syslog("Cannot get IP for mailserver [%s]",smtp_server);
zbx_snprintf(error,max_error_len,"Cannot get IP for mailserver [%s]",smtp_server);
return FAIL;
}
+ zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL2");
servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
servaddr_in.sin_port=htons(25);
diff --git a/src/libs/zbxnet/security.c b/src/libs/zbxnet/security.c
index 96c52396..4a4376d6 100644
--- a/src/libs/zbxnet/security.c
+++ b/src/libs/zbxnet/security.c
@@ -87,11 +87,7 @@ int check_security(ZBX_SOCKET sock, char *ip_list, int allow_if_empty)
while( NULL != host )
{
/* Allow IP addresses or DNS names for authorization */
- if( 0 == (hp = gethostbyname(host)))
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error on gethostbyname, can not resolve [%s]",host);
- }
- else
+ if( 0 != (hp = zbx_gethost(host)))
{
sip = inet_ntoa(*((struct in_addr *)hp->h_addr));
if( 0 == strcmp(sname, sip))
diff --git a/src/libs/zbxnet/zbxsock.c b/src/libs/zbxnet/zbxsock.c
index bfc8d2eb..b7796d89 100644
--- a/src/libs/zbxnet/zbxsock.c
+++ b/src/libs/zbxnet/zbxsock.c
@@ -22,7 +22,7 @@
#include "log.h"
-struct hostent *zbx_gethost(char *hostname)
+struct hostent *zbx_gethost(const char *hostname)
{
unsigned int addr;
struct hostent* host;
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index 412d706e..000ed873 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -23,9 +23,9 @@
#include "alias.h"
#include "md5.h"
#include "log.h"
-#include "zbxsock.h"
#include "threads.h"
#include "cfg.h"
+#include "zbxsock.h"
ZBX_METRIC *commands=NULL;
extern ZBX_METRIC parameters_specific[];
@@ -1475,13 +1475,8 @@ static int forward_request(char *proxy, char *command, int port, unsigned flags,
init_result(result);
- if(NULL == (hp = gethostbyname(proxy)) )
+ if(NULL == (hp = zbx_gethost(proxy)) )
{
-#ifdef HAVE_HSTRERROR
- zabbix_log( LOG_LEVEL_DEBUG,"gethostbyname() failed for proxy '%s' [%s]", proxy, (char*)hstrerror((int)h_errno));
-#else
- zabbix_log( LOG_LEVEL_DEBUG,"gethostbyname() failed for proxy '%s' [%s]", proxy, strerror_from_system(h_errno));
-#endif
SET_MSG_RESULT(result, strdup("ZBX_NETWORK_ERROR"));
return SYSINFO_RET_FAIL;
}
@@ -1555,19 +1550,8 @@ static int tcp_expect(const char *hostname, short port, const char *request, con
*value_int = 0;
- if(NULL == (hp = gethostbyname(hostname)) )
+ if(NULL == (hp = zbx_gethost(hostname)) )
{
- zabbix_log(
- LOG_LEVEL_DEBUG,
- "gethostbyname() failed for host '%s' [%s]",
- hostname,
-#ifdef HAVE_HSTRERROR
- (char*)hstrerror((int)h_errno)
-#else
- strerror_from_system(h_errno)
-#endif
- );
-
return SYSINFO_RET_OK;
}
@@ -1727,19 +1711,8 @@ static int check_ssh(const char *hostname, short port, int *value_int)
*value_int = 0;
- if(NULL == (hp = gethostbyname(hostname)) )
+ if(NULL == (hp = zbx_gethost(hostname)) )
{
- zabbix_log(
- LOG_LEVEL_DEBUG,
- "gethostbyname() failed for host '%s' [%s]",
- hostname,
-#ifdef HAVE_HSTRERROR
- (char*)hstrerror((int)h_errno)
-#else
- strerror_from_system(h_errno)
-#endif
- );
-
return SYSINFO_RET_OK;
}
diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c
index d8862dca..b7219183 100644
--- a/src/libs/zbxsysinfo/common/http.c
+++ b/src/libs/zbxsysinfo/common/http.c
@@ -37,19 +37,8 @@ static int get_http_page(char *hostname, char *param, unsigned short port, char
struct hostent *hp;
- if(NULL == (hp = gethostbyname(hostname)) )
+ if(NULL == (hp = zbx_gethost(hostname)) )
{
- zabbix_log(
- LOG_LEVEL_DEBUG,
- "get_http_page - gethostbyname() failed for host '%s' [%s]",
- hostname,
-#ifdef HAVE_HSTRERROR
- (char*)hstrerror((int)h_errno)
-#else
- strerror_from_system(h_errno)
-#endif
- );
-
return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/common/ntp.c b/src/libs/zbxsysinfo/common/ntp.c
index be87c41f..164de72d 100644
--- a/src/libs/zbxsysinfo/common/ntp.c
+++ b/src/libs/zbxsysinfo/common/ntp.c
@@ -264,13 +264,8 @@ int check_ntp(char *host, unsigned short port, int *value_int)
*value_int = 0;
- if(NULL == (hp = gethostbyname(host)) )
+ if(NULL == (hp = zbx_gethost(host)) )
{
-#ifdef HAVE_HSTRERROR
- zabbix_log( LOG_LEVEL_DEBUG, "gethostbyname() failed for NTP server [%d]", (char*)hstrerror((int)h_errno));
-#else
- zabbix_log( LOG_LEVEL_DEBUG, "gethostbyname() failed for NTP server [%s]", strerror_from_system(h_errno));
-#endif
return SYSINFO_RET_OK;
}
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index 9a239cd0..cbbfb8b8 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -249,14 +249,13 @@ static int get_active_checks(char *server, unsigned short port, char *error, int
zabbix_log( LOG_LEVEL_DEBUG, "get_active_checks('%s',%u)", server, port);
- if(NULL == (hp = gethostbyname(server)) )
+ if(NULL == (hp = zbx_gethost(server)) )
{
#ifdef HAVE_HSTRERROR
- zbx_snprintf(error, max_error_len,"gethostbyname() failed for server '%s' [%s]", server, (char*)hstrerror((int)h_errno));
+ zbx_snprintf(error, max_error_len,"gethost() failed for server '%s' [%s]", server, (char*)hstrerror((int)h_errno));
#else
- zbx_snprintf(error, max_error_len,"gethostbyname() failed for server '%s' [%s]", server, strerror_from_system(h_errno));
+ zbx_snprintf(error, max_error_len,"gethost() failed for server '%s' [%s]", server, strerror_from_system(h_errno));
#endif
- zabbix_log( LOG_LEVEL_WARNING, error);
return NETWORK_ERROR;
}
@@ -368,18 +367,12 @@ static int send_value(char *server,unsigned short port,char *host, char *key,cha
zabbix_log( LOG_LEVEL_DEBUG, "In send_value('%s',%u,'%s','%s','%s','%s','%s','%s')",
server, port, host, key, lastlogsize, timestamp, source, severity);
- if(NULL == (hp = gethostbyname(server)))
- {
- addr = inet_addr(server);
- hp = gethostbyaddr((char *)&addr, 4, AF_INET);
- }
-
- if( NULL == hp )
+ if( NULL == (hp = zbx_gethost(server)))
{
#ifdef HAVE_HSTRERROR
- zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed for server '%s' [%s]", server, (char*)hstrerror((int)h_errno));
+ zabbix_log( LOG_LEVEL_WARNING, "gethost() failed for server '%s' [%s]", server, (char*)hstrerror((int)h_errno));
#else
- zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed for server '%s' [%s]", server, strerror_from_system(h_errno));
+ zabbix_log( LOG_LEVEL_WARNING, "gethost() failed for server '%s' [%s]", server, strerror_from_system(h_errno));
#endif
return FAIL;
}
diff --git a/src/zabbix_get/Makefile.am b/src/zabbix_get/Makefile.am
index 740c8d33..e38248ff 100644
--- a/src/zabbix_get/Makefile.am
+++ b/src/zabbix_get/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_get
zabbix_get_SOURCES = zabbix_get.c
-zabbix_get_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxsys/libzbxsys.a ../libs/zbxconf/libzbxconf.a
+zabbix_get_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxsys/libzbxsys.a ../libs/zbxconf/libzbxconf.a ../libs/zbxnet/libzbxnet.a
diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c
index 785bd80f..c8298d0e 100644
--- a/src/zabbix_get/zabbix_get.c
+++ b/src/zabbix_get/zabbix_get.c
@@ -43,6 +43,8 @@
#include "common.h"
+#include "zbxsock.h"
+
char *progname = NULL;
char title_message[] = "ZABBIX get - Communicate with ZABBIX agent";
char usage_message[] = "[-hv] -s<host name or IP> [-p<port number>] -k<key>";
@@ -145,11 +147,10 @@ static int get_value(char *server,int port,char *key,char *value)
/* printf("get_value([%s],[%d],[%s])",server,port,key);*/
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(server);
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(server)));
{
- zbx_error("Error on gethostbyname. [%s]", strerror(errno));
+ zbx_error("Error on gethost(). [%s]", strerror(errno));
return FAIL;
}
diff --git a/src/zabbix_sender/Makefile.am b/src/zabbix_sender/Makefile.am
index e17ec3ba..0406c742 100644
--- a/src/zabbix_sender/Makefile.am
+++ b/src/zabbix_sender/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_sender
zabbix_sender_SOURCES = zabbix_sender.c
-zabbix_sender_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxsys/libzbxsys.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxconf/libzbxconf.a ../libs/zbxcomms/libzbxcomms.a
+zabbix_sender_LDADD = ../libs/zbxcommon/libzbxcommon.a ../libs/zbxlog/libzbxlog.a ../libs/zbxsys/libzbxsys.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxconf/libzbxconf.a ../libs/zbxcomms/libzbxcomms.a ../libs/zbxnet/libzbxnet.a
diff --git a/src/zabbix_server/nodewatcher/nodecomms.c b/src/zabbix_server/nodewatcher/nodecomms.c
index 33d74f5c..1162339e 100644
--- a/src/zabbix_server/nodewatcher/nodecomms.c
+++ b/src/zabbix_server/nodewatcher/nodecomms.c
@@ -48,6 +48,7 @@
#include "db.h"
#include "log.h"
#include "zlog.h"
+#include "zbxsock.h"
#include "nodecomms.h"
@@ -103,9 +104,8 @@ int send_to_node(int dest_nodeid, int nodeid, char *data)
DBfree_result(result);
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(ip);
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(ip)))
{
zabbix_log( LOG_LEVEL_WARNING, "Cannot resolve [%s] for node [%d]", ip, dest_nodeid);
return FAIL;
diff --git a/src/zabbix_server/poller/checks_agent.c b/src/zabbix_server/poller/checks_agent.c
index 8f7921d2..36b3611c 100644
--- a/src/zabbix_server/poller/checks_agent.c
+++ b/src/zabbix_server/poller/checks_agent.c
@@ -18,6 +18,7 @@
**/
#include "checks_agent.h"
+#include "zbxsock.h"
/******************************************************************************
* *
@@ -59,22 +60,20 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
servaddr_in.sin_family=AF_INET;
if(item->useip==1)
{
- hp=gethostbyname(item->ip);
+ hp = zbx_gethost(item->ip);
}
else
{
- hp=gethostbyname(item->host);
+ hp = zbx_gethost(item->host);
}
if(hp==NULL)
{
#ifdef HAVE_HSTRERROR
- zbx_snprintf(error,sizeof(error),"gethostbyname() failed [%s]", hstrerror(h_errno));
- zabbix_log(LOG_LEVEL_WARNING, "%s", error);
+ zbx_snprintf(error,sizeof(error),"gethost() failed [%s]", hstrerror(h_errno));
result->msg=strdup(error);
#else
- zbx_snprintf(error,sizeof(error),"gethostbyname() failed [%d]", h_errno);
- zabbix_log(LOG_LEVEL_WARNING, "%s", error);
+ zbx_snprintf(error,sizeof(error),"gethost() failed [%d]", h_errno);
result->msg=strdup(error);
#endif
return NETWORK_ERROR;
diff --git a/src/zabbix_snmptrapper/zabbix_snmptrapper.c b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
index 4388d546..bab1caad 100644
--- a/src/zabbix_snmptrapper/zabbix_snmptrapper.c
+++ b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
@@ -144,9 +144,8 @@ int send_value(char *server,int port,char *shortname,char *value)
/* struct linger ling;*/
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(server);
- if(hp==NULL)
+ if(NULL == (hp = zbx_gethost(server)))
{
return FAIL;
}