summaryrefslogtreecommitdiffstats
path: root/include/comms.h
blob: dc7d1a518eebcfd1115c554d74fd834344f1e543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 
** 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.
**/

#ifndef ZABBIX_COMMS_H
#define ZABBIX_COMMS_H

#if defined(SOCKET)
	typedef SOCKET ZBX_SOCKET;
#else /* not SOCKET */
	typedef int ZBX_SOCKET;
#endif /* SOCKET */

typedef struct sockaddr_in ZBX_SOCKADDR;

typedef enum
{
	ZBX_BUF_TYPE_STAT = 0,
	ZBX_BUF_TYPE_DYN
} zbx_buf_type_t;

#define ZBX_STAT_BUF_LEN	2048

typedef struct zbx_sock
{
	ZBX_SOCKET	socket;
	ZBX_SOCKET	socket2;
	char		buf_stat[ZBX_STAT_BUF_LEN];
	char		*buf_dyn;
	zbx_buf_type_t	buf_type;
	unsigned char accepted;
	char		*error;
} zbx_sock_t;

char*	zbx_tcp_strerror(void);

struct hostent	*zbx_gethost(const char *hostname);

void	zbx_tcp_init(zbx_sock_t *s);
int     zbx_tcp_connect(zbx_sock_t *s, const char *ip, unsigned short port);

#define ZBX_TCP_NEW_PROTOCOL	0x01

#define zbx_tcp_send(s, d)		zbx_tcp_send_ext((s), (d), ZBX_TCP_NEW_PROTOCOL)
#define zbx_tcp_send_raw(s, d)	zbx_tcp_send_ext((s), (d), 0)

int     zbx_tcp_send_ext(zbx_sock_t *s, const char *data, unsigned char flags);

void    zbx_tcp_close(zbx_sock_t *s);

int zbx_tcp_listen(
	zbx_sock_t		*s,
	const char		*listen_ip,
	unsigned short	listen_port
	);

int	zbx_tcp_accept(zbx_sock_t *s);
void	zbx_tcp_unaccept(zbx_sock_t *s);

void    zbx_tcp_free(zbx_sock_t *s);

int	zbx_tcp_recv(zbx_sock_t *s, char **data);

int	zbx_tcp_check_security(
	zbx_sock_t *s, 
	const char *ip_list, 
	int allow_if_empty
	);

#endif