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
|
diff -uNr nagios-plugins-1.4.3.old/plugins/check_ping.c nagios-plugins-1.4.3/plugins/check_ping.c
--- nagios-plugins-1.4.3.old/plugins/check_ping.c 2006-03-13 06:08:28.000000000 -0500
+++ nagios-plugins-1.4.3/plugins/check_ping.c 2006-05-19 11:33:42.000000000 -0400
@@ -50,6 +50,7 @@
float wrta = UNKNOWN_TRIP_TIME;
float crta = UNKNOWN_TRIP_TIME;
char **addresses = NULL;
+char *source_address;
int n_addresses = 0;
int max_addr = 1;
int max_packets = -1;
@@ -67,6 +68,7 @@
{
char *cmd = NULL;
char *rawcmd = NULL;
+ char *ping_args = NULL;
int result = STATE_UNKNOWN;
int this_result = STATE_UNKNOWN;
int i;
@@ -101,15 +103,28 @@
rawcmd = strdup(PING_COMMAND);
#endif
+ ping_args = strdup("");
+
+ /* Need to check ping -I in configure and enclose this in ifdef */
+ if (source_address != NULL) {
+ ping_args = realloc (ping_args, 20 * sizeof(char));
+ ping_args = strcat(ping_args, "-I ");
+ ping_args = strncat(ping_args, source_address, 15 * sizeof(char));
+ ping_args = strcat(ping_args, " ");
+ }
+
+ ping_args = realloc (ping_args, strlen(ping_args) + strlen(addresses[i]) + 1);
+ ping_args = strcat(ping_args, addresses[i]);
+
/* does the host address of number of packets argument come first? */
#ifdef PING_PACKETS_FIRST
# ifdef PING_HAS_TIMEOUT
- asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
+ asprintf (&cmd, rawcmd, timeout_interval, max_packets, ping_args);
# else
- asprintf (&cmd, rawcmd, max_packets, addresses[i]);
+ asprintf (&cmd, rawcmd, max_packets, ping_args);
# endif
#else
- asprintf (&cmd, rawcmd, addresses[i], max_packets);
+ asprintf (&cmd, rawcmd, ping_args, max_packets);
#endif
if (verbose >= 2)
@@ -150,6 +165,7 @@
printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
result = max_state (result, this_result);
+ free (ping_args);
free (rawcmd);
free (cmd);
}
@@ -170,6 +186,7 @@
static struct option longopts[] = {
STD_LONG_OPTS,
{"packets", required_argument, 0, 'p'},
+ {"source", required_argument, 0, 's'},
{"nohtml", no_argument, 0, 'n'},
{"link", no_argument, 0, 'L'},
{"use-ipv4", no_argument, 0, '4'},
@@ -188,7 +205,7 @@
}
while (1) {
- c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option);
+ c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:s:", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -245,6 +262,9 @@
else
usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg);
break;
+ case 's': /* number of packets to send */
+ source_address = strdup (optarg);
+ break;
case 'n': /* no HTML */
display_html = FALSE;
break;
@@ -396,6 +416,11 @@
usage (_("You must specify a server address or host name"));
}
+ if (source_address != NULL) {
+ if (is_addr(source_address) == FALSE)
+ usage2 (_("Invalid source address"), source_address);
+ }
+
return OK;
}
@@ -535,6 +560,8 @@
critical threshold pair\n\
-p, --packets=INTEGER\n\
number of ICMP ECHO packets to send (Default: %d)\n\
+-s, --source=IP\n\
+ source address\n\
-L, --link\n\
show HTML in the plugin output (obsoleted by urlize)\n"),
DEFAULT_MAX_PACKETS);
@@ -559,5 +586,5 @@
print_usage (void)
{
printf ("Usage: %s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n\
- [-p packets] [-t timeout] [-L] [-4|-6]\n", progname);
+ [-p packets] [-s source_address] [-t timeout] [-L] [-4|-6]\n", progname);
}
|