Fixed IpAddress::GetLocalAddress() (was incorrectly returning 127.0.0.1)

This commit is contained in:
Laurent Gomila 2011-09-04 14:46:36 +02:00
parent 9205942917
commit d6a40cf062
2 changed files with 4 additions and 4 deletions

View File

@ -139,7 +139,7 @@ IpAddress IpAddress::GetLocalAddress()
return localAddress; return localAddress;
// Connect the socket to localhost on any port // 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<sockaddr*>(&address), sizeof(address)) == -1) if (connect(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
{ {
priv::SocketImpl::Close(sock); priv::SocketImpl::Close(sock);

View File

@ -28,7 +28,7 @@
#include <SFML/Network/Unix/SocketImpl.hpp> #include <SFML/Network/Unix/SocketImpl.hpp>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <cstring>
namespace sf namespace sf
@ -39,7 +39,7 @@ namespace priv
sockaddr_in SocketImpl::CreateAddress(unsigned long address, unsigned short port) sockaddr_in SocketImpl::CreateAddress(unsigned long address, unsigned short port)
{ {
sockaddr_in addr; 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_addr.s_addr = htonl(address);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);