Changeset 9321 in orxonox.OLD for branches/proxy/src/lib/network/ip.cc
- Timestamp:
- Jul 18, 2006, 11:30:12 AM (19 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.