diff --git a/include/SFML/Network/IpAddress.hpp b/include/SFML/Network/IpAddress.hpp index 52179f79..d71d0633 100644 --- a/include/SFML/Network/IpAddress.hpp +++ b/include/SFML/Network/IpAddress.hpp @@ -107,29 +107,6 @@ public : //////////////////////////////////////////////////////////// IpAddress(Uint32 address); - //////////////////////////////////////////////////////////// - /// \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 - /// - //////////////////////////////////////////////////////////// - bool IsValid() const; - //////////////////////////////////////////////////////////// /// \brief Get a string representation of the address /// @@ -203,6 +180,7 @@ public : //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// + static const IpAddress None; ///< Value representing an empty/invalid address static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally) private : @@ -317,7 +295,8 @@ SFML_API std::ostream& operator <<(std::ostream& stream, const IpAddress& addres /// /// Usage example: /// \code -/// sf::IpAddress a1; // an invalid address +/// sf::IpAddress a0; // an invalid address +/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0) /// 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 diff --git a/samples/ftp/Ftp.cpp b/samples/ftp/Ftp.cpp index 238adae0..b7882aa5 100644 --- a/samples/ftp/Ftp.cpp +++ b/samples/ftp/Ftp.cpp @@ -32,7 +32,7 @@ int main() std::cout << "Enter the FTP server address : "; std::cin >> address; } - while (!address.IsValid()); + while (address == sf::IpAddress::None); // Connect to the server sf::Ftp server; diff --git a/samples/sockets/TCP.cpp b/samples/sockets/TCP.cpp index 1800d64c..124ffe06 100644 --- a/samples/sockets/TCP.cpp +++ b/samples/sockets/TCP.cpp @@ -19,7 +19,7 @@ void DoClientTCP(unsigned short port) std::cout << "Type address or name of the server to connect to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a TCP socket for communicating with server sf::SocketTCP client; diff --git a/samples/sockets/UDP.cpp b/samples/sockets/UDP.cpp index 7e610019..fa520cb0 100644 --- a/samples/sockets/UDP.cpp +++ b/samples/sockets/UDP.cpp @@ -19,7 +19,7 @@ void DoClientUDP(unsigned short port) std::cout << "Type address or name of the server to send the message to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a UDP socket for communicating with server sf::SocketUDP client; diff --git a/samples/voip/Client.cpp b/samples/voip/Client.cpp index 12b0d217..e397eece 100644 --- a/samples/voip/Client.cpp +++ b/samples/voip/Client.cpp @@ -76,7 +76,7 @@ void DoClient(unsigned short port) std::cout << "Type address or name of the server to connect to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a TCP socket for communicating with server sf::SocketTCP socket; diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 0fd96b40..846fc02a 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -34,6 +34,7 @@ namespace sf { //////////////////////////////////////////////////////////// +const IpAddress IpAddress::None; const IpAddress IpAddress::LocalHost(127, 0, 0, 1); @@ -52,7 +53,7 @@ IpAddress::IpAddress(const std::string& address) myAddress = inet_addr(address.c_str()); // If not successful, try to convert it as a host name - if (!IsValid()) + if (myAddress == INADDR_NONE) { hostent* host = gethostbyname(address.c_str()); if (host) @@ -76,7 +77,7 @@ IpAddress::IpAddress(const char* address) myAddress = inet_addr(address); // If not successful, try to convert it as a host name - if (!IsValid()) + if (myAddress == INADDR_NONE) { hostent* host = gethostbyname(address); if (host) @@ -107,13 +108,6 @@ IpAddress::IpAddress(Uint32 address) } -//////////////////////////////////////////////////////////// -bool IpAddress::IsValid() const -{ - return myAddress != INADDR_NONE; -} - - //////////////////////////////////////////////////////////// std::string IpAddress::ToString() const {