Changeset 9321 in orxonox.OLD for branches/proxy/src/lib/network
- Timestamp:
- Jul 18, 2006, 11:30:12 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/ip.cc
r9311 r9321 1 1 /** 2 2 * @file ip.cc 3 * @brief A IP class, that handles all about time.3 * @brief A IP class, that handles IP names and resolution. 4 4 * 5 5 * code taken from audiere. … … 7 7 8 8 #include "ip.h" 9 10 #include <iostream> 11 9 12 #include "multi_type.h" 10 13 #include "substring.h" … … 16 19 { 17 20 this->_ip = 0; 18 this->_port = 0;21 this->_port = IP::_defaultPort; 19 22 } 20 23 … … 29 32 { 30 33 this->_ip = ip; 31 this->_port = port; 32 } 33 34 if (port != -1) 35 this->_port = port; 36 else 37 this->_port = IP::_defaultPort; 38 } 39 40 41 /** 42 * @brief constructor from a String 43 * @param ip the IP as a String. 44 * @param resolve if true, the IP is resolved via DNS, 45 * @return self 46 */ 47 IP::IP(const std::string& ip, bool resolve) 48 { 49 *this = IP::stringToIP(ip, IP::_defaultPort, resolve); 50 } 34 51 35 52 /** … … 65 82 IP::IP(const IP& ip) 66 83 { 67 this->_ip = ip.ip(); 68 this->_port = ip.port(); 84 *this = ip; 69 85 } 70 86 … … 88 104 bool IP::operator==(const IP& ip) 89 105 { 90 return (this->_ip == ip.ip() && this->_port == ip.port()); 106 return (this->_ip == ip.ip() && 107 this->_port == ip.port()); 91 108 } 92 109 … … 160 177 std::string IP::ipString() const 161 178 { 162 return IP::ipToString(this->_ip );179 return IP::ipToString(this->_ip, this->_port); 163 180 } 164 181 … … 172 189 { 173 190 int ip = SDLNet_Read32 (ipaddr.host); 174 return ipToString(ip, ipaddr.port);191 return IP::ipToString(ip, ipaddr.port); 175 192 } 176 193 … … 193 210 194 211 if (port != -1) 195 addr += MultiType(port).getString();212 addr += ":" + MultiType(port).getString(); 196 213 return addr; 197 214 } 198 215 216 217 /// default port definition. 218 short IP::_defaultPort = 80; 219 220 /** 221 * @brief if no IP is supplied this port is used, so that IP can be resolved usefully. 222 * @param defaultPort The default port. 223 */ 224 void IP::setDefaultPort(short defaultPort) 225 { 226 IP::_defaultPort = defaultPort; 227 } 228 229 230 /** 231 * @brief print out the IP in a nice fashion 232 */ 233 void IP::debug() const 234 { 235 std::cout << "IP is " << this->ipString() << std::endl; 236 } -
branches/proxy/src/lib/network/ip.h
r9311 r9321 22 22 /// CONSTRUCTORS 23 23 IP(); 24 IP(int ip, int port); 25 IP(const std::string& ip, bool resolve = true); 24 26 IP(const std::string& ip, int port = -1, bool resolve = true); 25 IP(int ip, int port);26 27 IP(const IPaddress& ip); 27 28 IP(const IP& ip); … … 31 32 bool operator==(const IP& ip); 32 33 33 /// RETRI EAL34 /// RETRIVEAL 34 35 /** @returns the IP */ 35 36 int ip() const { return this->_ip; }; … … 40 41 std::string ipString() const; 41 42 43 void debug() const; 44 42 45 public: 43 44 46 /// SETUP 45 47 static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true); 46 47 48 48 49 static std::string ipToString(const IPaddress& ipaddr); 49 50 static std::string ipToString(int ip, int port = -1); 50 51 52 53 static void setDefaultPort(short defaultPort); 54 static short defaultPort(short defaultPort) { return IP::_defaultPort; }; 55 51 56 private: 52 int _ip; //!< The IP in int form.53 short _port; //!< The Port number of the IP57 int _ip; //!< The IP in int form. 58 short _port; //!< The Port number of the IP 54 59 60 61 static short _defaultPort; //!< Default Port 55 62 }; 56 63
Note: See TracChangeset
for help on using the changeset viewer.