| 1 |  | 
|---|
| 2 | /*! | 
|---|
| 3 | * @file ip.h | 
|---|
| 4 | * | 
|---|
| 5 | * @brief the ip class is used to transform strings to ip's and backwards | 
|---|
| 6 | * it can also be used to | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef __IP_H__ | 
|---|
| 10 | #define __IP_H__ | 
|---|
| 11 |  | 
|---|
| 12 | #include "netincl.h" | 
|---|
| 13 | #include <string> | 
|---|
| 14 |  | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | //! A class to handle time itself | 
|---|
| 18 | class IP | 
|---|
| 19 | { | 
|---|
| 20 | public: | 
|---|
| 21 | /// CONSTRUCTORS | 
|---|
| 22 | IP(); | 
|---|
| 23 | IP(int ip, int port); | 
|---|
| 24 | IP(const std::string& ip, bool resolve = true); | 
|---|
| 25 | IP(const std::string& ip, int port = -1, bool resolve = true); | 
|---|
| 26 | IP(const IPaddress& ip); | 
|---|
| 27 | IP(const IP& ip); | 
|---|
| 28 | IP(unsigned int first, unsigned int second, unsigned int third, unsigned int fourth, int port = IP::_defaultPort); | 
|---|
| 29 |  | 
|---|
| 30 | /// OPERATORS | 
|---|
| 31 | const IP& operator=(const IP& ip); | 
|---|
| 32 | const IP& operator=(const IPaddress& ip); | 
|---|
| 33 | bool operator==(const IP& ip) const; | 
|---|
| 34 | bool operator!=(const IP& up) const; | 
|---|
| 35 |  | 
|---|
| 36 | /// RETRIVEAL | 
|---|
| 37 | /** @returns the IP */ | 
|---|
| 38 | int host() const { return this->_host; }; | 
|---|
| 39 | int* hostRef()  { return &this->_host; } | 
|---|
| 40 | /** @returns the Port */ | 
|---|
| 41 | int port() const { return this->_port; }; | 
|---|
| 42 | int* portRef() { return &this->_port; }; | 
|---|
| 43 |  | 
|---|
| 44 | inline IPaddress getSDLNotation() { IPaddress sdlIP; sdlIP.host = this->_host; sdlIP.port = this->_port; return sdlIP; } | 
|---|
| 45 |  | 
|---|
| 46 | int ipPart(unsigned int part) const; | 
|---|
| 47 | std::string ipString() const; | 
|---|
| 48 |  | 
|---|
| 49 | void debug() const; | 
|---|
| 50 |  | 
|---|
| 51 | public: | 
|---|
| 52 | /// SETUP | 
|---|
| 53 | static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true); | 
|---|
| 54 |  | 
|---|
| 55 | static std::string ipToString(const IPaddress& ipaddr); | 
|---|
| 56 | static std::string ipToString(int host, int port = -1); | 
|---|
| 57 |  | 
|---|
| 58 | static void setDefaultPort(int defaultPort); | 
|---|
| 59 | static int defaultPort(int defaultPort) { return IP::_defaultPort; }; | 
|---|
| 60 |  | 
|---|
| 61 | private: | 
|---|
| 62 | int           _host;           //!< The IP in int form. | 
|---|
| 63 | int           _port;         //!< The Port number of the IP | 
|---|
| 64 |  | 
|---|
| 65 | static int    _defaultPort;  //!< Default Port | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 | #endif /* __IP_H__ */ | 
|---|