00001 #ifndef NET_ERROR 00002 #define NET_ERROR 00003 #include <abuse/abuse.h> 00004 #ifndef WIN32 00005 #include <abuse/SysError.h> 00006 #endif 00007 #include <sstream> 00008 #include <stdexcept> 00009 00010 class net_error:public std::runtime_error 00011 { 00012 public: 00013 net_error(const std::string& msg):std::runtime_error(""),err(0),w(msg) 00014 { 00015 } 00016 net_error(int n=0):std::runtime_error("noone"),err(n) 00017 { 00018 #ifdef WIN32 00019 if(!n) 00020 n=WSAGetLastError(); 00021 #endif 00022 if(n) 00023 { 00024 std::ostringstream oss; 00025 oss<<"Network error #"<<n; 00026 w=oss.str(); 00027 #ifndef WIN32 00028 w+=' '+SysError().what(); 00029 #endif 00030 } 00031 else 00032 w="Unspecified network error"; 00033 } 00034 virtual ~net_error()throw(){} 00035 virtual const char* what()const throw() 00036 { 00037 return w.c_str(); 00038 } 00039 const int err; 00040 protected: 00041 std::string w; 00042 00043 }; 00044 00045 class whois_error:public net_error 00046 { 00047 public: 00048 whois_error(const std::string& msg):net_error(msg){} 00049 whois_error():net_error("Unspecified whois error"){} 00050 whois_error(int n):net_error(n){} 00051 }; 00052 00053 class dns_error:public net_error 00054 { 00055 public: 00056 dns_error(const std::string& msg):net_error(msg){} 00057 dns_error() 00058 #ifdef WIN32 00059 :net_error(WSAGetLastError()){} 00060 #else 00061 { 00062 w=std::string("Name lookup error: ")+hstrerror(h_errno); 00063 } 00064 #endif 00065 00066 dns_error(int n):net_error(n) 00067 #ifdef WIN32 00068 {} 00069 #else 00070 { 00071 w=std::string("Name lookup error: ")+hstrerror(h_errno); 00072 } 00073 #endif 00074 00075 }; 00076 00077 class notlisted_exception: public dns_error 00078 { 00079 public: 00080 notlisted_exception(const std::string& lst):dns_error(std::string("Not listed in ")+lst) 00081 { 00082 } 00083 notlisted_exception():dns_error("Not listed") 00084 { 00085 } 00086 }; 00087 00088 00089 00090 #endif //NET_ERROR