/*
- * $Id$
- *
* DEBUG: section 42 ICMP Pinger program
* AUTHOR: Duane Wessels
*
#if USE_ICMP
-#include "SquidTime.h"
-#include "IcmpPinger.h"
+#include "Debug.h"
#include "Icmp4.h"
#include "Icmp6.h"
-#include "Debug.h"
+#include "IcmpPinger.h"
+#include "SquidTime.h"
+
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
IcmpPinger::IcmpPinger() : Icmp()
{
Close();
}
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
void
Win32SockCleanup(void)
{
int
IcmpPinger::Open(void)
{
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
WSADATA wsaData;
WSAPROTOCOL_INFO wpi;
if (x < (int)sizeof(wpi)) {
getCurrentTime();
- debugs(42, 0, HERE << "read: FD 0: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "read: FD 0: " << xstrerror());
write(1, "ERR\n", 4);
return -1;
}
if (x < (int)sizeof(PS)) {
getCurrentTime();
- debugs(42, 0, HERE << "read: FD 0: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "read: FD 0: " << xstrerror());
write(1, "ERR\n", 4);
return -1;
}
if (icmp_sock == -1) {
getCurrentTime();
- debugs(42, 0, HERE << "WSASocket: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "WSASocket: " << xstrerror());
write(1, "ERR\n", 4);
return -1;
}
if (SOCKET_ERROR == x) {
getCurrentTime();
- debugs(42, 0, HERE << "connect: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "connect: " << xstrerror());
write(1, "ERR\n", 4);
return -1;
}
x = recv(icmp_sock, (void *) buf, sizeof(buf), 0);
if (x < 3) {
- debugs(42, 0, HERE << "recv: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "recv: " << xstrerror());
return -1;
}
x = send(icmp_sock, (const void *) buf, strlen(buf), 0);
if (x < 3 || strncmp("OK\n", buf, 3)) {
- debugs(42, 0, HERE << "recv: " << xstrerror());
+ debugs(42, DBG_CRITICAL, HERE << "recv: " << xstrerror());
return -1;
}
getCurrentTime();
- debugs(42, 1, "pinger: Squid socket opened");
+ debugs(42, DBG_IMPORTANT, "pinger: Squid socket opened");
/* windows uses a socket stream as a dual-direction channel */
socket_to_squid = icmp_sock;
return icmp_sock;
-#else /* !_SQUID_MSWIN_ */
+#else /* !_SQUID_WINDOWS_ */
/* non-windows apps use stdin/out pipes as the squid channel(s) */
socket_from_squid = 0; // use STDIN macro ??
void
IcmpPinger::Close(void)
{
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
shutdown(icmp_sock, SD_BOTH);
close(icmp_sock);
n = recv(socket_from_squid, &pecho, sizeof(pecho), 0);
if (n < 0) {
- debugs(42, 1, "Pinger exiting.");
+ debugs(42, DBG_IMPORTANT, "Pinger exiting.");
Close();
exit(1);
}
if (0 == n) {
/* EOF indicator */
- debugs(42, 0, HERE << "EOF encountered. Pinger exiting.\n");
+ debugs(42, DBG_CRITICAL, HERE << "EOF encountered. Pinger exiting.\n");
errno = 0;
Close();
exit(1);
}
/* pass request for ICMPv6 handing */
- if (pecho.to.IsIPv6()) {
+ if (pecho.to.isIPv6()) {
debugs(42, 2, HERE << " Pass " << pecho.to << " off to ICMPv6 module.");
icmp6.SendEcho(pecho.to,
pecho.opcode,
}
/* pass the packet for ICMP handling */
- else if (pecho.to.IsIPv4()) {
+ else if (pecho.to.isIPv4()) {
debugs(42, 2, HERE << " Pass " << pecho.to << " off to ICMPv4 module.");
icmp4.SendEcho(pecho.to,
pecho.opcode,
pecho.payload,
pecho.psize);
} else {
- debugs(42, 1, HERE << " IP has unknown Type. " << pecho.to );
+ debugs(42, DBG_IMPORTANT, HERE << " IP has unknown Type. " << pecho.to );
}
}
debugs(42, 2, HERE << "return result to squid. len=" << len);
if (send(socket_to_squid, &preply, len, 0) < 0) {
- debugs(42, 0, "pinger: FATAL error on send: " << xstrerror());
+ debugs(42, DBG_CRITICAL, "pinger: FATAL error on send: " << xstrerror());
Close();
exit(1);
}