/*
- * 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-2018 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"
#include "IcmpPinger.h"
#include "SquidTime.h"
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
+#include <cerrno>
IcmpPinger::IcmpPinger() : Icmp()
{
int x;
struct sockaddr_in PS;
+ int xerrno;
WSAStartup(2, &wsaData);
atexit(Win32SockCleanup);
x = read(0, buf, sizeof(wpi));
if (x < (int)sizeof(wpi)) {
+ xerrno = errno;
getCurrentTime();
- debugs(42, DBG_CRITICAL, HERE << "read: FD 0: " << xstrerror());
+ debugs(42, DBG_CRITICAL, MYNAME << " read: FD 0: " << xstrerr(xerrno));
write(1, "ERR\n", 4);
return -1;
}
x = read(0, buf, sizeof(PS));
if (x < (int)sizeof(PS)) {
+ xerrno = errno;
getCurrentTime();
- debugs(42, DBG_CRITICAL, HERE << "read: FD 0: " << xstrerror());
+ debugs(42, DBG_CRITICAL, MYNAME << " read: FD 0: " << xstrerr(xerrno));
write(1, "ERR\n", 4);
return -1;
}
icmp_sock = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &wpi, 0, 0);
if (icmp_sock == -1) {
+ xerrno = errno;
getCurrentTime();
- debugs(42, DBG_CRITICAL, HERE << "WSASocket: " << xstrerror());
+ debugs(42, DBG_CRITICAL, MYNAME << "WSASocket: " << xstrerr(xerrno));
write(1, "ERR\n", 4);
return -1;
}
x = connect(icmp_sock, (struct sockaddr *) &PS, sizeof(PS));
if (SOCKET_ERROR == x) {
+ xerrno = errno;
getCurrentTime();
- debugs(42, DBG_CRITICAL, HERE << "connect: " << xstrerror());
+ debugs(42, DBG_CRITICAL, MYNAME << "connect: " << xstrerr(xerrno));
write(1, "ERR\n", 4);
return -1;
}
x = recv(icmp_sock, (void *) buf, sizeof(buf), 0);
if (x < 3) {
- debugs(42, DBG_CRITICAL, HERE << "recv: " << xstrerror());
+ xerrno = errno;
+ debugs(42, DBG_CRITICAL, MYNAME << "recv: " << xstrerr(xerrno));
return -1;
}
x = send(icmp_sock, (const void *) buf, strlen(buf), 0);
+ xerrno = errno;
if (x < 3 || strncmp("OK\n", buf, 3)) {
- debugs(42, DBG_CRITICAL, HERE << "recv: " << xstrerror());
+ debugs(42, DBG_CRITICAL, MYNAME << "recv: " << xstrerr(xerrno));
return -1;
}
if (n < 0) {
debugs(42, DBG_IMPORTANT, "Pinger exiting.");
Close();
- exit(1);
+ exit(EXIT_FAILURE);
}
if (0 == n) {
/* EOF indicator */
- debugs(42, DBG_CRITICAL, HERE << "EOF encountered. Pinger exiting.\n");
+ debugs(42, DBG_CRITICAL, "EOF encountered. Pinger exiting.");
errno = 0;
Close();
- exit(1);
+ exit(EXIT_FAILURE);
}
guess_size = n - (sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ);
debugs(42, 2, HERE << "return result to squid. len=" << len);
if (send(socket_to_squid, &preply, len, 0) < 0) {
- debugs(42, DBG_CRITICAL, "pinger: FATAL error on send: " << xstrerror());
+ int xerrno = errno;
+ debugs(42, DBG_CRITICAL, "pinger: FATAL error on send: " << xstrerr(xerrno));
Close();
- exit(1);
+ exit(EXIT_FAILURE);
}
}
#endif /* USE_ICMP */
+