/*
- * $Id$
- *
- * DEBUG: section 42 ICMP Pinger program
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 42 ICMP Pinger program */
+
#define SQUID_HELPER 1
-#include "squid-old.h"
+#include "squid.h"
#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"
+
+#include <cerrno>
IcmpPinger::IcmpPinger() : Icmp()
{
Close();
}
-#if _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
void
Win32SockCleanup(void)
{
int
IcmpPinger::Open(void)
{
-#if _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)
{
-#if _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);
}
}
#endif /* USE_ICMP */
+