| Line | |
|---|
| 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 "netdefs.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 | |
|---|
| 29 | /// OPERATORS |
|---|
| 30 | const IP& operator=(const IP& ip); |
|---|
| 31 | bool operator==(const IP& ip); |
|---|
| 32 | |
|---|
| 33 | /// RETRIVEAL |
|---|
| 34 | /** @returns the IP */ |
|---|
| 35 | int ip() const { return this->_ip; }; |
|---|
| 36 | /** @returns the Port */ |
|---|
| 37 | short port() const { return this->_port; }; |
|---|
| 38 | |
|---|
| 39 | int ipPart(unsigned int part) const; |
|---|
| 40 | std::string ipString() const; |
|---|
| 41 | |
|---|
| 42 | void debug() const; |
|---|
| 43 | |
|---|
| 44 | public: |
|---|
| 45 | /// SETUP |
|---|
| 46 | static IP stringToIP(const std::string& ip, int port = -1, bool resolve = true); |
|---|
| 47 | |
|---|
| 48 | static std::string ipToString(const IPaddress& ipaddr); |
|---|
| 49 | static std::string ipToString(int ip, int port = -1); |
|---|
| 50 | |
|---|
| 51 | static void setDefaultPort(short defaultPort); |
|---|
| 52 | static short defaultPort(short defaultPort) { return IP::_defaultPort; }; |
|---|
| 53 | |
|---|
| 54 | private: |
|---|
| 55 | int _ip; //!< The IP in int form. |
|---|
| 56 | short _port; //!< The Port number of the IP |
|---|
| 57 | |
|---|
| 58 | static short _defaultPort; //!< Default Port |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | #endif /* __IP_H__ */ |
|---|
Note: See
TracBrowser
for help on using the repository browser.