libi2ncommon: (tomj) improve IP_RANGE exceptions
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 25 Nov 2004 15:19:56 +0000 (15:19 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 25 Nov 2004 15:19:56 +0000 (15:19 +0000)
src/ipfunc.cpp

index 185e938..8ecfebb 100644 (file)
@@ -28,7 +28,7 @@ void IP_RANGE::load(const std::string& ip)
         (delim_pos=ip.find('-')) != string::npos)
     {
         if (delim_pos+1 >= ip.size())
-            throw runtime_error("invalid IP given");
+            throw runtime_error("invalid IP given: "+ip);
         
         if (ip.at(delim_pos) == '/')
             t=NETWORK;
@@ -52,7 +52,7 @@ void IP_RANGE::load(type t, const std::string& ip, const std::string& mask_or_en
     if (t==IP)
     {
         if(!inet_aton(ip.c_str(),&ia_ip1))
-            throw runtime_error("invalid IP given");
+            throw runtime_error("invalid IP given: "+ip);
     
         this->ip=ia_ip1.s_addr;
         this->mask=0xFFFFFFFF;
@@ -62,7 +62,7 @@ void IP_RANGE::load(type t, const std::string& ip, const std::string& mask_or_en
     {
         // TODO: Better IP checks: "16" != "0.0.0.16"        
         if(!inet_aton(ip.c_str(),&ia_ip1))
-            throw runtime_error("invalid IP given");
+            throw runtime_error("invalid IP given: "+ip);
         
         // Check if mask is in cidr notation
         if (mask_or_end.find(".") == string::npos) {
@@ -71,12 +71,12 @@ void IP_RANGE::load(type t, const std::string& ip, const std::string& mask_or_en
             in >> calc_mask;
             
             if(calc_mask > 32)
-                throw runtime_error("invalid cidr mask given");
+                throw runtime_error("invalid cidr mask given: "+mask_or_end);
             
             ia_ip2.s_addr = calc_netmask_from_cidr(calc_mask);
         } else
             if (!inet_aton(mask_or_end.c_str(),&ia_ip2))
-                throw runtime_error("invalid IP given");
+                throw runtime_error("invalid IP given: "+mask_or_end);
                 
         this->ip=ia_ip1.s_addr;
         this->mask=ia_ip2.s_addr;
@@ -90,7 +90,7 @@ void IP_RANGE::load(type t, const std::string& ip, const std::string& mask_or_en
     else if (t==RANGE)
     {
         if(!inet_aton(ip.c_str(),&ia_ip1) || !inet_aton(mask_or_end.c_str(),&ia_ip2))
-            throw runtime_error("invalid IP given");
+            throw runtime_error("invalid IP given: "+ip);
     
         this->ip=ia_ip1.s_addr;
         this->end=ia_ip2.s_addr;
@@ -583,7 +583,7 @@ string IP_RANGE::resolve_ip(const string &iporname)
         throw dns_exception(hstrerror(h_errno));
 
     if (dnsdata->h_addr_list == NULL || *(dnsdata->h_addr_list) == NULL)
-        throw dns_exception("no corresponding ip found");
+        throw dns_exception("no corresponding ip found for: "+iporname);
 
     return inet_ntoa(*(struct in_addr*)(*dnsdata->h_addr_list));
 }