diff --git a/src/operators/rbl.cc b/src/operators/rbl.cc index 44a07bc8..894f9dc8 100644 --- a/src/operators/rbl.cc +++ b/src/operators/rbl.cc @@ -226,14 +226,14 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule, return false; } - // NOSONAR // SonarCloud suggested to use the init-statement to declare "addr" inside the if statement. // I think that's not good here, because we need that in the else block - struct sockaddr *addr = info->ai_addr; - // NOSONAR - if (addr->sa_family == AF_INET) { // only IPv4 address is allowed - auto sin = (struct sockaddr_in *) addr; // cppcheck-suppress[dangerousTypeCast] - furtherInfo(sin, ipStr, t, m_provider); + struct sockaddr *addr = info->ai_addr; // NOSONAR + if (addr->sa_family == AF_INET) { // NOSONAR + struct sockaddr_in sin{}; // initialize an empty struct; we don't need port info + memcpy(&sin.sin_addr, addr->sa_data + 2, sizeof(sin.sin_addr)); + sin.sin_family = AF_INET; + furtherInfo(&sin, ipStr, t, m_provider); } else { ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));