Changeset 9306 in orxonox.OLD for branches/proxy/src/lib/network/ip.cc
- Timestamp:
- Jul 17, 2006, 2:21:42 PM (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/ip.cc
r9305 r9306 8 8 #include "ip.h" 9 9 #include "multi_type.h" 10 #include "substring.h" 10 11 11 12 IP::IP() 12 {} 13 { 14 this->_ip = 0; 15 this->_port = 0; 16 } 13 17 14 18 15 IP::IP(int ip )19 IP::IP(int ip, int port) 16 20 { 17 21 this->_ip = ip; 18 } 19 20 IP::IP(const std::string& ip) 21 { 22 this->_ip = IP::stringToIP(ip); 22 this->_port = port; 23 23 } 24 24 25 25 26 26 27 IP::IP(const std::string& ip) 28 { 29 *this = IP::stringToIP(ip); 30 } 27 31 28 int IP::stringToIP(const std::string& ip) 32 33 IP::IP(const IPaddress& ip) 29 34 { 35 this->_ip = ip.host; 36 this->_port = ip.port; 37 } 38 39 40 IP::IP(const IP& ip) 41 { 42 this->_ip = ip.ip(); 43 this->_port = ip.port(); 44 } 45 46 47 48 const IP& IP::operator=(const IP& ip) 49 { 50 this->_ip = ip.ip(); 51 this->_port = ip.port(); 52 return *this; 53 } 54 55 56 57 bool IP::operator==(const IP& ip) 58 { 59 return (this->_ip == ip.ip() && this->_port == ip.port()); 60 } 61 62 63 /** 64 * @returns The retrieved IP 65 * 66 */ 67 IP IP::stringToIP(const std::string& ip) 68 { 69 IPaddress ipaddr; 70 71 SDLNet_ResolveHost(&ipaddr, NULL, 2000); 72 73 return IP(ipaddr); 74 75 /* 76 SubString addr(ip, '.'); 77 if(ip.size() != 4 ) 78 return -1; 79 80 MultiType part0(ip[0]); 81 MultiType part1(ip[1]); 82 MultiType part2(ip[2]); 83 MultiType part3(ip[3]); 84 */ 85 } 86 87 int IP::ipPart(unsigned int part) const 88 { 89 switch (part) 90 { 91 case 0: 92 return (_ip & 0xFF000000) >> 24; 93 case 1: 94 return (_ip & 0x00FF0000) >> 16; 95 case 2: 96 return (_ip & 0x0000FF00) >> 8; 97 case 3: 98 return (_ip & 0x000000FF); 99 default: 100 return -1; 101 } 30 102 31 103 } 104 105 106 std::string IP::ipString() const 107 { 108 return IP::ipToString(this->_ip); 109 } 110 32 111 33 112 std::string IP::ipToString(const IPaddress& ipaddr) … … 38 117 39 118 119 120 121 40 122 std::string IP::ipToString(int ip) 41 123 { 42 MultiType part0( (ip & 0xFF000000) >> 24);43 MultiType part1( (ip & 0x00FF0000) >> 16);44 MultiType part2( (ip & 0x0000FF00) >> 8);45 MultiType part3( (ip & 0x000000FF) );124 MultiType part0((int) (ip & 0xFF000000) >> 24); 125 MultiType part1((int) (ip & 0x00FF0000) >> 16); 126 MultiType part2((int) (ip & 0x0000FF00) >> 8); 127 MultiType part3((int) (ip & 0x000000FF) ); 46 128 47 129 48 130 return part0.getString() + "." + part1.getString() + "." + 49 131 part2.getString() + "." + part3.getString(); 50 132 } 51 133
Note: See TracChangeset
for help on using the changeset viewer.