summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9d0badb)
raw | patch | inline | side by side (parent: 9d0badb)
author | M. Sean Finney <seanius@users.sourceforge.net> | |
Tue, 24 May 2005 20:25:19 +0000 (20:25 +0000) | ||
committer | M. Sean Finney <seanius@users.sourceforge.net> | |
Tue, 24 May 2005 20:25:19 +0000 (20:25 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1173 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_tcp.c | patch | blob | history | |
plugins/netutils.c | patch | blob | history | |
plugins/netutils.h | patch | blob | history |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index fd2fe66bc572a273e94eedf1c3322e0826f81bb1..1bf1f4cbb5df97af2a71fb07fd5ecd5671570db8 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
int check_certificate (X509 **);
#endif
-enum {
- TCP_PROTOCOL = 1,
- UDP_PROTOCOL = 2,
- MAXBUF = 1024
-};
+#define MAXBUF 1024
int process_arguments (int, char **);
int my_recv (void);
SEND = NULL;
EXPECT = NULL;
QUIT = NULL;
- PROTOCOL = UDP_PROTOCOL;
+ PROTOCOL = IPPROTO_UDP;
PORT = 0;
}
else if (strstr (argv[0], "check_tcp")) {
SEND = NULL;
EXPECT = NULL;
QUIT = NULL;
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 0;
}
else if (strstr (argv[0], "check_ftp")) {
SEND = NULL;
EXPECT = strdup ("220");
QUIT = strdup ("QUIT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 21;
}
else if (strstr (argv[0], "check_smtp")) {
SEND = NULL;
EXPECT = strdup ("220");
QUIT = strdup ("QUIT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 25;
}
else if (strstr (argv[0], "check_pop")) {
SEND = NULL;
EXPECT = strdup ("+OK");
QUIT = strdup ("QUIT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 110;
}
else if (strstr (argv[0], "check_imap")) {
SEND = NULL;
EXPECT = strdup ("* OK");
QUIT = strdup ("a1 LOGOUT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 143;
}
#ifdef HAVE_SSL
SEND=NULL;
EXPECT = strdup ("* OK");
QUIT = strdup ("a1 LOGOUT\r\n");
- PROTOCOL=TCP_PROTOCOL;
+ PROTOCOL=IPPROTO_TCP;
use_ssl=TRUE;
PORT=993;
}
SEND=NULL;
EXPECT = strdup ("+OK");
QUIT = strdup ("QUIT\r\n");
- PROTOCOL=TCP_PROTOCOL;
+ PROTOCOL=IPPROTO_TCP;
use_ssl=TRUE;
PORT=995;
}
SEND=NULL;
EXPECT = strdup ("220");
QUIT = strdup ("QUIT\r\n");
- PROTOCOL=TCP_PROTOCOL;
+ PROTOCOL=IPPROTO_TCP;
use_ssl=TRUE;
PORT=465;
}
SEND = strdup("<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n");
EXPECT = strdup("<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'");
QUIT = strdup("</stream:stream>\n");
- PROTOCOL=TCP_PROTOCOL;
+ PROTOCOL=IPPROTO_TCP;
use_ssl=TRUE;
PORT = 5222;
}
server_expect = realloc (server_expect, ++server_expect_count);
asprintf (&server_expect[server_expect_count - 1], "201");
QUIT = strdup("QUIT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
use_ssl=TRUE;
PORT = 563;
}
server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
asprintf (&server_expect[server_expect_count - 1], "201");
asprintf (&QUIT, "QUIT\r\n");
- PROTOCOL = TCP_PROTOCOL;
+ PROTOCOL = IPPROTO_TCP;
PORT = 119;
}
else {
result = connect_SSL ();
else
#endif
- {
- if (PROTOCOL == UDP_PROTOCOL)
- result = my_udp_connect (server_address, server_port, &sd);
- else
- /* default is TCP */
- result = my_tcp_connect (server_address, server_port, &sd);
- }
+ result = my_connect (server_address, server_port, &sd, PROTOCOL);
if (result == STATE_CRITICAL)
return STATE_CRITICAL;
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 1231c1efe87e67c71135955dc4d80c0ac19664c5..e7d5ba788b067ca154aeca088e7d1ab04a0191ab 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
int was_refused = FALSE;
int address_family = AF_UNSPEC;
-static int my_connect(const char *address, int port, int *sd, int proto);
/* handles socket timeouts */
void
socket_timeout_alarm_handler (int sig)
}
-/* connects to a host on a specified TCP port, sends a string,
- and gets a response */
-int
-process_tcp_request (const char *server_address, int server_port,
- const char *send_buffer, char *recv_buffer, int recv_size)
-{
- int result;
-
- result = process_request (server_address, server_port,
- IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
-
- return result;
-}
-
-
-/* connects to a host on a specified UDP port, sends a string, and gets a
- response */
-int
-process_udp_request (const char *server_address, int server_port,
- const char *send_buffer, char *recv_buffer, int recv_size)
-{
- int result;
-
- result = process_request (server_address, server_port,
- IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
-
- return result;
-}
-
-
-
/* connects to a host on a specified tcp port, sends a string, and gets a
response. loops on select-recv until timeout or eof to get all of a
multi-packet answer */
return result;
}
+
/* connects to a host on a specified port, sends a string, and gets a
response */
int
}
-/* opens a connection to a remote host/tcp port */
-int
-my_tcp_connect (const char *host_name, int port, int *sd)
-{
- int result;
-
- result = my_connect (host_name, port, sd, IPPROTO_TCP);
-
- return result;
-}
-
-
-/* opens a connection to a remote host/udp port */
-int
-my_udp_connect (const char *host_name, int port, int *sd)
-{
- int result;
-
- result = my_connect (host_name, port, sd, IPPROTO_UDP);
-
- return result;
-}
-
-
/* opens a tcp or udp connection to a remote host */
-static int
+int
my_connect (const char *host_name, int port, int *sd, int proto)
{
struct addrinfo hints;
}
-int
-send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
-{
- return send_request (sd, IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
-}
-
-
-int
-send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
-{
- return send_request (sd, IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
-}
-
-
int
send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)
{
return TRUE;
}
}
-
-int
-is_inet_addr (const char *address)
-{
- return resolve_host_or_addr (address, AF_INET);
-}
-
-#ifdef USE_IPV6
-int
-is_inet6_addr (const char *address)
-{
- return resolve_host_or_addr (address, AF_INET6);
-}
-#endif
-
-int
-is_hostname (const char *s1)
-{
-#ifdef USE_IPV6
- return resolve_host_or_addr (s1, address_family);
-#else
- return resolve_host_or_addr (s1, AF_INET);
-#endif
-}
-
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 2f31bdc83f3b33e30fed9ee6a52cb6bde81e001f..bd5320110d2bed1ca6d3800db9a5e4881d80a57f 100644 (file)
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
+/* process_request and wrapper macros */
+#define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
+ process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
+#define process_udp_request(addr, port, sbuf, rbuf, rsize) \
+ process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
int process_tcp_request2 (const char *address, int port,
const char *sbuffer, char *rbuffer, int rsize);
-int process_tcp_request (const char *address, int port,
- const char *sbuffer, char *rbuffer, int rsize);
-int process_udp_request (const char *address, int port,
- const char *sbuffer, char *rbuffer, int rsize);
int process_request (const char *address, int port, int proto,
const char *sbuffer, char *rbuffer, int rsize);
-int my_tcp_connect (const char *address, int port, int *sd);
-int my_udp_connect (const char *address, int port, int *sd);
+/* my_connect and wrapper macros */
+#define my_tcp_connect(addr, port, s) my_connect(addr, port, s, IPPROTO_TCP)
+#define my_udp_connect(addr, port, s) my_connect(addr, port, s, IPPROTO_UDP)
+int my_connect(const char *address, int port, int *sd, int proto);
-int send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
-int send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
+/* send_request and wrapper macros */
+#define send_tcp_request(s, sbuf, rbuf, rsize) \
+ send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
+#define send_udp_request(s, sbuf, rbuf, rsize) \
+ send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
+
+/* "is_*" wrapper macros and functions */
int is_host (const char *);
int is_addr (const char *);
int resolve_host_or_addr (const char *, int);
-int is_inet_addr (const char *);
+#define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
#ifdef USE_IPV6
-int is_inet6_addr (const char *);
+# define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
+# define is_hostname(addr) resolve_host_or_addr(addr, address_family)
+#else
+# define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
#endif
-int is_hostname (const char *);
extern unsigned int socket_timeout;
extern int econn_refuse_state;