Fixed IpAddress::getLocalAddress on OS X and improved SocketImpl for Unix & Windows

This commit is contained in:
Marco Antognini 2013-10-07 13:25:00 +02:00
parent 5931236858
commit 713aed7079
3 changed files with 7 additions and 3 deletions

View File

@ -148,7 +148,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(ntohl(INADDR_LOOPBACK), 0); sockaddr_in address = priv::SocketImpl::createAddress(ntohl(INADDR_LOOPBACK), 9);
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

@ -39,11 +39,15 @@ namespace priv
sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port)
{ {
sockaddr_in addr; 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_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);
#if defined(SFML_SYSTEM_MACOS)
addr.sin_len = sizeof(addr);
#endif
return addr; return addr;
} }

View File

@ -37,7 +37,7 @@ namespace priv
sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port) sockaddr_in SocketImpl::createAddress(Uint32 address, unsigned short port)
{ {
sockaddr_in addr; 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_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);