mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fixed IpAddress::GetLocalAddress() (was incorrectly returning 127.0.0.1)
This commit is contained in:
parent
9205942917
commit
d6a40cf062
@ -139,13 +139,13 @@ 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);
|
||||||
return localAddress;
|
return localAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the local address of the socket connection
|
// Get the local address of the socket connection
|
||||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||||
if (getsockname(sock, reinterpret_cast<sockaddr*>(&address), &size) == -1)
|
if (getsockname(sock, reinterpret_cast<sockaddr*>(&address), &size) == -1)
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user