Код: Выделить всё
# diff -Naur check_ping_orig.c check_ping.c
--- check_ping_orig.c 2008-05-07 13:02:42.000000000 +0300
+++ check_ping.c 2009-09-06 01:42:26.000000000 +0300
@@ -67,6 +67,7 @@
int max_addr = 1;
int max_packets = -1;
int verbose = 0;
+char *interface = NULL;
float rta = UNKNOWN_TRIP_TIME;
int pl = UNKNOWN_PACKET_LOSS;
@@ -125,12 +126,12 @@
/* 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, addresses[i], interface);
# else
- asprintf (&cmd, rawcmd, max_packets, addresses[i]);
+ asprintf (&cmd, rawcmd, max_packets, addresses[i], interface);
# endif
#else
- asprintf (&cmd, rawcmd, addresses[i], max_packets);
+ asprintf (&cmd, rawcmd, addresses[i], max_packets, interface);
#endif
if (verbose >= 2)
@@ -138,7 +139,7 @@
/* run the command */
this_result = run_ping (cmd, addresses[i]);
-
+
if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) {
printf ("%s\n", cmd);
die (STATE_UNKNOWN,
@@ -204,6 +205,7 @@
{"link", no_argument, 0, 'L'},
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
+ {"interface", required_argument, 0, 'I'},
{0, 0, 0, 0}
};
@@ -218,7 +220,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:I:", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -230,6 +232,11 @@
print_help ();
exit (STATE_OK);
break;
+
+ case 'I': /* interface */
+ interface = optarg;
+ break;
+
case 'V': /* version */
print_revision (progname, revision);
exit (STATE_OK);
@@ -401,6 +408,10 @@
printf (_("<cpl> was not set\n"));
return ERROR;
}
+ else if (interface == NULL) {
+ printf (_("<interface> was not set\n"));
+ return ERROR;
+ }
else if (wrta > crta) {
printf (_("<wrta> (%f) cannot be larger than <crta> (%f)\n"), wrta, crta);
return ERROR;
@@ -585,6 +596,10 @@
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+ printf (" %s\n", "-I <interface_address>");
+ printf (" %s\n ", _("Set source address to specified interface address. Argument may be numeric IP address"));
+ printf (" %s\n ", _("or name of device. When pinging IPv6 link-local address this option is required."));
+
printf ("\n");
printf ("%s\n", _("THRESHOLD is <rta>,<pl>% where <rta> is the round trip average travel"));
printf ("%s\n", _("time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the"));
@@ -609,6 +624,6 @@
print_usage (void)
{
printf (_("Usage:"));
- printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n", progname);
+ printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%% -I <interface>\n", progname);
printf (" [-p packets] [-t timeout] [-4|-6]\n");
}