string val = asString(value);
if (val == "0") return false;
if (val == "1") return true;
- } catch (JsonException) {};
+ } catch (const JsonException&) {};
throw JsonException("Json value not convertible to boolean");
};
struct addrinfo* address = res;
do {
if (address->ai_addrlen <= sizeof(remote)) {
- memcpy(&remote, address->ai_addr, address->ai_addrlen);
+ remote.setSockaddr(address->ai_addr, address->ai_addrlen);
addresses->push_back(remote.toString());
}
} while((address = address->ai_next));
shared_ptr<DNSCryptoKeyEngine> dpk(DNSCryptoKeyEngine::make(algorithm));
try{
dpk->create(bits);
- } catch (std::runtime_error error){
+ } catch (const std::runtime_error& error){
throw runtime_error("The algorithm does not support the given bit size.");
}
dspk.setKey(dpk);
vector<uint8_t> rewrittenResponse;
shared_ptr<DownstreamState> ds;
ComboAddress dest;
- memset(&dest, 0, sizeof(dest));
+ dest.reset();
dest.sin4.sin_family = ci.remote.sin4.sin_family;
socklen_t len = dest.getSocklen();
size_t queriesCount = 0;
ComboAddress AAAARecordContent::getCA(int port) const
{
ComboAddress ret;
- memset(&ret, 0, sizeof(ret));
+ ret.reset();
ret.sin4.sin_family=AF_INET6;
ret.sin6.sin6_port = htons(port);
return false;
if(octetsin > sizeof(address.sin4.sin_addr.s_addr))
return false;
- memset(&address, 0, sizeof(address));
+ address.reset();
address.sin4.sin_family = AF_INET;
if(octetsin > 0)
memcpy(&address.sin4.sin_addr.s_addr, options+sizeof(esow), octetsin);
return false;
if(octetsin > sizeof(address.sin6.sin6_addr.s6_addr))
return false;
- memset(&address, 0, sizeof(address));
+
+ address.reset();
address.sin4.sin_family = AF_INET6;
if(octetsin > 0)
memcpy(&address.sin6.sin6_addr.s6_addr, options+sizeof(esow), octetsin);
}
bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination)
{
- memset(destination, 0, sizeof(*destination));
+ destination->reset();
const struct cmsghdr* cmsg;
for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(const_cast<struct msghdr*>(msgh), const_cast<struct cmsghdr*>(cmsg))) {
#if defined(IP_PKTINFO)
return ntohs(sin4.sin_port);
}
+ void reset()
+ {
+ memset(&sin4, 0, sizeof(sin4));
+ memset(&sin6, 0, sizeof(sin6));
+ }
};
/** This exception is thrown by the Netmask class and by extension by the NetmaskGroup class */
port = pdns_stou(addr.substr(pos+2));
portSet = true;
}
- catch(std::out_of_range) {
+ catch(const std::out_of_range&) {
return -1;
}
}
if(!setNonBlocking(s))
throw PDNSException("Unable to set UDP socket to non-blocking: "+stringerror());
-
- memset(&locala,0,sizeof(locala));
+
+ locala.reset();
locala.sin4.sin_family=AF_INET;
if(localname=="0.0.0.0")
dc->d_tcp=true;
dc->setRemote(&conn->d_remote);
ComboAddress dest;
- memset(&dest, 0, sizeof(dest));
+ dest.reset();
dest.sin4.sin_family = conn->d_remote.sin4.sin_family;
socklen_t len = dest.getSocklen();
getsockname(conn->getFD(), (sockaddr*)&dest, &len); // if this fails, we're ok with it
struct timeval tv={0,0};
HarvestTimestamp(&msgh, &tv);
ComboAddress dest;
- memset(&dest, 0, sizeof(dest)); // this makes sure we ignore this address if not returned by recvmsg above
+ dest.reset(); // this makes sure we ignore this address if not returned by recvmsg above
auto loc = rplookup(g_listenSocketsAddresses, fd);
if(HarvestDestinationAddress(&msgh, &dest)) {
// but.. need to get port too
ComboAddress sin;
- memset((char *)&sin,0, sizeof(sin));
+ sin.reset();
sin.sin4.sin_family = AF_INET;
if(!IpToU32(st.host, (uint32_t*)&sin.sin4.sin_addr.s_addr)) {
sin.sin6.sin6_family = AF_INET6;
ComboAddress sin;
- memset(&sin, 0, sizeof(sin));
+ sin.reset();
sin.sin4.sin_family = AF_INET;
if(!IpToU32(st.host.c_str() , (uint32_t*)&sin.sin4.sin_addr.s_addr)) {
sin.sin6.sin6_family = AF_INET6;
{
PacketID() : id(0), type(0), sock(0), inNeeded(0), inIncompleteOkay(false), outPos(0), nearMisses(0), fd(-1)
{
- memset(&remote, 0, sizeof(remote));
+ remote.reset();
}
uint16_t id; // wait for a specific id/remote pair
BOOST_AUTO_TEST_CASE(test_ComboAddressCompare) {
ComboAddress a, b;
- memset(&a, 0, sizeof(a));
- memset(&b, 0, sizeof(b));
+ a.reset();
+ b.reset();
BOOST_CHECK(!(a<b));
BOOST_CHECK(!(a>b));
}