From e924c9cf3924d2001ef9cd1a3560239c675d7132 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 12 Mar 2010 09:35:17 +0000 Subject: [PATCH] Improved the API documentation of sf::IpAddress git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1452 4e206d99-4929-0410-ac5d-dfc041789085 --- CSFML/build/VC2005/csfml-network.vcproj | 4 +- CSFML/build/VC2008/csfml-network.vcproj | 4 +- CSFML/build/codeblocks/csfml-network.cbp | 4 +- CSFML/include/SFML/Network.h | 2 +- CSFML/include/SFML/Network/Ftp.h | 4 +- CSFML/include/SFML/Network/IpAddress.h | 22 +- CSFML/include/SFML/Network/SocketTCP.h | 6 +- CSFML/include/SFML/Network/SocketUDP.h | 10 +- CSFML/src/SFML/Network/Ftp.cpp | 6 +- CSFML/src/SFML/Network/IpAddress.cpp | 42 ++-- CSFML/src/SFML/Network/SocketTCP.cpp | 10 +- CSFML/src/SFML/Network/SocketUDP.cpp | 18 +- CSFML/src/SFML/Network/csfml-network-d.def | 18 +- CSFML/src/SFML/Network/csfml-network.def | 18 +- build/codeblocks/sfml-network.cbp | 4 +- build/vc2005/sfml-network.vcproj | 4 +- build/vc2008/sfml-network.vcproj | 4 +- include/SFML/Network.hpp | 2 +- include/SFML/Network/Ftp.hpp | 4 +- include/SFML/Network/Http.hpp | 4 +- include/SFML/Network/IpAddress.hpp | 235 +++++++++++++++------ include/SFML/Network/SocketTCP.hpp | 6 +- include/SFML/Network/SocketUDP.hpp | 10 +- samples/ftp/Ftp.cpp | 2 +- samples/sockets/TCP.cpp | 4 +- samples/sockets/UDP.cpp | 40 ++-- samples/voip/Client.cpp | 2 +- samples/voip/Server.cpp | 2 +- src/SFML/Network/Ftp.cpp | 6 +- src/SFML/Network/Http.cpp | 2 +- src/SFML/Network/IpAddress.cpp | 73 +++---- src/SFML/Network/SocketTCP.cpp | 10 +- src/SFML/Network/SocketUDP.cpp | 16 +- src/SFML/System/String.cpp | 2 - 34 files changed, 336 insertions(+), 264 deletions(-) diff --git a/CSFML/build/VC2005/csfml-network.vcproj b/CSFML/build/VC2005/csfml-network.vcproj index fcb1ba30..9560a393 100644 --- a/CSFML/build/VC2005/csfml-network.vcproj +++ b/CSFML/build/VC2005/csfml-network.vcproj @@ -223,11 +223,11 @@ > - + @@ -67,7 +67,7 @@ - + diff --git a/CSFML/include/SFML/Network.h b/CSFML/include/SFML/Network.h index bbc87ffc..94fe3337 100644 --- a/CSFML/include/SFML/Network.h +++ b/CSFML/include/SFML/Network.h @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include -#include +#include #include #include #include diff --git a/CSFML/include/SFML/Network/Ftp.h b/CSFML/include/SFML/Network/Ftp.h index 12c60f18..70bd4c80 100644 --- a/CSFML/include/SFML/Network/Ftp.h +++ b/CSFML/include/SFML/Network/Ftp.h @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include @@ -287,7 +287,7 @@ CSFML_API void sfFtp_Destroy(sfFtp* ftp); /// \return Server response to the request /// //////////////////////////////////////////////////////////// -CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIPAddress server, unsigned short port, float timeout); +CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout); //////////////////////////////////////////////////////////// /// Log in using anonymous account diff --git a/CSFML/include/SFML/Network/IpAddress.h b/CSFML/include/SFML/Network/IpAddress.h index 6558c47d..e879b414 100644 --- a/CSFML/include/SFML/Network/IpAddress.h +++ b/CSFML/include/SFML/Network/IpAddress.h @@ -32,12 +32,12 @@ //////////////////////////////////////////////////////////// -/// sfIPAddress provides easy manipulation of IP v4 addresses +/// sfIpAddress provides easy manipulation of IP v4 addresses //////////////////////////////////////////////////////////// typedef struct { char Address[16]; -} sfIPAddress; +} sfIpAddress; //////////////////////////////////////////////////////////// @@ -48,7 +48,7 @@ typedef struct /// \return Resulting address /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_FromString(const char* string); +CSFML_API sfIpAddress sfIpAddress_FromString(const char* string); //////////////////////////////////////////////////////////// /// Construct an address from 4 bytes @@ -61,7 +61,7 @@ CSFML_API sfIPAddress sfIPAddress_FromString(const char* string); /// \return Resulting address /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3); +CSFML_API sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3); //////////////////////////////////////////////////////////// /// Construct the address from a 32-bits integer @@ -69,7 +69,7 @@ CSFML_API sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint /// \param address : 4 bytes of the address packed into a 32-bits integer /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_FromInteger(sfUint32 address); +CSFML_API sfIpAddress sfIpAddress_FromInteger(sfUint32 address); //////////////////////////////////////////////////////////// /// Tell if an address is a valid one @@ -79,7 +79,7 @@ CSFML_API sfIPAddress sfIPAddress_FromInteger(sfUint32 address); /// \return sfTrue if address has a valid syntax /// //////////////////////////////////////////////////////////// -CSFML_API sfBool sfIPAddress_IsValid(sfIPAddress address); +CSFML_API sfBool sfIpAddress_IsValid(sfIpAddress address); //////////////////////////////////////////////////////////// /// Get a string representation of an address @@ -88,7 +88,7 @@ CSFML_API sfBool sfIPAddress_IsValid(sfIPAddress address); /// \param string : Char array to fill (size must be >= 16) /// //////////////////////////////////////////////////////////// -CSFML_API void sfIPAddress_ToString(sfIPAddress address, char* string); +CSFML_API void sfIpAddress_ToString(sfIpAddress address, char* string); //////////////////////////////////////////////////////////// /// Get an integer representation of the address @@ -98,7 +98,7 @@ CSFML_API void sfIPAddress_ToString(sfIPAddress address, char* string); /// \return 32-bits integer containing the 4 bytes of the address, in system endianness /// //////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfIPAddress_ToInteger(sfIPAddress address); +CSFML_API sfUint32 sfIpAddress_ToInteger(sfIpAddress address); //////////////////////////////////////////////////////////// /// Get the computer's local IP address (from the LAN point of view) @@ -106,7 +106,7 @@ CSFML_API sfUint32 sfIPAddress_ToInteger(sfIPAddress address); /// \return Local IP address /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_GetLocalAddress(); +CSFML_API sfIpAddress sfIpAddress_GetLocalAddress(); //////////////////////////////////////////////////////////// /// Get the computer's public IP address (from the web point of view). @@ -119,7 +119,7 @@ CSFML_API sfIPAddress sfIPAddress_GetLocalAddress(); /// \return Public IP address /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_GetPublicAddress(float timeout); +CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(float timeout); //////////////////////////////////////////////////////////// /// Get the computer's loopback address @@ -127,7 +127,7 @@ CSFML_API sfIPAddress sfIPAddress_GetPublicAddress(float timeout); /// \return Local host IP address (127.0.0.1, or "localhost") /// //////////////////////////////////////////////////////////// -CSFML_API sfIPAddress sfIPAddress_LocalHost(); +CSFML_API sfIpAddress sfIpAddress_LocalHost(); #endif // SFML_IPADDRESS_H diff --git a/CSFML/include/SFML/Network/SocketTCP.h b/CSFML/include/SFML/Network/SocketTCP.h index 81d84664..90ca03f5 100644 --- a/CSFML/include/SFML/Network/SocketTCP.h +++ b/CSFML/include/SFML/Network/SocketTCP.h @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include @@ -81,7 +81,7 @@ CSFML_API void sfSocketTCP_SetBlocking(sfSocketTCP* socket, sfBool blocking); /// \return sfTrue if operation has been successful /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIPAddress host, float timeout); +CSFML_API sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIpAddress host, float timeout); //////////////////////////////////////////////////////////// /// Listen to a specified port for incoming data or connections @@ -106,7 +106,7 @@ CSFML_API sfBool sfSocketTCP_Listen(sfSocketTCP* socket, unsigned short port); /// \return Socket status /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIPAddress* address); +CSFML_API sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIpAddress* address); //////////////////////////////////////////////////////////// /// Send an array of bytes to the host (must be connected first) diff --git a/CSFML/include/SFML/Network/SocketUDP.h b/CSFML/include/SFML/Network/SocketUDP.h index ba2216f1..3c8a40d9 100644 --- a/CSFML/include/SFML/Network/SocketUDP.h +++ b/CSFML/include/SFML/Network/SocketUDP.h @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include @@ -103,7 +103,7 @@ CSFML_API sfBool sfSocketUDP_Unbind(sfSocketUDP* socket); /// \return Socket status /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIPAddress address, unsigned short port); +CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIpAddress address, unsigned short port); //////////////////////////////////////////////////////////// /// Receive an array of bytes. @@ -120,7 +120,7 @@ CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, /// \return Socket status /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIPAddress* address, unsigned short* port); +CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port); //////////////////////////////////////////////////////////// /// Send a packet of data @@ -133,7 +133,7 @@ CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, si /// \return Socket status /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress address, unsigned short port); +CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress address, unsigned short port); //////////////////////////////////////////////////////////// /// Receive a packet. @@ -148,7 +148,7 @@ CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* p /// \return Socket status /// //////////////////////////////////////////////////////////// -CSFML_API sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress* address, unsigned short* port); +CSFML_API sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port); //////////////////////////////////////////////////////////// /// Close the socket diff --git a/CSFML/src/SFML/Network/Ftp.cpp b/CSFML/src/SFML/Network/Ftp.cpp index 05988434..43efb128 100644 --- a/CSFML/src/SFML/Network/Ftp.cpp +++ b/CSFML/src/SFML/Network/Ftp.cpp @@ -27,7 +27,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include #include @@ -197,11 +197,11 @@ void sfFtp_Destroy(sfFtp* ftp) //////////////////////////////////////////////////////////// /// Connect to the specified FTP server //////////////////////////////////////////////////////////// -sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIPAddress server, unsigned short port, float timeout) +sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout) { CSFML_CHECK_RETURN(ftp, NULL); - sf::IPAddress SFMLServer(server.Address); + sf::IpAddress SFMLServer(server.Address); return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, timeout)); } diff --git a/CSFML/src/SFML/Network/IpAddress.cpp b/CSFML/src/SFML/Network/IpAddress.cpp index 4bb9987d..1c20e4ee 100644 --- a/CSFML/src/SFML/Network/IpAddress.cpp +++ b/CSFML/src/SFML/Network/IpAddress.cpp @@ -25,8 +25,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include -#include +#include +#include #include @@ -35,9 +35,9 @@ namespace //////////////////////////////////////////////////////////// /// Helper function for converting a SFML address to a CSFML one //////////////////////////////////////////////////////////// - sfIPAddress FromSFMLAddress(sf::IPAddress address) + sfIpAddress FromSFMLAddress(sf::IpAddress address) { - sfIPAddress result; + sfIpAddress result; strncpy(result.Address, address.ToString().c_str(), 16); return result; @@ -46,9 +46,9 @@ namespace //////////////////////////////////////////////////////////// /// Helper function for converting a CSFML address to a SFML one //////////////////////////////////////////////////////////// - sf::IPAddress ToSFMLAddress(sfIPAddress address) + sf::IpAddress ToSFMLAddress(sfIpAddress address) { - return sf::IPAddress(address.Address); + return sf::IpAddress(address.Address); } } @@ -56,34 +56,34 @@ namespace //////////////////////////////////////////////////////////// /// Construct an address from a string //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_FromString(const char* string) +sfIpAddress sfIpAddress_FromString(const char* string) { - return FromSFMLAddress(sf::IPAddress(string)); + return FromSFMLAddress(sf::IpAddress(string)); } //////////////////////////////////////////////////////////// /// Construct an address from 4 bytes //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3) +sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3) { - return FromSFMLAddress(sf::IPAddress(byte0, byte1, byte2, byte3)); + return FromSFMLAddress(sf::IpAddress(byte0, byte1, byte2, byte3)); } //////////////////////////////////////////////////////////// /// Construct the address from a 32-bits integer //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_FromInteger(sfUint32 address) +sfIpAddress sfIpAddress_FromInteger(sfUint32 address) { - return FromSFMLAddress(sf::IPAddress(address)); + return FromSFMLAddress(sf::IpAddress(address)); } //////////////////////////////////////////////////////////// /// Tell if an address is a valid one //////////////////////////////////////////////////////////// -sfBool sfIPAddress_IsValid(sfIPAddress address) +sfBool sfIpAddress_IsValid(sfIpAddress address) { return ToSFMLAddress(address).IsValid() ? sfTrue : sfFalse; } @@ -92,7 +92,7 @@ sfBool sfIPAddress_IsValid(sfIPAddress address) //////////////////////////////////////////////////////////// /// Get a string representation of an address //////////////////////////////////////////////////////////// -void sfIPAddress_ToString(sfIPAddress address, char* string) +void sfIpAddress_ToString(sfIpAddress address, char* string) { if (string) strcpy(string, address.Address); @@ -102,7 +102,7 @@ void sfIPAddress_ToString(sfIPAddress address, char* string) //////////////////////////////////////////////////////////// /// Get an integer representation of the address //////////////////////////////////////////////////////////// -sfUint32 sfIPAddress_ToInteger(sfIPAddress address) +sfUint32 sfIpAddress_ToInteger(sfIpAddress address) { return ToSFMLAddress(address).ToInteger(); } @@ -111,9 +111,9 @@ sfUint32 sfIPAddress_ToInteger(sfIPAddress address) //////////////////////////////////////////////////////////// /// Get the computer's local IP address (from the LAN point of view) //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_GetLocalAddress() +sfIpAddress sfIpAddress_GetLocalAddress() { - return FromSFMLAddress(sf::IPAddress::GetLocalAddress()); + return FromSFMLAddress(sf::IpAddress::GetLocalAddress()); } @@ -123,16 +123,16 @@ sfIPAddress sfIPAddress_GetLocalAddress() /// distant website ; as a consequence, this function may be /// very slow -- use it as few as possible ! //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_GetPublicAddress(float timeout) +sfIpAddress sfIpAddress_GetPublicAddress(float timeout) { - return FromSFMLAddress(sf::IPAddress::GetPublicAddress(timeout)); + return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout)); } //////////////////////////////////////////////////////////// /// Get the computer's loopback address //////////////////////////////////////////////////////////// -sfIPAddress sfIPAddress_LocalHost() +sfIpAddress sfIpAddress_LocalHost() { - return FromSFMLAddress(sf::IPAddress::LocalHost); + return FromSFMLAddress(sf::IpAddress::LocalHost); } diff --git a/CSFML/src/SFML/Network/SocketTCP.cpp b/CSFML/src/SFML/Network/SocketTCP.cpp index 73b5a38c..edd8d44b 100644 --- a/CSFML/src/SFML/Network/SocketTCP.cpp +++ b/CSFML/src/SFML/Network/SocketTCP.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -79,9 +79,9 @@ void sfSocketTCP_SetBlocking(sfSocketTCP* socket, sfBool blocking) //////////////////////////////////////////////////////////// /// Connect a TCP socket to another computer on a specified port //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIPAddress host, float timeout) +sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIpAddress host, float timeout) { - sf::IPAddress address(host.Address); + sf::IpAddress address(host.Address); CSFML_CHECK_RETURN(socket, sfSocketError); @@ -103,13 +103,13 @@ sfBool sfSocketTCP_Listen(sfSocketTCP* socket, unsigned short port) /// This function is blocking, ie. it won't return before /// a connection has been accepted //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIPAddress* address) +sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIpAddress* address) { CSFML_CHECK_RETURN(socket, sfSocketError); CSFML_CHECK_RETURN(connected, sfSocketError); // Call SFML internal function - sf::IPAddress clientAddress; + sf::IpAddress clientAddress; sf::SocketTCP client; sf::Socket::Status status = socket->This.Accept(client, &clientAddress); if (status != sf::Socket::Done) diff --git a/CSFML/src/SFML/Network/SocketUDP.cpp b/CSFML/src/SFML/Network/SocketUDP.cpp index efad583e..21665f3b 100644 --- a/CSFML/src/SFML/Network/SocketUDP.cpp +++ b/CSFML/src/SFML/Network/SocketUDP.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -97,12 +97,12 @@ sfBool sfSocketUDP_Unbind(sfSocketUDP* socket) //////////////////////////////////////////////////////////// /// Send an array of bytes //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIPAddress address, unsigned short port) +sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIpAddress address, unsigned short port) { CSFML_CHECK_RETURN(socket, sfSocketError) // Convert the address - sf::IPAddress receiver(address.Address); + sf::IpAddress receiver(address.Address); return static_cast(socket->This.Send(data, size, receiver, port)); } @@ -113,12 +113,12 @@ sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t si /// This function is blocking, ie. it won't return before some /// bytes have been received //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIPAddress* address, unsigned short* port) +sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port) { CSFML_CHECK_RETURN(socket, sfSocketError); // Call SFML internal function - sf::IPAddress sender; + sf::IpAddress sender; unsigned short senderPort; std::size_t received; @@ -142,13 +142,13 @@ sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSi //////////////////////////////////////////////////////////// /// Send a packet of data //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress address, unsigned short port) +sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress address, unsigned short port) { CSFML_CHECK_RETURN(socket, sfSocketError); CSFML_CHECK_RETURN(packet, sfSocketError); // Convert the address - sf::IPAddress receiver(address.Address); + sf::IpAddress receiver(address.Address); return static_cast(socket->This.Send(packet->This, receiver, port)); } @@ -159,12 +159,12 @@ sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfI /// This function is blocking, ie. it won't return before a /// packet is received //////////////////////////////////////////////////////////// -sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress* address, unsigned short* port) +sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port) { CSFML_CHECK_RETURN(socket, sfSocketError); CSFML_CHECK_RETURN(packet, sfSocketError); - sf::IPAddress sender; + sf::IpAddress sender; unsigned short senderPort; sf::Socket::Status status = socket->This.Receive(packet->This, sender, senderPort); if (status != sf::Socket::Done) diff --git a/CSFML/src/SFML/Network/csfml-network-d.def b/CSFML/src/SFML/Network/csfml-network-d.def index ae4309b5..c5c92905 100644 --- a/CSFML/src/SFML/Network/csfml-network-d.def +++ b/CSFML/src/SFML/Network/csfml-network-d.def @@ -49,15 +49,15 @@ EXPORTS sfHttp_Destroy sfHttp_SetHost sfHttp_SendRequest - sfIPAddress_FromString - sfIPAddress_FromBytes - sfIPAddress_FromInteger - sfIPAddress_IsValid - sfIPAddress_ToString - sfIPAddress_ToInteger - sfIPAddress_GetLocalAddress - sfIPAddress_GetPublicAddress - sfIPAddress_LocalHost + sfIpAddress_FromString + sfIpAddress_FromBytes + sfIpAddress_FromInteger + sfIpAddress_IsValid + sfIpAddress_ToString + sfIpAddress_ToInteger + sfIpAddress_GetLocalAddress + sfIpAddress_GetPublicAddress + sfIpAddress_LocalHost sfSocketTCP_Create sfSocketTCP_Destroy sfSocketTCP_SetBlocking diff --git a/CSFML/src/SFML/Network/csfml-network.def b/CSFML/src/SFML/Network/csfml-network.def index 8a5381b3..e33b2f63 100644 --- a/CSFML/src/SFML/Network/csfml-network.def +++ b/CSFML/src/SFML/Network/csfml-network.def @@ -49,15 +49,15 @@ EXPORTS sfHttp_Destroy sfHttp_SetHost sfHttp_SendRequest - sfIPAddress_FromString - sfIPAddress_FromBytes - sfIPAddress_FromInteger - sfIPAddress_IsValid - sfIPAddress_ToString - sfIPAddress_ToInteger - sfIPAddress_GetLocalAddress - sfIPAddress_GetPublicAddress - sfIPAddress_LocalHost + sfIpAddress_FromString + sfIpAddress_FromBytes + sfIpAddress_FromInteger + sfIpAddress_IsValid + sfIpAddress_ToString + sfIpAddress_ToInteger + sfIpAddress_GetLocalAddress + sfIpAddress_GetPublicAddress + sfIpAddress_LocalHost sfSocketTCP_Create sfSocketTCP_Copy sfSocketTCP_Destroy diff --git a/build/codeblocks/sfml-network.cbp b/build/codeblocks/sfml-network.cbp index 6ef81652..31d8a831 100644 --- a/build/codeblocks/sfml-network.cbp +++ b/build/codeblocks/sfml-network.cbp @@ -114,7 +114,7 @@ - + @@ -125,7 +125,7 @@ - + diff --git a/build/vc2005/sfml-network.vcproj b/build/vc2005/sfml-network.vcproj index 39954c79..55edf761 100644 --- a/build/vc2005/sfml-network.vcproj +++ b/build/vc2005/sfml-network.vcproj @@ -369,11 +369,11 @@ > #include #include -#include +#include #include #include #include diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index d78fc9d6..be059f3e 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -36,7 +36,7 @@ namespace sf { -class IPAddress; +class IpAddress; //////////////////////////////////////////////////////////// /// This class provides methods for manipulating the FTP @@ -267,7 +267,7 @@ public : /// \return Server response to the request /// //////////////////////////////////////////////////////////// - Response Connect(const IPAddress& server, unsigned short port = 21, float timeout = 0.f); + Response Connect(const IpAddress& server, unsigned short port = 21, float timeout = 0.f); //////////////////////////////////////////////////////////// /// Log in using anonymous account diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index d6d34d4c..7cdcf9fd 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include #include @@ -334,7 +334,7 @@ private : // Member data //////////////////////////////////////////////////////////// SocketTCP myConnection; ///< Connection to the host - IPAddress myHost; ///< Web host address + IpAddress myHost; ///< Web host address std::string myHostName; ///< Web host name unsigned short myPort; ///< Port used for connection with host }; diff --git a/include/SFML/Network/IpAddress.hpp b/include/SFML/Network/IpAddress.hpp index d29d4d89..52179f79 100644 --- a/include/SFML/Network/IpAddress.hpp +++ b/include/SFML/Network/IpAddress.hpp @@ -37,56 +37,93 @@ namespace sf { //////////////////////////////////////////////////////////// -/// IPAddress provides easy manipulation of IP v4 addresses +/// \brief Encapsulate an IPv4 network address +/// //////////////////////////////////////////////////////////// -class SFML_API IPAddress +class SFML_API IpAddress { public : //////////////////////////////////////////////////////////// - /// Default constructor -- constructs an invalid address + /// \brief Default constructor + /// + /// This constructor creates an empty (invalid) address /// //////////////////////////////////////////////////////////// - IPAddress(); + IpAddress(); //////////////////////////////////////////////////////////// - /// Construct the address from a string + /// \brief Construct the address from a string /// - /// \param address : IP address ("xxx.xxx.xxx.xxx") or network name + /// Here \a address can be either a decimal address + /// (ex: "192.168.1.56") or a network name (ex: "localhost"). + /// + /// \param address IP address or network name /// //////////////////////////////////////////////////////////// - IPAddress(const std::string& address); + IpAddress(const std::string& address); //////////////////////////////////////////////////////////// - /// Construct the address from a C-style string ; - /// Needed for implicit conversions from literal strings to IPAddress to work + /// \brief Construct the address from a string /// - /// \param address : IP address ("xxx.xxx.xxx.xxx") or network name + /// Here \a address can be either a decimal address + /// (ex: "192.168.1.56") or a network name (ex: "localhost"). + /// This is equivalent to the constructor taking a std::string + /// parameter, it is defined for convenience so that the + /// implicit conversions from literal strings to IpAddress work. + /// + /// \param address IP address or network name /// //////////////////////////////////////////////////////////// - IPAddress(const char* address); + IpAddress(const char* address); //////////////////////////////////////////////////////////// - /// Construct the address from 4 bytes + /// \brief Construct the address from 4 bytes /// - /// \param byte0 : First byte of the address - /// \param byte1 : Second byte of the address - /// \param byte2 : Third byte of the address - /// \param byte3 : Fourth byte of the address + /// Calling IpAddress(a, b, c, d) is equivalent to calling + /// IpAddress("a.b.c.d"), but safer as it doesn't have to + /// parse a string to get the address components. + /// + /// \param byte0 First byte of the address + /// \param byte1 Second byte of the address + /// \param byte2 Third byte of the address + /// \param byte3 Fourth byte of the address /// //////////////////////////////////////////////////////////// - IPAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3); + IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3); //////////////////////////////////////////////////////////// - /// Construct the address from a 32-bits integer + /// \brief Construct the address from a 32-bits integer /// - /// \param address : 4 bytes of the address packed into a 32-bits integer + /// This constructor uses the internal representation of + /// the address directly. It should be used for optimization + /// purposes, and only if you got that representation from + /// IpAddress::ToInteger(). + /// + /// \param address 4 bytes of the address packed into a 32-bits integer + /// + /// \see ToInteger /// //////////////////////////////////////////////////////////// - IPAddress(Uint32 address); + IpAddress(Uint32 address); //////////////////////////////////////////////////////////// - /// Tell if the address is a valid one + /// \brief Check if the address is a valid one + /// + /// If the address was constructed from a decimal representation + /// (like "192.168.1.56") this function will always return true + /// unless the address is the special one 255.255.255.255. + /// If the address was constructed from a host name, it is + /// reported as beeing valid only if the host exists and could + /// be converted to a decimal IP address. + /// + /// Examples: + /// \begincode + /// bool b1 = sf::IpAddress("127.0.0.1").IsValid(); // true + /// bool b2 = sf::IpAddress("1.2.3.4").IsValid(); // true + /// bool b3 = sf::IpAddress("www.google.com").IsValid(); // true + /// bool b4 = sf::IpAddress("www.dfgfghqsd.com").IsValid(); // false + /// \endcode /// /// \return True if address has a valid syntax /// @@ -94,46 +131,79 @@ public : bool IsValid() const; //////////////////////////////////////////////////////////// - /// Get a string representation of the address + /// \brief Get a string representation of the address /// - /// \return String representation of the IP address ("xxx.xxx.xxx.xxx") + /// The returned string is the decimal representation of the + /// IP address (like "192.168.1.56"), even if it was constructed + /// from a host name. + /// + /// \return String representation of the address + /// + /// \see ToInteger /// //////////////////////////////////////////////////////////// std::string ToString() const; //////////////////////////////////////////////////////////// - /// Get an integer representation of the address + /// \brief Get an integer representation of the address /// - /// \return 32-bits integer containing the 4 bytes of the address, in system endianness + /// The returned number is the internal representation of the + /// address, and should be used for optimization purposes only + /// (like sending the address through a socket). + /// The integer produced by this function can then be converted + /// back to a sf::IpAddress with the proper constructor. + /// + /// \return 32-bits unsigned integer representation of the address + /// + /// \see ToString /// //////////////////////////////////////////////////////////// Uint32 ToInteger() const; //////////////////////////////////////////////////////////// - /// Get the computer's local IP address (from the LAN point of view) + /// \brief Get the computer's local address /// - /// \return Local IP address + /// The local address is the address of the computer from the + /// LAN point of view, i.e. something like 192.168.1.56. It is + /// meaningful only for communications over the local network. + /// Unlike GetPublicAddress, this function is fast and may be + /// used safely anywhere. + /// + /// \return Local IP address of the computer + /// + /// \see GetPublicAddress /// //////////////////////////////////////////////////////////// - static IPAddress GetLocalAddress(); + static IpAddress GetLocalAddress(); //////////////////////////////////////////////////////////// - /// Get the computer's public IP address (from the web point of view). + /// \brief Get the computer's public address + /// + /// The public address is the address of the computer from the + /// internet point of view, i.e. something like 89.54.1.169. + /// It is necessary for communications over the world wide web. /// The only way to get a public address is to ask it to a - /// distant website ; as a consequence, this function may be - /// very slow -- use it as few as possible ! + /// distant website; as a consequence, this function depends on + /// both your network connection and the server, and may be + /// very slow. You should use it as few as possible. Because + /// this function depends on the network connection and on a distant + /// server, you may use a time limit if you don't want your program + /// to be possibly stuck waiting in case there is a problem; this + /// limit is deactivated by default. /// - /// \param timeout : Maximum time to wait, in seconds (0 by default : no timeout) + /// \param timeout Maximum time to wait, in seconds /// - /// \return Public IP address + /// \return Public IP address of the computer + /// + /// \see GetLocalAddress /// //////////////////////////////////////////////////////////// - static IPAddress GetPublicAddress(float timeout = 0.f); + static IpAddress GetPublicAddress(float timeout = 0.f); //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// - static const IPAddress LocalHost; ///< Local host address (to connect to the same computer) + static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally) private : @@ -144,94 +214,121 @@ private : }; //////////////////////////////////////////////////////////// -/// \brief Overload of == operator to compare two host addresses +/// \brief Overload of == operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// -/// \return True if both hosts are equal +/// \return True if both addresses are equal /// //////////////////////////////////////////////////////////// -SFML_API bool operator ==(const IPAddress& left, const IPAddress& right); +SFML_API bool operator ==(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// \brief Overload of != operator to compare two host addresses +/// \brief Overload of != operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// -/// \return True if both hosts are different +/// \return True if both addresses are different /// //////////////////////////////////////////////////////////// -SFML_API bool operator !=(const IPAddress& left, const IPAddress& right); +SFML_API bool operator !=(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// \brief Overload of < operator to compare two host addresses +/// \brief Overload of < operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// /// \return True if \a left is lesser than \a right /// //////////////////////////////////////////////////////////// -SFML_API bool operator <(const IPAddress& left, const IPAddress& right); +SFML_API bool operator <(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// \brief Overload of > operator to compare two host addresses +/// \brief Overload of > operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// /// \return True if \a left is greater than \a right /// //////////////////////////////////////////////////////////// -SFML_API bool operator >(const IPAddress& left, const IPAddress& right); +SFML_API bool operator >(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// \brief Overload of <= operator to compare two host addresses +/// \brief Overload of <= operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// /// \return True if \a left is lesser or equal than \a right /// //////////////////////////////////////////////////////////// -SFML_API bool operator <=(const IPAddress& left, const IPAddress& right); +SFML_API bool operator <=(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// \brief Overload of >= operator to compare two host addresses +/// \brief Overload of >= operator to compare two IP addresses /// -/// \param left Left operand (a host address) -/// \param right Right operand (a host address) +/// \param left Left operand (a IP address) +/// \param right Right operand (a IP address) /// /// \return True if \a left is greater or equal than \a right /// //////////////////////////////////////////////////////////// -SFML_API bool operator >=(const IPAddress& left, const IPAddress& right); +SFML_API bool operator >=(const IpAddress& left, const IpAddress& right); //////////////////////////////////////////////////////////// -/// Operator >> overload to extract an host address from an input stream +/// \brief Overload of >> operator to extract an IP address from an input stream /// -/// \param Stream : Input stream -/// \param Address : Host address to extract +/// \param stream Input stream +/// \param address IP address to extract /// /// \return Reference to the input stream /// //////////////////////////////////////////////////////////// -SFML_API std::istream& operator >>(std::istream& stream, IPAddress& address); +SFML_API std::istream& operator >>(std::istream& stream, IpAddress& address); //////////////////////////////////////////////////////////// -/// Operator << overload to print an host address to an output stream +/// \brief Overload of << operator to print an IP address to an output stream /// -/// \param Stream : Output stream -/// \param Address : Host address to print +/// \param stream Output stream +/// \param address IP address to print /// /// \return Reference to the output stream /// //////////////////////////////////////////////////////////// -SFML_API std::ostream& operator <<(std::ostream& stream, const IPAddress& address); +SFML_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address); } // namespace sf #endif // SFML_IPADDRESS_HPP + + +//////////////////////////////////////////////////////////// +/// \class sf::IpAddress +/// +/// sf::IpAddress is a utility class for manipulating network +/// addresses. It provides a set a implicit constructors and +/// conversion functions to easily build or transform an IP +/// address from/to various representations. +/// +/// Usage example: +/// \code +/// sf::IpAddress a1; // an invalid address +/// sf::IpAddress a2("127.0.0.1"); // the local host address +/// sf::IpAddress a3 = sf::IpAddress::LocalHost; // the local host address (same as a2) +/// sf::IpAddress a4(192, 168, 1, 56); // a local address +/// sf::IpAddress a5("my_computer"); // a local address created from a network name +/// sf::IpAddress a6("89.54.1.169"); // a distant address +/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name +/// sf::IpAddress a8 = sf::IpAddress::GetLocalAddress(); // my address on the local network +/// sf::IpAddress a9 = sf::IpAddress::GetPublicAddress(); // my address on the internet +/// \endcode +/// +/// Note that sf::IpAddress currently doesn't support IPv6 +/// nor other types of network addresses. +/// +//////////////////////////////////////////////////////////// diff --git a/include/SFML/Network/SocketTCP.hpp b/include/SFML/Network/SocketTCP.hpp index 4adacf48..d6eb6a8a 100644 --- a/include/SFML/Network/SocketTCP.hpp +++ b/include/SFML/Network/SocketTCP.hpp @@ -35,7 +35,7 @@ namespace sf { class Packet; -class IPAddress; +class IpAddress; template class Selector; //////////////////////////////////////////////////////////// @@ -71,7 +71,7 @@ public : /// \return True if operation has been successful /// //////////////////////////////////////////////////////////// - Socket::Status Connect(unsigned short port, const IPAddress& host, float timeout = 0.f); + Socket::Status Connect(unsigned short port, const IpAddress& host, float timeout = 0.f); //////////////////////////////////////////////////////////// /// Listen to a specified port for incoming data or connections @@ -93,7 +93,7 @@ public : /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Accept(SocketTCP& connected, IPAddress* address = NULL); + Socket::Status Accept(SocketTCP& connected, IpAddress* address = NULL); //////////////////////////////////////////////////////////// /// Send an array of bytes to the host (must be connected first) diff --git a/include/SFML/Network/SocketUDP.hpp b/include/SFML/Network/SocketUDP.hpp index a177c3bf..1b35b903 100644 --- a/include/SFML/Network/SocketUDP.hpp +++ b/include/SFML/Network/SocketUDP.hpp @@ -35,7 +35,7 @@ namespace sf { class Packet; -class IPAddress; +class IpAddress; template class Selector; //////////////////////////////////////////////////////////// @@ -90,7 +90,7 @@ public : /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Send(const char* data, std::size_t sizeInBytes, const IPAddress& address, unsigned short port); + Socket::Status Send(const char* data, std::size_t sizeInBytes, const IpAddress& address, unsigned short port); //////////////////////////////////////////////////////////// /// Receive an array of bytes. @@ -105,7 +105,7 @@ public : /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IPAddress& address, unsigned short& port); + Socket::Status Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IpAddress& address, unsigned short& port); //////////////////////////////////////////////////////////// /// Send a packet of data @@ -117,7 +117,7 @@ public : /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Send(Packet& packet, const IPAddress& address, unsigned short port); + Socket::Status Send(Packet& packet, const IpAddress& address, unsigned short port); //////////////////////////////////////////////////////////// /// Receive a packet. @@ -130,7 +130,7 @@ public : /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Receive(Packet& packet, IPAddress& address, unsigned short& port); + Socket::Status Receive(Packet& packet, IpAddress& address, unsigned short& port); //////////////////////////////////////////////////////////// /// Close the socket diff --git a/samples/ftp/Ftp.cpp b/samples/ftp/Ftp.cpp index b0c001ec..238adae0 100644 --- a/samples/ftp/Ftp.cpp +++ b/samples/ftp/Ftp.cpp @@ -26,7 +26,7 @@ std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& respons int main() { // Choose the server address - sf::IPAddress address; + sf::IpAddress address; do { std::cout << "Enter the FTP server address : "; diff --git a/samples/sockets/TCP.cpp b/samples/sockets/TCP.cpp index fa5c29e6..1800d64c 100644 --- a/samples/sockets/TCP.cpp +++ b/samples/sockets/TCP.cpp @@ -13,7 +13,7 @@ void DoClientTCP(unsigned short port) { // Ask for server address - sf::IPAddress serverAddress; + sf::IpAddress serverAddress; do { std::cout << "Type address or name of the server to connect to : "; @@ -66,7 +66,7 @@ void DoServerTCP(unsigned short port) std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl; // Wait for a connection - sf::IPAddress clientAddress; + sf::IpAddress clientAddress; sf::SocketTCP client; if (server.Accept(client, &clientAddress) != sf::Socket::Done) return; diff --git a/samples/sockets/UDP.cpp b/samples/sockets/UDP.cpp index b0bdb8dd..7e610019 100644 --- a/samples/sockets/UDP.cpp +++ b/samples/sockets/UDP.cpp @@ -10,28 +10,28 @@ /// Create a client and send a message to a running server /// //////////////////////////////////////////////////////////// -void DoClientUDP(unsigned short Port) +void DoClientUDP(unsigned short port) { // Ask for server address - sf::IPAddress ServerAddress; + sf::IpAddress serverAddress; do { std::cout << "Type address or name of the server to send the message to : "; - std::cin >> ServerAddress; + std::cin >> serverAddress; } - while (!ServerAddress.IsValid()); + while (!serverAddress.IsValid()); // Create a UDP socket for communicating with server - sf::SocketUDP Client; + sf::SocketUDP client; // Send a message to the server - char Message[] = "Hi, I'm a client !"; - if (Client.Send(Message, sizeof(Message), ServerAddress, Port) != sf::Socket::Done) + char message[] = "Hi, I'm a client !"; + if (client.Send(message, sizeof(message), serverAddress, port) != sf::Socket::Done) return; - std::cout << "Message sent to server : \"" << Message << "\"" << std::endl; + std::cout << "Message sent to server : \"" << message << "\"" << std::endl; // Close the socket when we're done - Client.Close(); + client.Close(); } @@ -39,27 +39,27 @@ void DoClientUDP(unsigned short Port) /// Launch a server and wait for incoming messages /// //////////////////////////////////////////////////////////// -void DoServerUDP(unsigned short Port) +void DoServerUDP(unsigned short port) { // Create a UDP socket for communicating with clients - sf::SocketUDP Server; + sf::SocketUDP server; // Bind it to the specified port - if (!Server.Bind(Port)) + if (!server.Bind(port)) return; // Receive a message from anyone - sf::IPAddress ClientAddress; - unsigned short ClientPort; - char Message[128]; - std::size_t Received; - if (Server.Receive(Message, sizeof(Message), Received, ClientAddress, ClientPort) != sf::Socket::Done) + sf::IpAddress clientAddress; + unsigned short clientPort; + char message[128]; + std::size_t received; + if (server.Receive(message, sizeof(message), received, clientAddress, clientPort) != sf::Socket::Done) return; // Display it - std::cout << "Message received from " << ClientAddress << " on port " << ClientPort - << ": \"" << Message << "\"" << std::endl; + std::cout << "Message received from " << clientAddress << " on port " << clientPort + << ": \"" << message << "\"" << std::endl; // Close the socket when we're done - Server.Close(); + server.Close(); } diff --git a/samples/voip/Client.cpp b/samples/voip/Client.cpp index 15e0ec96..12b0d217 100644 --- a/samples/voip/Client.cpp +++ b/samples/voip/Client.cpp @@ -70,7 +70,7 @@ void DoClient(unsigned short port) } // Ask for server address - sf::IPAddress serverAddress; + sf::IpAddress serverAddress; do { std::cout << "Type address or name of the server to connect to : "; diff --git a/samples/voip/Server.cpp b/samples/voip/Server.cpp index 29ed6d83..965e72ab 100644 --- a/samples/voip/Server.cpp +++ b/samples/voip/Server.cpp @@ -57,7 +57,7 @@ public : std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl; // Wait for a connection - sf::IPAddress clientAddress; + sf::IpAddress clientAddress; myListener.Accept(myClient, &clientAddress); std::cout << "Client connected : " << clientAddress << std::endl; diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 8ebfc213..f592fed7 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include #include @@ -192,7 +192,7 @@ Ftp::~Ftp() //////////////////////////////////////////////////////////// /// Connect to the specified FTP server //////////////////////////////////////////////////////////// -Ftp::Response Ftp::Connect(const IPAddress& server, unsigned short port, float timeout) +Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, float timeout) { // Connect to the server if (myCommandSocket.Connect(port, server, timeout) != Socket::Done) @@ -647,7 +647,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode) // Reconstruct connection port and address unsigned short port = data[4] * 256 + data[5]; - IPAddress address(static_cast(data[0]), + IpAddress address(static_cast(data[0]), static_cast(data[1]), static_cast(data[2]), static_cast(data[3])); diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index a9695246..65829b65 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -350,7 +350,7 @@ void Http::SetHost(const std::string& host, unsigned short port) if (!myHostName.empty() && (*myHostName.rbegin() == '/')) myHostName.erase(myHostName.size() - 1); - myHost = IPAddress(myHostName); + myHost = IpAddress(myHostName); } diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index accfbcc2..0fd96b40 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -25,7 +25,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include #include #include #include @@ -34,15 +34,11 @@ namespace sf { //////////////////////////////////////////////////////////// -/// Static member data -//////////////////////////////////////////////////////////// -const IPAddress IPAddress::LocalHost(127, 0, 0, 1); +const IpAddress IpAddress::LocalHost(127, 0, 0, 1); //////////////////////////////////////////////////////////// -/// Default constructor -//////////////////////////////////////////////////////////// -IPAddress::IPAddress() : +IpAddress::IpAddress() : myAddress(INADDR_NONE) { @@ -50,9 +46,7 @@ myAddress(INADDR_NONE) //////////////////////////////////////////////////////////// -/// Construct the address from a string -//////////////////////////////////////////////////////////// -IPAddress::IPAddress(const std::string& address) +IpAddress::IpAddress(const std::string& address) { // First try to convert it as a byte representation ("xxx.xxx.xxx.xxx") myAddress = inet_addr(address.c_str()); @@ -76,10 +70,7 @@ IPAddress::IPAddress(const std::string& address) //////////////////////////////////////////////////////////// -/// Construct the address from a C-style string ; -/// Needed for implicit conversions from literal strings to IPAddress to work -//////////////////////////////////////////////////////////// -IPAddress::IPAddress(const char* address) +IpAddress::IpAddress(const char* address) { // First try to convert it as a byte representation ("xxx.xxx.xxx.xxx") myAddress = inet_addr(address); @@ -103,36 +94,28 @@ IPAddress::IPAddress(const char* address) //////////////////////////////////////////////////////////// -/// Construct the address from 4 bytes -//////////////////////////////////////////////////////////// -IPAddress::IPAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) +IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) { myAddress = htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3); } //////////////////////////////////////////////////////////// -/// Construct the address from a 32-bits integer -//////////////////////////////////////////////////////////// -IPAddress::IPAddress(Uint32 address) +IpAddress::IpAddress(Uint32 address) { myAddress = htonl(address); } //////////////////////////////////////////////////////////// -/// Tell if the address is a valid one -//////////////////////////////////////////////////////////// -bool IPAddress::IsValid() const +bool IpAddress::IsValid() const { return myAddress != INADDR_NONE; } //////////////////////////////////////////////////////////// -/// Get a string representation of the address -//////////////////////////////////////////////////////////// -std::string IPAddress::ToString() const +std::string IpAddress::ToString() const { in_addr address; address.s_addr = myAddress; @@ -142,24 +125,20 @@ std::string IPAddress::ToString() const //////////////////////////////////////////////////////////// -/// Get an integer representation of the address -//////////////////////////////////////////////////////////// -Uint32 IPAddress::ToInteger() const +Uint32 IpAddress::ToInteger() const { return ntohl(myAddress); } //////////////////////////////////////////////////////////// -/// Get the computer's local IP address (from the LAN point of view) -//////////////////////////////////////////////////////////// -IPAddress IPAddress::GetLocalAddress() +IpAddress IpAddress::GetLocalAddress() { // The method here is to connect a UDP socket to anyone (here to localhost), // and get the local socket address with the getsockname function. // UDP connection will not send anything to the network, so this function won't cause any overhead. - IPAddress localAddress; + IpAddress localAddress; // Create the socket SocketHelper::SocketType sock = socket(PF_INET, SOCK_DGRAM, 0); @@ -199,82 +178,80 @@ IPAddress IPAddress::GetLocalAddress() //////////////////////////////////////////////////////////// -/// Get the computer's public IP address (from the web point of view) -//////////////////////////////////////////////////////////// -IPAddress IPAddress::GetPublicAddress(float timeout) +IpAddress IpAddress::GetPublicAddress(float timeout) { // The trick here is more complicated, because the only way // to get our public IP address is to get it from a distant computer. // Here we get the web page from http://www.sfml-dev.org/ip-provider.php // and parse the result to extract our IP address - // (not very hard : the web page contains only our IP address). + // (not very hard: the web page contains only our IP address). Http server("www.sfml-dev.org"); Http::Request request(Http::Request::Get, "/ip-provider.php"); Http::Response page = server.SendRequest(request, timeout); if (page.GetStatus() == Http::Response::Ok) - return IPAddress(page.GetBody()); + return IpAddress(page.GetBody()); // Something failed: return an invalid address - return IPAddress(); + return IpAddress(); } //////////////////////////////////////////////////////////// -bool operator ==(const IPAddress& left, const IPAddress& right) +bool operator ==(const IpAddress& left, const IpAddress& right) { return left.ToInteger() == right.ToInteger(); } //////////////////////////////////////////////////////////// -bool operator !=(const IPAddress& left, const IPAddress& right) +bool operator !=(const IpAddress& left, const IpAddress& right) { return !(left == right); } //////////////////////////////////////////////////////////// -bool operator <(const IPAddress& left, const IPAddress& right) +bool operator <(const IpAddress& left, const IpAddress& right) { return left.ToInteger() < right.ToInteger(); } //////////////////////////////////////////////////////////// -bool operator >(const IPAddress& left, const IPAddress& right) +bool operator >(const IpAddress& left, const IpAddress& right) { return right < left; } //////////////////////////////////////////////////////////// -bool operator <=(const IPAddress& left, const IPAddress& right) +bool operator <=(const IpAddress& left, const IpAddress& right) { return !(right < left); } //////////////////////////////////////////////////////////// -bool operator >=(const IPAddress& left, const IPAddress& right) +bool operator >=(const IpAddress& left, const IpAddress& right) { return !(left < right); } //////////////////////////////////////////////////////////// -std::istream& operator >>(std::istream& stream, IPAddress& address) +std::istream& operator >>(std::istream& stream, IpAddress& address) { std::string str; stream >> str; - address = IPAddress(str); + address = IpAddress(str); return stream; } //////////////////////////////////////////////////////////// -std::ostream& operator <<(std::ostream& stream, const IPAddress& address) +std::ostream& operator <<(std::ostream& stream, const IpAddress& address) { return stream << address.ToString(); } diff --git a/src/SFML/Network/SocketTCP.cpp b/src/SFML/Network/SocketTCP.cpp index 278dc995..980b2956 100644 --- a/src/SFML/Network/SocketTCP.cpp +++ b/src/SFML/Network/SocketTCP.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include #include @@ -67,7 +67,7 @@ void SocketTCP::SetBlocking(bool blocking) //////////////////////////////////////////////////////////// /// Connect to another computer on a specified port //////////////////////////////////////////////////////////// -Socket::Status SocketTCP::Connect(unsigned short port, const IPAddress& host, float timeout) +Socket::Status SocketTCP::Connect(unsigned short port, const IpAddress& host, float timeout) { // Make sure our socket is valid if (!IsValid()) @@ -203,7 +203,7 @@ bool SocketTCP::Listen(unsigned short port) /// Wait for a connection (must be listening to a port). /// This function will block if the socket is blocking //////////////////////////////////////////////////////////// -Socket::Status SocketTCP::Accept(SocketTCP& connected, IPAddress* address) +Socket::Status SocketTCP::Accept(SocketTCP& connected, IpAddress* address) { // Address that will be filled with client informations sockaddr_in clientAddress; @@ -216,14 +216,14 @@ Socket::Status SocketTCP::Accept(SocketTCP& connected, IPAddress* address) if (!connected.IsValid()) { if (address) - *address = IPAddress(); + *address = IpAddress(); return SocketHelper::GetErrorStatus(); } // Fill address if requested if (address) - *address = IPAddress(inet_ntoa(clientAddress.sin_addr)); + *address = IpAddress(inet_ntoa(clientAddress.sin_addr)); return Socket::Done; } diff --git a/src/SFML/Network/SocketUDP.cpp b/src/SFML/Network/SocketUDP.cpp index a31805b4..51127c80 100644 --- a/src/SFML/Network/SocketUDP.cpp +++ b/src/SFML/Network/SocketUDP.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ bool SocketUDP::Unbind() //////////////////////////////////////////////////////////// /// Send an array of bytes //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const IPAddress& address, unsigned short port) +Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const IpAddress& address, unsigned short port) { // Make sure the socket is valid if (!IsValid()) @@ -159,7 +159,7 @@ Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const /// Receive an array of bytes. /// This function will block if the socket is blocking //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IPAddress& address, unsigned short& port) +Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IpAddress& address, unsigned short& port) { // First clear the size received sizeReceived = 0; @@ -192,14 +192,14 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& // Check the number of bytes received if (received > 0) { - address = IPAddress(inet_ntoa(sockAddr.sin_addr)); + address = IpAddress(inet_ntoa(sockAddr.sin_addr)); port = ntohs(sockAddr.sin_port); sizeReceived = static_cast(received); return Socket::Done; } else { - address = IPAddress(); + address = IpAddress(); port = 0; return received == 0 ? Socket::Disconnected : SocketHelper::GetErrorStatus(); } @@ -216,7 +216,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& //////////////////////////////////////////////////////////// /// Send a packet of data //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Send(Packet& packet, const IPAddress& address, unsigned short port) +Socket::Status SocketUDP::Send(Packet& packet, const IpAddress& address, unsigned short port) { // Get the data to send from the packet std::size_t dataSize = 0; @@ -242,7 +242,7 @@ Socket::Status SocketUDP::Send(Packet& packet, const IPAddress& address, unsigne /// Receive a packet. /// This function will block if the socket is blocking //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned short& port) +Socket::Status SocketUDP::Receive(Packet& packet, IpAddress& address, unsigned short& port) { // We start by getting the size of the incoming packet Uint32 packetSize = 0; @@ -272,7 +272,7 @@ Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned s // Use another address instance for receiving the packet data ; // chunks of data coming from a different sender will be discarded (and lost...) - IPAddress sender; + IpAddress sender; unsigned short senderPort; // Then loop until we receive all the packet data diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index d1c91347..2db3252e 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -34,8 +34,6 @@ namespace sf { //////////////////////////////////////////////////////////// -// Static member data -//////////////////////////////////////////////////////////// const std::size_t String::InvalidPos = std::basic_string::npos;