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
|
--- /tmp/nagios-plugins-1.3.0/plugins/check_time.c 2003-02-15 23:48:46.000000000 +1100
+++ nagios-plugins-1.3.0/plugins/check_time.c 2003-06-06 10:43:32.000000000 +1000
@@ -61,7 +61,7 @@
int check_critical_diff = FALSE;
int server_port = TIME_PORT;
char *server_address = NULL;
-
+int use_udp = FALSE;
int process_arguments (int, char **);
void print_usage (void);
@@ -85,7 +85,13 @@
time (&start_time);
/* try to connect to the host at the given port number */
- if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) {
+ if (use_udp) {
+ result = my_udp_connect (server_address, server_port, &sd);
+ } else {
+ result = my_tcp_connect (server_address, server_port, &sd);
+ }
+
+ if (result != STATE_OK) {
if (check_critical_time == TRUE)
result = STATE_CRITICAL;
else if (check_warning_time == TRUE)
@@ -94,7 +100,21 @@
result = STATE_UNKNOWN;
terminate (result,
"TIME UNKNOWN - could not connect to server %s, port %d\n",
- server_address, server_port);
+ server_address, server_port);
+ }
+
+ if (use_udp) {
+ if (send (sd, "", 0, 0) < 0) {
+ if (check_critical_time == TRUE)
+ result = STATE_CRITICAL;
+ else if (check_warning_time == TRUE)
+ result = STATE_WARNING;
+ else
+ result = STATE_UNKNOWN;
+ terminate (result,
+ "TIME UNKNOWN - could not send UDP request to server %s, port %d\n",
+ server_address, server_port);
+ }
}
/* watch for the connection string */
@@ -170,6 +190,7 @@
{"timeout", required_argument, 0, 't'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
+ {"udp", no_argument, 0, 'u'},
{0, 0, 0, 0}
};
#endif
@@ -193,10 +214,10 @@
while (1) {
#ifdef HAVE_GETOPT_H
c =
- getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options,
+ getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", long_options,
&option_index);
#else
- c = getopt (argc, argv, "hVH:w:c:W:C:p:t:");
+ c = getopt (argc, argv, "hVH:w:c:W:C:p:t:u");
#endif
if (c == -1 || c == EOF)
@@ -275,6 +296,9 @@
usage ("Timeout interval must be a nonnegative integer\n");
socket_timeout = atoi (optarg);
break;
+ case 'u':
+ /* udp */
+ use_udp = TRUE;
}
}
@@ -338,6 +362,8 @@
" Seconds before connection times out (default: %d)\n"
" -p, --port=INTEGER\n"
" Port number (default: %d)\n"
+ " -u, --udp\n"
+ " Use UDP to connect, not TCP\n"
" -h, --help\n"
" Print detailed help screen\n"
" -V, --version\n"
|