From d6a40cf06202de4d05fb83e08844ebec6a6b8b43 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Sun, 4 Sep 2011 14:46:36 +0200 Subject: [PATCH] Fixed IpAddress::GetLocalAddress() (was incorrectly returning 127.0.0.1) --- src/SFML/Network/IpAddress.cpp | 4 ++-- src/SFML/Network/Unix/SocketImpl.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 73cf6a1e..ae3d90cb 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -139,13 +139,13 @@ IpAddress IpAddress::GetLocalAddress() return localAddress; // Connect the socket to localhost on any port - sockaddr_in address = priv::SocketImpl::CreateAddress(INADDR_LOOPBACK, 0); + sockaddr_in address = priv::SocketImpl::CreateAddress(ntohl(INADDR_LOOPBACK), 0); if (connect(sock, reinterpret_cast(&address), sizeof(address)) == -1) { priv::SocketImpl::Close(sock); return localAddress; } - + // Get the local address of the socket connection priv::SocketImpl::AddrLength size = sizeof(address); if (getsockname(sock, reinterpret_cast(&address), &size) == -1) diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp index bf6c86a3..1cf50324 100644 --- a/src/SFML/Network/Unix/SocketImpl.cpp +++ b/src/SFML/Network/Unix/SocketImpl.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace sf @@ -39,7 +39,7 @@ namespace priv sockaddr_in SocketImpl::CreateAddress(unsigned long address, unsigned short port) { sockaddr_in addr; - memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); + std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); addr.sin_addr.s_addr = htonl(address); addr.sin_family = AF_INET; addr.sin_port = htons(port);