00001 #ifndef ABUSEURL
00002 #define ABUSEURL
00003
00004 #pragma warning(disable:4786)
00005 #include <abuse/abuse.h>
00006 #include <list>
00007 #include <string>
00008 #include <abuse/net_error.h>
00009
00010
00011 class UrlRange;
00012
00013 class Url
00014 {
00015 public:
00016 Url(const in_addr& addr,bool lazy=true)throw(net_error);
00017 Url(const std::string& hostname,bool lazy=true)throw(net_error);
00018 virtual ~Url();
00019 operator const in_addr&()const;
00020 std::string ip()const;
00021 std::string hostname()const;
00022 const std::list<std::string>& hostnames()const;
00023 const std::list<in_addr>& ips()const;
00024 bool operator==(const Url& other)const;
00025 bool similar(const in_addr& addr)const;
00026 enum Type{INTERNET,INTRANET,RESERVED}type;
00027 static bool inNet(const in_addr& addr,const in_addr& netmask,unsigned char netwidth);
00028 static bool inNet(const in_addr& addr,const UrlRange& range);
00029 static std::string format(DWORD dwAddress)throw(std::runtime_error);
00030 static std::string format(const in_addr& addr)throw(std::runtime_error);
00031 static const char* NORDNS;
00032 private:
00033 std::list<in_addr> m_addresses;
00034 std::list<std::string> m_hostnames;
00035 void assignHost(const hostent* host);
00036 hostent* assignIP(unsigned long ip,bool lazy=true)throw(net_error);
00037 hostent* Url::retrieveHost(const in_addr* add)const throw(net_error);
00038 void setType(const in_addr& addr);
00039 mutable bool bLazy;
00040 };
00041
00042 bool operator==(const in_addr& addr1,const in_addr& addr2);
00043 __inline bool operator!=(const in_addr& addr1,const in_addr& addr2)
00044 {
00045 return !(addr1==addr2);
00046 }
00047 bool operator <(const in_addr& addr1,const in_addr& addr2);
00048 __inline bool operator<=(const in_addr& addr1,const in_addr& addr2)
00049 {
00050 return !(addr2<addr1);
00051 }
00052 __inline bool operator>=(const in_addr& addr1,const in_addr& addr2)
00053 {
00054 return !(addr1<addr2);
00055 }
00056
00057 __inline bool operator>(const in_addr& addr1,const in_addr& addr2)
00058 {
00059 return !(addr1<=addr2);
00060 }
00061 #endif //ABUSEURL