summaryrefslogtreecommitdiffstats
path: root/web/attachments/209934-check_ping-1.4.5-filtered-packets.diff
blob: e738d27777312bdf733432b4117b26e8970ab3a1 (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
diff -r -u nagios-plugins-1.4.5.old/plugins/check_ping.c nagios-plugins-1.4.5/plugins/check_ping.c
--- nagios-plugins-1.4.5.old/plugins/check_ping.c	2006-10-19 01:25:16.000000000 +0100
+++ nagios-plugins-1.4.5/plugins/check_ping.c	2007-01-05 18:17:12.000000000 +0000
@@ -503,6 +503,27 @@
 int
 error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
 {
+	/*
+	 * This constant shouldn't be here.  It is bad practice, and just
+	 * generally offensive to the sensibilities.  Unfortunately, the
+	 * relevant constant, MAX_HOST_ADDRESS_LENGTH, is an enum, which means
+	 * I can't compile-time cat it into a scanf format string.
+	 *
+	 * I could change the common header to work around this, but that's
+	 * invasive.  I could sprintf a scanf string, but then I need about 5
+	 * times the memory (for a sprintf buffer of unknown length).  Since I
+	 * intend to report my problem as a bug to the Nagios maintainers I'll
+	 * just leave it for them to fix as they feel best fits the
+	 * application -- they're the experts, after all, I'm just a device
+	 * for ensuring RFC1925 Section 2(1) compliancy, and this does it.  I
+	 * would never put this in my own code, got it?  I'm just not sure
+	 * what the house style dictates in this case.
+	 *
+	 * Maybe this variable shouldn't even be here -- it looks awfully
+	 * lonely, doesn't it?  Dunno.  It works for me, though.
+	 */
+	char filter_host[256+1];
+
 	if (strstr (buf, "Network is unreachable"))
 		die (STATE_CRITICAL, _("CRITICAL - Network unreachable (%s)"), addr);
 	else if (strstr (buf, "Destination Host Unreachable"))
@@ -511,6 +532,8 @@
 		die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr);
 	else if (strstr (buf, "Time to live exceeded"))
 		die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)"), addr);
+	else if (sscanf (buf, "From %256s %*s Packet filtered", filter_host) == 1)
+		die (STATE_CRITICAL, _("CRITICAL - Packet filtered by %s (%s)"), filter_host, addr);
 
 	if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
 		if (warn_text == NULL)