Fixed IpAddress::getLocalAddress on OS X and improved SocketImpl for Unix & Windows
This commit is contained in:
parent
5931236858
commit
713aed7079
@ -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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user