IpAddress.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef CPP3DS_IPADDRESS_HPP
26 #define CPP3DS_IPADDRESS_HPP
27 
29 // Headers
31 #include <cpp3ds/System/Time.hpp>
32 #include <istream>
33 #include <ostream>
34 #include <string>
35 
36 
37 namespace cpp3ds
38 {
43 class IpAddress
44 {
45 public:
46 
53  IpAddress();
54 
64  IpAddress(const std::string& address);
65 
78  IpAddress(const char* address);
79 
93  IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
94 
108  explicit IpAddress(Uint32 address);
109 
122  std::string toString() const;
123 
138  Uint32 toInteger() const;
139 
154  static IpAddress getLocalAddress();
155 
178  static IpAddress getPublicAddress(Time timeout = Time::Zero);
179 
181  // Static member data
183  static const IpAddress None;
184  static const IpAddress LocalHost;
185  static const IpAddress Broadcast;
186 
187 private:
188 
190  // Member data
192  Uint32 m_address;
193 };
194 
204 bool operator ==(const IpAddress& left, const IpAddress& right);
205 
215 bool operator !=(const IpAddress& left, const IpAddress& right);
216 
226 bool operator <(const IpAddress& left, const IpAddress& right);
227 
237 bool operator >(const IpAddress& left, const IpAddress& right);
238 
248 bool operator <=(const IpAddress& left, const IpAddress& right);
249 
259 bool operator >=(const IpAddress& left, const IpAddress& right);
260 
270 std::istream& operator >>(std::istream& stream, IpAddress& address);
271 
281 std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
282 
283 } // namespace cpp3ds
284 
285 
286 #endif // CPP3DS_IPADDRESS_HPP
287 
288 
Encapsulate an IPv4 network address.
Definition: IpAddress.hpp:43
Uint32 toInteger() const
Get an integer representation of the address.
static const IpAddress None
Value representing an empty/invalid address.
Definition: IpAddress.hpp:183
std::string toString() const
Get a string representation of the address.
Represents a time value.
Definition: Time.hpp:37
static const IpAddress Broadcast
The "broadcast" address (for sending UDP messages to everyone on a local network) ...
Definition: IpAddress.hpp:185
IpAddress()
Default constructor.
static const IpAddress LocalHost
The "localhost" address (for connecting a computer to itself locally)
Definition: IpAddress.hpp:184
static IpAddress getPublicAddress(Time timeout=Time::Zero)
Get the computer's public address.
static IpAddress getLocalAddress()
Get the computer's local address.
static const Time Zero
Predefined "zero" time value.
Definition: Time.hpp:82