Changeset 9310 in orxonox.OLD for branches/proxy/src
- Timestamp:
- Jul 18, 2006, 1:30:58 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/ip.cc
r9307 r9310 37 37 * @brief constructor from a String 38 38 * @param ip the IP as a String. 39 * @return self 40 */ 41 IP::IP(const std::string& ip) 42 { 43 *this = IP::stringToIP(ip); 39 * @param port The port to be resolved. 40 * @param resolve if true, the IP is resolved via DNS, 41 * @return self 42 */ 43 IP::IP(const std::string& ip, int port, bool resolve) 44 { 45 *this = IP::stringToIP(ip, port, resolve); 44 46 } 45 47 … … 98 100 * @brief converts a String into an IP Object. 99 101 * @param ip The string holding an IP. 100 * @return a constructed IP. 101 */ 102 IP IP::stringToIP(const std::string& ip) 103 { 104 IPaddress ipaddr; 105 106 SDLNet_ResolveHost(&ipaddr, NULL, 2000); 107 108 return IP(ipaddr); 109 110 /* 111 SubString addr(ip, '.'); 112 if(ip.size() != 4 ) 113 return -1; 114 115 MultiType part0(ip[0]); 116 MultiType part1(ip[1]); 117 MultiType part2(ip[2]); 118 MultiType part3(ip[3]); 119 */ 102 * @param port The port to be resolved. 103 * @param resolve if true, the IP is resolved via DNS, 104 * otherwise (resolve == false) the IP is being transformed 105 * from a String (xxx.xxx.xxx.xxx) to an integer. 106 * 107 * @return A newly constructed IP. 108 */ 109 IP IP::stringToIP(const std::string& ip, int port, bool resolve) 110 { 111 if (resolve) 112 { 113 IPaddress ipaddr; 114 115 SDLNet_ResolveHost(&ipaddr, NULL, 2000); 116 117 return IP(ipaddr.host, port); 118 } 119 else 120 { 121 SubString ipaddr(ip, '.'); 122 if(ip.size() != 4 ) 123 return IP(); 124 125 MultiType part0(ipaddr[0]); 126 MultiType part1(ipaddr[1]); 127 MultiType part2(ipaddr[2]); 128 MultiType part3(ipaddr[3]); 129 130 int addr = (part0.getInt() << 24) + 131 (part1.getInt() << 16) + 132 (part2.getInt() << 8) + 133 part3.getInt(); 134 return IP(addr, port); 135 } 120 136 } 121 137 … … 170 186 171 187 /** 172 * converts a IP into a String (without port).188 * @brief converts a IP into a String (without port). 173 189 * @param ip the IP to put into the string. 174 190 * @param port -1 if not wanted -
branches/proxy/src/lib/network/ip.h
r9307 r9310 21 21 public: 22 22 IP(); 23 IP(const std::string& ip );23 IP(const std::string& ip, int port = -1, bool resolve = true); 24 24 IP(int ip, int port); 25 25 IP(const IPaddress& ip); … … 30 30 31 31 32 /** @returns the IP */ 32 33 int ip() const { return this->_ip; }; 34 /** @returns the Port */ 33 35 short port() const { return this->_port; }; 34 36 … … 36 38 std::string ipString() const; 37 39 38 39 40 40 public: 41 static IP stringToIP(const std::string& ip );41 static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true); 42 42 43 43
Note: See TracChangeset
for help on using the changeset viewer.