summaryrefslogtreecommitdiffstats
path: root/web/attachments/135800-nagiosplug-check_tcp-protocol.diff
blob: ea63efb6ed41b14ccd4d37e2bce298932eb4366c (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
diff -urN ../orig.nplg/plugins/check_tcp.c ./plugins/check_tcp.c
--- ../orig.nplg/plugins/check_tcp.c	2005-05-23 21:55:06.000000000 +0200
+++ ./plugins/check_tcp.c	2005-05-24 21:13:43.000000000 +0200
@@ -57,11 +57,7 @@
 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);
@@ -120,7 +116,7 @@
 		SEND = NULL;
 		EXPECT = NULL;
 		QUIT = NULL;
-		PROTOCOL = UDP_PROTOCOL;
+		PROTOCOL = IPPROTO_UDP;
 		PORT = 0;
 	}
 	else if (strstr (argv[0], "check_tcp")) {
@@ -129,7 +125,7 @@
 		SEND = NULL;
 		EXPECT = NULL;
 		QUIT = NULL;
-		PROTOCOL = TCP_PROTOCOL;
+		PROTOCOL = IPPROTO_TCP;
 		PORT = 0;
 	}
 	else if (strstr (argv[0], "check_ftp")) {
@@ -138,7 +134,7 @@
 		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")) {
@@ -147,7 +143,7 @@
 		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")) {
@@ -156,7 +152,7 @@
 		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")) {
@@ -165,7 +161,7 @@
 		SEND = NULL;
 		EXPECT = strdup ("* OK");
 		QUIT = strdup ("a1 LOGOUT\r\n");
-		PROTOCOL = TCP_PROTOCOL;
+		PROTOCOL = IPPROTO_TCP;
 		PORT = 143;
 	}
 #ifdef HAVE_SSL
@@ -175,7 +171,7 @@
 		SEND=NULL;
 		EXPECT = strdup ("* OK");
 		QUIT = strdup ("a1 LOGOUT\r\n");
-		PROTOCOL=TCP_PROTOCOL;
+		PROTOCOL=IPPROTO_TCP;
 		use_ssl=TRUE;
 		PORT=993;
 	}
@@ -185,7 +181,7 @@
 		SEND=NULL;
 		EXPECT = strdup ("+OK");
 		QUIT = strdup ("QUIT\r\n");
-		PROTOCOL=TCP_PROTOCOL;
+		PROTOCOL=IPPROTO_TCP;
 		use_ssl=TRUE;
 		PORT=995;
 	}
@@ -195,7 +191,7 @@
 		SEND=NULL;
 		EXPECT = strdup ("220");
 		QUIT = strdup ("QUIT\r\n");
-		PROTOCOL=TCP_PROTOCOL;
+		PROTOCOL=IPPROTO_TCP;
 		use_ssl=TRUE;
 		PORT=465;
 	}
@@ -205,7 +201,7 @@
 		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;
 	}
@@ -219,7 +215,7 @@
 		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;
 }
@@ -235,7 +231,7 @@
 		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 {
@@ -288,13 +284,7 @@
 		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;