From 4324d44eafefc66e0a0b2efcd5eecdff9a95a588 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 4 Feb 2019 09:39:50 +0100 Subject: [PATCH] Avoid unaligned access, it hurts on e.g. sparc64 --- pdns/iputils.hh | 7 +++++++ pdns/nameserver.cc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 90ecdad28..490e45ac4 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 60e2e72ed..995420144 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<