Changeset 9306 in orxonox.OLD for branches/proxy/src/lib/network
- Timestamp:
- Jul 17, 2006, 2:21:42 PM (19 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/Makefile.am
r9296 r9306 40 40 synchronizeable_var/synchronizeable_bool.cc \ 41 41 synchronizeable_var/synchronizeable_uint.cc \ 42 synchronizeable_var/synchronizeable_ip.cc 42 synchronizeable_var/synchronizeable_ip.cc \ 43 \ 44 ip.cc 43 45 44 46 … … 82 84 synchronizeable_var/synchronizeable_bool.h \ 83 85 synchronizeable_var/synchronizeable_uint.h \ 84 synchronizeable_var/synchronizeable_ip.h 86 synchronizeable_var/synchronizeable_ip.h \ 87 \ 88 ip.h 85 89 86 90 -
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 -
branches/proxy/src/lib/network/ip.h
r9305 r9306 2 2 /*! 3 3 * @file ip.h 4 * @brief Definition of Time Class.5 4 * 6 * These are mainly Classes, that are used for wrapping around SDL_thread 5 * @brief the ip class is used to transform strings to ip's and backwards 6 * it can also be used to 7 * 7 8 */ 8 9 … … 21 22 IP(); 22 23 IP(const std::string& ip); 23 IP(int ip); 24 IP(int ip, int port); 25 IP(const IPaddress& ip); 26 IP(const IP& ip); 27 28 const IP& operator=(const IP& ip); 29 bool operator==(const IP& ip); 24 30 25 31 … … 27 33 short port() const { return this->_port; }; 28 34 29 int ip (unsigned int part) const;30 std::string &ipString() const;35 int ipPart(unsigned int part) const; 36 std::string ipString() const; 31 37 32 38 33 39 34 40 public: 35 static int stringToIP(const std::string& ip); 41 static IP stringToIP(const std::string& ip); 42 43 36 44 static std::string ipToString(const IPaddress& ipaddr); 37 45 static std::string ipToString(int ip); 38 46 39 47 private: 40 int _ip; //!< the IP in int form.41 short _port; 48 int _ip; //!< The IP in int form. 49 short _port; //!< The Port number of the IP 42 50 43 51 };
Note: See TracChangeset
for help on using the changeset viewer.