Module: check_mk
Branch: master
Commit: dfa113b102485fbdbcd82ecf78b44a4c7734d821
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dfa113b102485f…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Mon Feb 26 09:30:12 2018 +0100
Windows agent: remove redundant IPv6->IPv4 fallback
Since #5704 fix, the supported IP family (v6/v4) is checked before
initializing the socket. Falling back to IPv4 in case IPv6 is not
supported will never take place any more as we use the supported IP
family straight away.
Also fix the const correctness of two member variables and use logging
instead of stderr prints. Using stderr is not exactly so smart when
running as service ;-)
---
agents/windows/ListenSocket.cc | 24 ++++++++----------------
agents/windows/ListenSocket.h | 4 ++--
agents/windows/build_version | 2 +-
3 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/agents/windows/ListenSocket.cc b/agents/windows/ListenSocket.cc
index 51a3144..34b024b 100644
--- a/agents/windows/ListenSocket.cc
+++ b/agents/windows/ListenSocket.cc
@@ -113,19 +113,10 @@ SOCKET ListenSocket::init_listen_socket(int port) {
_winapi.socket(_use_ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
if (tmp_s == INVALID_SOCKET) {
int error_id = _winapi.WSAGetLastError();
- if (error_id == WSAEAFNOSUPPORT) {
- // this will happen on Win2k and WinXP without the ipv6 patch
- Notice(_logger) << "IPV6 not supported";
- _use_ipv6 = false;
- tmp_s = _winapi.socket(AF_INET, SOCK_STREAM, 0);
- }
- if (tmp_s == INVALID_SOCKET) {
- error_id = _winapi.WSAGetLastError();
- fprintf(stderr, "Cannot create socket: %s (%d)\n",
- get_win_error_as_string(_winapi, error_id).c_str(),
- error_id);
- exit(1);
- }
+ Error(_logger) << "Cannot create socket: "
+ << get_win_error_as_string(_winapi, error_id) <<
" ("
+ << error_id << ")";
+ exit(1);
}
SOCKET s = RemoveSocketInheritance(tmp_s);
@@ -151,13 +142,14 @@ SOCKET ListenSocket::init_listen_socket(int port) {
if (SOCKET_ERROR == _winapi.bind(s, addr.get(), addr_size)) {
int error_id = _winapi.WSAGetLastError();
- fprintf(stderr, "Cannot bind socket to port %d: %s (%d)\n", port,
- get_win_error_as_string(_winapi, error_id).c_str(), error_id);
+ Error(_logger) << "Cannot bind socket to port " << port
<< ": "
+ << get_win_error_as_string(_winapi, error_id) <<
" ("
+ << error_id << ")";
exit(1);
}
if (SOCKET_ERROR == _winapi.listen(s, 5)) {
- fprintf(stderr, "Cannot listen to socket\n");
+ Error(_logger) << "Cannot listen to socket";
exit(1);
}
diff --git a/agents/windows/ListenSocket.h b/agents/windows/ListenSocket.h
index 7991444..0f96ad8 100644
--- a/agents/windows/ListenSocket.h
+++ b/agents/windows/ListenSocket.h
@@ -55,9 +55,9 @@ private:
Logger *_logger;
const WinApiAdaptor &_winapi;
- bool _use_ipv6;
+ const bool _use_ipv6;
SOCKET _socket;
- only_from_t _source_whitelist;
+ const only_from_t _source_whitelist;
bool _supports_ipv4;
};
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 63e4f98..5c5bfcd 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3116
+3118