Fix "cast from 'struct sockaddr*' to 'struct sockaddr_in*' increases required alignment" on OS X

This commit is contained in:
Jeffrey Walton 2017-12-26 17:57:26 -05:00
parent 0aa2ebbbf3
commit 09f9d76631
No known key found for this signature in database
GPG Key ID: B36AB348921B1838

View File

@ -255,8 +255,10 @@ bool Socket::Connect(const char *addr, unsigned int port)
} }
else else
{ {
// sa.sin_addr.s_addr = ((in_addr *)(void *)lphost->h_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; // 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); freeaddrinfo(result);
} }
} }