From 09f9d766314575f69335fbd8dfd636f53ac5fbee Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 26 Dec 2017 17:57:26 -0500 Subject: [PATCH] Fix "cast from 'struct sockaddr*' to 'struct sockaddr_in*' increases required alignment" on OS X --- socketft.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/socketft.cpp b/socketft.cpp index 20cda226..00c6b603 100644 --- a/socketft.cpp +++ b/socketft.cpp @@ -255,8 +255,10 @@ bool Socket::Connect(const char *addr, unsigned int port) } else { - // sa.sin_addr.s_addr = ((in_addr *)(void *)lphost->h_addr)->s_addr; - sa.sin_addr.s_addr = ((struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr; + // Avoid assignment on due to alignment issues in Apple headers + // sa.sin_addr.s_addr = ((struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr; + struct sockaddr_in* sap = (struct sockaddr_in *)result->ai_addr; + memcpy(&sa.sin_addr.s_addr, &sap->sin_addr.s_addr, sizeof(sa.sin_addr.s_addr)); freeaddrinfo(result); } }