From 4ffaace3849d9b084a8904aa6dbba50fa06bebd3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Mar 2015 22:25:53 +0000 Subject: Use std::memcpy to fix alignment As suggested by @madmaxoft --- src/OSSupport/NetworkInterfaceEnum.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/NetworkInterfaceEnum.cpp b/src/OSSupport/NetworkInterfaceEnum.cpp index 94edd3bfb..c4af1e93c 100644 --- a/src/OSSupport/NetworkInterfaceEnum.cpp +++ b/src/OSSupport/NetworkInterfaceEnum.cpp @@ -81,13 +81,19 @@ static AString PrintAddress(ifaddrs * InterfaceAddress) case AF_INET: { // IPv4 char AddressBuffer[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, &(reinterpret_cast(reinterpret_cast(InterfaceAddress->ifa_addr))->sin_addr), AddressBuffer, INET_ADDRSTRLEN); + sockaddr_in InternetSocket; + + std::memcpy(&InternetSocket, InterfaceAddress->ifa_addr, sizeof(InternetSocket)); + inet_ntop(AF_INET, &InternetSocket.sin_addr, AddressBuffer, INET_ADDRSTRLEN); return AddressBuffer; } case AF_INET6: { // IPv6 char AddressBuffer[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, &(reinterpret_cast(reinterpret_cast(InterfaceAddress->ifa_addr))->sin6_addr), AddressBuffer, INET6_ADDRSTRLEN); + sockaddr_in6 InternetSocket; + + std::memcpy(&InternetSocket, InterfaceAddress->ifa_addr, sizeof(InternetSocket)); + inet_ntop(AF_INET6, &InternetSocket.sin6_addr, AddressBuffer, INET6_ADDRSTRLEN); return AddressBuffer; } default: -- cgit v1.2.3