From 713aed707912bc6bf5b47632ed46efc707925eda Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Mon, 7 Oct 2013 13:25:00 +0200 Subject: [PATCH] Fixed IpAddress::getLocalAddress on OS X and improved SocketImpl for Unix & Windows --- src/SFML/Network/IpAddress.cpp | 2 +- src/SFML/Network/Unix/SocketImpl.cpp | 6 +++++- src/SFML/Network/Win32/SocketImpl.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index c4efabaf..11c96425 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -148,7 +148,7 @@ IpAddress IpAddress::getLocalAddress() return localAddress; // Connect the socket to localhost on any port - sockaddr_in address = priv::SocketImpl::createAddress(ntohl(INADDR_LOOPBACK), 0); + sockaddr_in address = priv::SocketImpl::createAddress(ntohl(INADDR_LOOPBACK), 9); if (connect(sock, reinterpret_cast(&address), sizeof(address)) == -1) { priv::SocketImpl::close(sock); diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp index 4a6b5087..4c695ba5 100644 --- a/src/SFML/Network/Unix/SocketImpl.cpp +++ b/src/SFML/Network/Unix/SocketImpl.cpp @@ -39,11 +39,15 @@ namespace priv sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) { sockaddr_in addr; - std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); + std::memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(address); addr.sin_family = AF_INET; addr.sin_port = htons(port); +#if defined(SFML_SYSTEM_MACOS) + addr.sin_len = sizeof(addr); +#endif + return addr; } diff --git a/src/SFML/Network/Win32/SocketImpl.cpp b/src/SFML/Network/Win32/SocketImpl.cpp index a3c26b75..92ab95f8 100644 --- a/src/SFML/Network/Win32/SocketImpl.cpp +++ b/src/SFML/Network/Win32/SocketImpl.cpp @@ -37,7 +37,7 @@ namespace priv sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) { sockaddr_in addr; - std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); + std::memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(address); addr.sin_family = AF_INET; addr.sin_port = htons(port);