]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/IcmpPinger.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / icmp / IcmpPinger.cc
index 9827f17bee224a3ce920538aca5158f962e1bc5e..49bf8c55b28a88f818f45e365ffbeca92bda640c 100644 (file)
@@ -1,48 +1,26 @@
 /*
- * $Id: ICMPPinger.cc,v 1.1 2007/12/14 23:11:45 amosjeffries Exp $
- *
- * 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.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()
 {
@@ -56,7 +34,7 @@ IcmpPinger::~IcmpPinger()
     Close();
 }
 
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 void
 Win32SockCleanup(void)
 {
@@ -68,7 +46,7 @@ Win32SockCleanup(void)
 int
 IcmpPinger::Open(void)
 {
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 
     WSADATA wsaData;
     WSAPROTOCOL_INFO wpi;
@@ -88,30 +66,30 @@ IcmpPinger::Open(void)
 
     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;
     }
 
-    xmemcpy(&wpi, buf, sizeof(wpi));
+    memcpy(&wpi, buf, sizeof(wpi));
 
     write(1, "OK\n", 3);
     x = read(0, buf, sizeof(PS));
 
     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;
     }
 
-    xmemcpy(&PS, buf, sizeof(PS));
+    memcpy(&PS, buf, sizeof(PS));
 
     icmp_sock = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &wpi, 0, 0);
 
     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;
     }
@@ -120,7 +98,7 @@ IcmpPinger::Open(void)
 
     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;
     }
@@ -130,19 +108,19 @@ IcmpPinger::Open(void)
     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;
@@ -150,7 +128,7 @@ IcmpPinger::Open(void)
 
     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 ??
@@ -162,7 +140,7 @@ IcmpPinger::Open(void)
 void
 IcmpPinger::Close(void)
 {
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 
     shutdown(icmp_sock, SD_BOTH);
     close(icmp_sock);
@@ -171,9 +149,7 @@ IcmpPinger::Close(void)
 
     /* also shutdown the helper engines */
     icmp4.Close();
-#if USE_IPV6
     icmp6.Close();
-#endif
 }
 
 void
@@ -187,14 +163,14 @@ IcmpPinger::Recv(void)
     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);
@@ -208,27 +184,24 @@ IcmpPinger::Recv(void)
         return;
     }
 
-#if USE_IPV6
     /* 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,
                        pecho.payload,
                        pecho.psize);
     }
-#endif
 
     /* 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 );
+    } else {
+        debugs(42, DBG_IMPORTANT, HERE << " IP has unknown Type. " << pecho.to );
     }
 }
 
@@ -238,10 +211,11 @@ IcmpPinger::SendResult(pingerReplyData &preply, int len)
     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 */
+