summaryrefslogtreecommitdiffstats
path: root/web/attachments/154773-nagios_plugins-check_tcp.c.patch
blob: 3d547dfb0859eed0a4086affd13d042fcf49e9e1 (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
--- ../../original_sources/nagios-plugins-1.4.2/plugins/check_tcp.c	2005-06-05 13:43:58.000000000 -0400
+++ nagios-plugins-1.4.2/plugins/check_tcp.c	2005-11-02 10:21:56.000000000 -0500
@@ -78,6 +78,8 @@
 static char *server_address = NULL;
 static char *server_send = NULL;
 static char *server_quit = NULL;
+static char *lineend = "";
+static char *lineendquit = "\r\n";
 static char **server_expect;
 static size_t server_expect_count = 0;
 static size_t maxbytes = 0;
@@ -404,6 +406,7 @@
 		{"timeout", required_argument, 0, 't'},
 		{"protocol", required_argument, 0, 'P'},
 		{"port", required_argument, 0, 'p'},
+		{"lineend", required_argument, 0, 'l'},
 		{"send", required_argument, 0, 's'},
 		{"expect", required_argument, 0, 'e'},
 		{"maxbytes", required_argument, 0, 'm'},
@@ -445,7 +448,7 @@
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
+		c = getopt_long (argc, argv, "+hVv46H:l:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
 		                 longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
@@ -515,8 +518,30 @@
 			else
 				server_port = atoi (optarg);
 			break;
+		case 'l':
+		        switch (*optarg) {
+		              case 'n':
+                                      lineend = "\n";
+                                      lineendquit = lineend;
+                                      break;
+                              case 'r':
+                                      lineend = "\r";
+                                      lineendquit = lineend;
+                                      break;
+                              case 'b':
+                                      lineend = "\r\n";
+                                      lineendquit = lineend;
+                                      break;
+                              case 'e':
+                                      lineend = "";
+
+                                      break;
+                              default:
+				      usage4 (_("Unrecognized option to -l not r, n, b or e."));
+                        }
+			break;
 		case 's':
-			server_send = optarg;
+		        asprintf(&server_send, "%s%s", optarg, lineend);
 			break;
 		case 'e': /* expect string (may be repeated) */
 			EXPECT = NULL;
@@ -533,7 +558,7 @@
 			else
 				maxbytes = strtol (optarg, NULL, 0);
 		case 'q':
-			asprintf(&server_quit, "%s\r\n", optarg);
+			asprintf(&server_quit, "%s%s", optarg, lineendquit);
 			break;
 		case 'r':
 			if (!strncmp(optarg,"ok",2))
@@ -738,6 +763,10 @@
 	printf (_(UT_IPv46));
 
 	printf (_("\
+ -l, --lineend=b|e|n|r\n\
+    Ending on -s nd -q strings. b - both: <cr><lf> style, e - empty no\n\
+    end, n - newline: newline end, r - return: carriage return end\n\
+    Default is \"-l e -s <send> -l b -q <quit>\".\n\
  -s, --send=STRING\n\
     String to send to the server\n\
  -e, --expect=STRING\n\
@@ -783,6 +812,6 @@
                   [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
                   [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
                   [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
-                  [-D <days to cert expiry>] [-S <use SSL>]\n", progname);
+                  [-D <days to cert expiry>] [-S <use SSL>] [-l <n|r|b|e>]\n", progname);
 }