summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-29 13:04:53 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-29 13:04:53 +0000
commit8a3d1d2514dc71806644d23a8a2420f0bf290aeb (patch)
tree92435fa09d4f34cd668a3d5742cb9e04d7a79196 /src/libs
parent1af69e4b46054b7b2efca2b3d834e59caeab36f5 (diff)
downloadzabbix-8a3d1d2514dc71806644d23a8a2420f0bf290aeb.tar.gz
zabbix-8a3d1d2514dc71806644d23a8a2420f0bf290aeb.tar.xz
zabbix-8a3d1d2514dc71806644d23a8a2420f0bf290aeb.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@2916 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/zbxsysinfo/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/common/http.c92
2 files changed, 93 insertions, 1 deletions
diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am
index 77981f4f..522d2cd8 100644
--- a/src/libs/zbxsysinfo/Makefile.am
+++ b/src/libs/zbxsysinfo/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS=@ARCH@
libzbxsysinfo_a_LIBADD = ../zbxcommon/libzbxcommon.a ../zbxcrypto/libzbxcrypto.a
-libzbxsysinfo_a_SOURCES=common/common.c common/file.c common/ntp.c common/system.c @ARCH@/@ARCH@.c
+libzbxsysinfo_a_SOURCES=common/common.c common/file.c common/ntp.c common/system.c common/http.c @ARCH@/@ARCH@.c
lib_LIBRARIES=libzbxsysinfo.a
diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c
new file mode 100644
index 00000000..017d78c5
--- /dev/null
+++ b/src/libs/zbxsysinfo/common/http.c
@@ -0,0 +1,92 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+#include "log.h"
+
+int get_http_page(char *hostname, char *param, int port, char *buffer, int max_buf_len)
+{
+ char *haddr;
+ char c[1024];
+
+ int s;
+ struct sockaddr_in addr;
+ int addrlen, n, total;
+
+
+ struct hostent *host;
+
+ host = gethostbyname(hostname);
+ if(host == NULL)
+ {
+ return SYSINFO_RET_OK;
+ }
+
+ haddr=host->h_addr;
+
+ addrlen = sizeof(addr);
+ memset(&addr, 0, addrlen);
+ addr.sin_port = htons(port);
+ addr.sin_family = AF_INET;
+ bcopy(haddr, (void *) &addr.sin_addr.s_addr, 4);
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == -1)
+ {
+ close(s);
+ return SYSINFO_RET_OK;
+ }
+
+ if (connect(s, (struct sockaddr *) &addr, addrlen) == -1)
+ {
+ close(s);
+ return SYSINFO_RET_OK;
+ }
+
+ snprintf(c,1024-1,"GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname);
+
+ write(s,c,strlen(c));
+
+ memset(buffer, 0, max_buf_len);
+
+ total=0;
+ while((n=read(s, buffer+total, max_buf_len-1))>0)
+ {
+ total+=n;
+ printf("Read %d bytes\n", total);
+ }
+
+ close(s);
+ return SYSINFO_RET_OK;
+}
+#define ZABBIX_TEST
+
+#ifdef ZABBIX_TEST
+int main()
+{
+ char buffer[100*1024];
+
+ get_http_page("www.zabbix.com", "", 80, buffer, 100*1024);
+
+ printf("Back [%d] [%s]\n", strlen(buffer), buffer);
+}
+#endif