diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 9fb284c2..e5b35781 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -99,6 +99,9 @@ public : /// Note that this function know nothing about the standard /// fonts installed on the user's system, thus you can't /// load them directly. + /// Warning: SFML cannot preload all the font data in this + /// function, so the buffer pointed by \a data has to remain + /// valid as long as the font is used. /// /// \param data Pointer to the file data in memory /// \param sizeInBytes Size of the data to load, in bytes diff --git a/include/SFML/Network/TcpListener.hpp b/include/SFML/Network/TcpListener.hpp index 6fa803f7..4d2eb8f7 100644 --- a/include/SFML/Network/TcpListener.hpp +++ b/include/SFML/Network/TcpListener.hpp @@ -49,6 +49,19 @@ public : //////////////////////////////////////////////////////////// TcpListener(); + //////////////////////////////////////////////////////////// + /// \brief Get the port to which the socket is bound locally + /// + /// If the socket is not listening to a port, this function + /// returns 0. + /// + /// \return Port to which the socket is bound + /// + /// \see Listen + /// + //////////////////////////////////////////////////////////// + unsigned short GetLocalPort() const; + //////////////////////////////////////////////////////////// /// \brief Start listening for connections /// diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 1d59378b..e85af844 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -159,7 +159,7 @@ IpAddress IpAddress::GetLocalAddress() priv::SocketImpl::Close(sock); // Finally build the IP address - localAddress.myAddress = address.sin_addr.s_addr; + localAddress = IpAddress(ntohl(address.sin_addr.s_addr)); return localAddress; } diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index 615ecd0d..89fd19ca 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -41,6 +41,25 @@ Socket(Tcp) } +//////////////////////////////////////////////////////////// +unsigned short TcpListener::GetLocalPort() const +{ + if (GetHandle() != priv::SocketImpl::InvalidSocket()) + { + // Retrieve informations about the local end of the socket + sockaddr_in address; + priv::SocketImpl::AddrLength size = sizeof(address); + if (getsockname(GetHandle(), reinterpret_cast(&address), &size) != -1) + { + return ntohs(address.sin_port); + } + } + + // We failed to retrieve the port + return 0; +} + + //////////////////////////////////////////////////////////// Socket::Status TcpListener::Listen(unsigned short port) { diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 4c23e4fc..46879a44 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -30,8 +30,8 @@ #include #include #include -#include -#include +#include +#include #ifdef _MSC_VER #pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro