00001 #ifndef __IPADDRESS_H 00002 #define __IPADDRESS_H 00003 00004 #include <string> 00005 #include "os_spec.h" 00006 #include "GlobalConstants.h" 00007 #include "BasicObject.h" 00008 00009 using namespace std; 00010 00011 class IpAddress : public BasicObject { 00012 public: 00013 OS_SPEC_ENUM IpVersion { 00014 IPv4 = 4, 00015 IPv6 = 6 00016 }; 00017 00018 IpAddress(); 00019 IpAddress(unsigned long); 00020 IpAddress(const char*); 00021 IpAddress(std::string); 00022 IpAddress(struct in_addr); 00023 IpAddress(const IpAddress&); 00024 virtual ~IpAddress(); 00025 00026 unsigned long getUnsignedLongForm(); 00027 string getHostname(); 00028 IpVersion getVersion(); 00029 bool isLanIp(); 00030 bool isLoopback(); 00031 bool isZero(); 00032 bool isInAddrAny(); 00033 00034 void setIpAddress(unsigned long ipAddr); 00035 void setIpAddress(const char*); 00036 void setIpAddress(std::string); 00037 void setIpAddress(struct in_addr); 00038 void setIpAddress(const IpAddress&); 00039 00040 void setVersion(IpVersion); 00041 00042 bool equals(IpAddress); 00043 bool equals(unsigned long); 00044 bool equals(const char*); 00045 bool equals(std::string); 00046 bool equals(struct in_addr); 00047 00048 bool read(std::istream&); 00049 00050 virtual void toStream(std::ostream&); 00051 const char* toCStr(); 00052 00053 private: 00054 IpVersion m_version; 00055 unsigned long m_ipAddr; 00056 char m_cstr[MAX_IP_ADDR_STR]; 00057 string m_hostname; 00058 }; 00059 00060 #endif 00061