]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/Network/IPAddress.hpp
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / Network / IPAddress.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_IPADDRESS_HPP\r
26 #define SFML_IPADDRESS_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/Config.hpp>\r
32 #include <istream>\r
33 #include <ostream>\r
34 #include <string>\r
35 \r
36 \r
37 namespace sf\r
38 {\r
39 ////////////////////////////////////////////////////////////\r
40 /// IPAddress provides easy manipulation of IP v4 addresses\r
41 ////////////////////////////////////////////////////////////\r
42 class SFML_API IPAddress\r
43 {\r
44 public :\r
45 \r
46     ////////////////////////////////////////////////////////////\r
47     /// Default constructor -- constructs an invalid address\r
48     ///\r
49     ////////////////////////////////////////////////////////////\r
50     IPAddress();\r
51 \r
52     ////////////////////////////////////////////////////////////\r
53     /// Construct the address from a string\r
54     ///\r
55     /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name\r
56     ///\r
57     ////////////////////////////////////////////////////////////\r
58     IPAddress(const std::string& Address);\r
59 \r
60     ////////////////////////////////////////////////////////////\r
61     /// Construct the address from a C-style string ;\r
62     /// Needed for implicit conversions from literal strings to IPAddress to work\r
63     ///\r
64     /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name\r
65     ///\r
66     ////////////////////////////////////////////////////////////\r
67     IPAddress(const char* Address);\r
68 \r
69     ////////////////////////////////////////////////////////////\r
70     /// Construct the address from 4 bytes\r
71     ///\r
72     /// \param Byte0 : First byte of the address\r
73     /// \param Byte1 : Second byte of the address\r
74     /// \param Byte2 : Third byte of the address\r
75     /// \param Byte3 : Fourth byte of the address\r
76     ///\r
77     ////////////////////////////////////////////////////////////\r
78     IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3);\r
79 \r
80     ////////////////////////////////////////////////////////////\r
81     /// Construct the address from a 32-bits integer\r
82     ///\r
83     /// \param Address : 4 bytes of the address packed into a 32-bits integer\r
84     ///\r
85     ////////////////////////////////////////////////////////////\r
86     IPAddress(Uint32 Address);\r
87 \r
88     ////////////////////////////////////////////////////////////\r
89     /// Tell if the address is a valid one\r
90     ///\r
91     /// \return True if address has a valid syntax\r
92     ///\r
93     ////////////////////////////////////////////////////////////\r
94     bool IsValid() const;\r
95 \r
96     ////////////////////////////////////////////////////////////\r
97     /// Get a string representation of the address\r
98     ///\r
99     /// \return String representation of the IP address ("xxx.xxx.xxx.xxx")\r
100     ///\r
101     ////////////////////////////////////////////////////////////\r
102     std::string ToString() const;\r
103 \r
104     ////////////////////////////////////////////////////////////\r
105     /// Get an integer representation of the address\r
106     ///\r
107     /// \return 32-bits integer containing the 4 bytes of the address, in system endianness\r
108     ///\r
109     ////////////////////////////////////////////////////////////\r
110     Uint32 ToInteger() const;\r
111 \r
112     ////////////////////////////////////////////////////////////\r
113     /// Get the computer's local IP address (from the LAN point of view)\r
114     ///\r
115     /// \return Local IP address\r
116     ///\r
117     ////////////////////////////////////////////////////////////\r
118     static IPAddress GetLocalAddress();\r
119 \r
120     ////////////////////////////////////////////////////////////\r
121     /// Get the computer's public IP address (from the web point of view).\r
122     /// The only way to get a public address is to ask it to a\r
123     /// distant website ; as a consequence, this function may be\r
124     /// very slow -- use it as few as possible !\r
125     ///\r
126     /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout)\r
127     ///\r
128     /// \return Public IP address\r
129     ///\r
130     ////////////////////////////////////////////////////////////\r
131     static IPAddress GetPublicAddress(float Timeout = 0.f);\r
132 \r
133     ////////////////////////////////////////////////////////////\r
134     /// Comparison operator ==\r
135     ///\r
136     /// \param Other : Address to compare\r
137     ///\r
138     /// \return True if *this == Other\r
139     ///\r
140     ////////////////////////////////////////////////////////////\r
141     bool operator ==(const IPAddress& Other) const;\r
142 \r
143     ////////////////////////////////////////////////////////////\r
144     /// Comparison operator !=\r
145     ///\r
146     /// \param Other : Address to compare\r
147     ///\r
148     /// \return True if *this != Other\r
149     ///\r
150     ////////////////////////////////////////////////////////////\r
151     bool operator !=(const IPAddress& Other) const;\r
152 \r
153     ////////////////////////////////////////////////////////////\r
154     /// Comparison operator <\r
155     ///\r
156     /// \param Other : Address to compare\r
157     ///\r
158     /// \return True if *this < Other\r
159     ///\r
160     ////////////////////////////////////////////////////////////\r
161     bool operator <(const IPAddress& Other) const;\r
162 \r
163     ////////////////////////////////////////////////////////////\r
164     /// Comparison operator >\r
165     ///\r
166     /// \param Other : Address to compare\r
167     ///\r
168     /// \return True if *this > Other\r
169     ///\r
170     ////////////////////////////////////////////////////////////\r
171     bool operator >(const IPAddress& Other) const;\r
172 \r
173     ////////////////////////////////////////////////////////////\r
174     /// Comparison operator <=\r
175     ///\r
176     /// \param Other : Address to compare\r
177     ///\r
178     /// \return True if *this <= Other\r
179     ///\r
180     ////////////////////////////////////////////////////////////\r
181     bool operator <=(const IPAddress& Other) const;\r
182 \r
183     ////////////////////////////////////////////////////////////\r
184     /// Comparison operator >=\r
185     ///\r
186     /// \param Other : Address to compare\r
187     ///\r
188     /// \return True if *this >= Other\r
189     ///\r
190     ////////////////////////////////////////////////////////////\r
191     bool operator >=(const IPAddress& Other) const;\r
192 \r
193     ////////////////////////////////////////////////////////////\r
194     // Static member data\r
195     ////////////////////////////////////////////////////////////\r
196     static const IPAddress LocalHost; ///< Local host address (to connect to the same computer)\r
197 \r
198 private :\r
199 \r
200     ////////////////////////////////////////////////////////////\r
201     // Member data\r
202     ////////////////////////////////////////////////////////////\r
203     Uint32 myAddress; ///< Address stored as an unsigned 32 bits integer\r
204 };\r
205 \r
206 ////////////////////////////////////////////////////////////\r
207 /// Operator >> overload to extract an address from an input stream\r
208 ///\r
209 /// \param Stream :  Input stream\r
210 /// \param Address : Address to extract\r
211 ///\r
212 /// \return Reference to the input stream\r
213 ///\r
214 ////////////////////////////////////////////////////////////\r
215 SFML_API std::istream& operator >>(std::istream& Stream, IPAddress& Address);\r
216 \r
217 ////////////////////////////////////////////////////////////\r
218 /// Operator << overload to print an address to an output stream\r
219 ///\r
220 /// \param Stream :  Output stream\r
221 /// \param Address : Address to print\r
222 ///\r
223 /// \return Reference to the output stream\r
224 ///\r
225 ////////////////////////////////////////////////////////////\r
226 SFML_API std::ostream& operator <<(std::ostream& Stream, const IPAddress& Address);\r
227 \r
228 } // namespace sf\r
229 \r
230 \r
231 #endif // SFML_IPADDRESS_HPP\r