From: Otto Moerbeek Date: Mon, 4 Feb 2019 08:39:50 +0000 (+0100) Subject: Avoid unaligned access, it hurts on e.g. sparc64 X-Git-Tag: auth-4.2.0-beta1~38^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4324d44eafefc66e0a0b2efcd5eecdff9a95a588;p=thirdparty%2Fpdns.git Avoid unaligned access, it hurts on e.g. sparc64 --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 90ecdad281..490e45ac43 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -91,6 +91,13 @@ union ComboAddress { struct sockaddr_in sin4; struct sockaddr_in6 sin6; + // struct sockaddr_in6 is *not* defined as containing two uint64_t for the + // address , but we like to read or write it like that. + // Force alignment by adding an uint64_t in the union. This makes sure + // the start of the struct and s6_addr gets aligned. + // This works because of the spot of s6_addr in struct sockaddr_in6. + // Needed for strict alignment architectures like sparc64. + uint64_t force_align; bool operator==(const ComboAddress& rhs) const { diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 60e2e72ed5..9954201441 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -242,7 +242,7 @@ void UDPNameserver::bindIPv6() if( !d_additional_socket ) g_localaddresses.push_back(locala); - if(::bind(s, (sockaddr*)&locala, sizeof(locala))<0) { + if(::bind(s, (sockaddr*)&locala, locala.getSocklen())<0) { close(s); if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) { g_log<