]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/IcmpPinger.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / icmp / IcmpPinger.cc
index f5b2a77d59daa189912a11b82216042ac5455ed7..e49c69b8cdc62772566b815fd47662ef1d965a18 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: ICMPPinger.cc,v 1.1 2007/12/14 23:11:45 amosjeffries Exp $
- *
  * 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()
 {
@@ -56,7 +58,7 @@ IcmpPinger::~IcmpPinger()
     Close();
 }
 
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 void
 Win32SockCleanup(void)
 {
@@ -68,7 +70,7 @@ Win32SockCleanup(void)
 int
 IcmpPinger::Open(void)
 {
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 
     WSADATA wsaData;
     WSAPROTOCOL_INFO wpi;
@@ -88,30 +90,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 +122,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 +132,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 +152,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 +164,7 @@ IcmpPinger::Open(void)
 void
 IcmpPinger::Close(void)
 {
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
 
     shutdown(icmp_sock, SD_BOTH);
     close(icmp_sock);
@@ -171,9 +173,7 @@ IcmpPinger::Close(void)
 
     /* also shutdown the helper engines */
     icmp4.Close();
-#if USE_IPV6
     icmp6.Close();
-#endif
 }
 
 void
@@ -187,14 +187,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,26 +208,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 );
+        debugs(42, DBG_IMPORTANT, HERE << " IP has unknown Type. " << pecho.to );
     }
 }
 
@@ -237,7 +235,7 @@ 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);
     }