X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fipaddressacl.cpp;h=2f6295507ffa3b62b6c731fd7f01bb3a2f258dfd;hp=64ca979081ec090e08a2065d920d175f9fc27078;hb=026dc6b2bc548c945359c4e166eff514f2c47c6a;hpb=cd97061e86eeecf5b77dea35f0549e73a50eb200 diff --git a/src/ipaddressacl.cpp b/src/ipaddressacl.cpp index 64ca979..2f62955 100644 --- a/src/ipaddressacl.cpp +++ b/src/ipaddressacl.cpp @@ -12,7 +12,7 @@ IPAddressACL::IPAddressACL():m_allowbydefault(true) const bool IPAddressACL::Add(const std::string &aclentry) { bool allow=m_allowbydefault; - int maskbits=0; + int maskbits=32; std::string::size_type strpos=std::string::npos; std::string entrystr=aclentry; @@ -63,21 +63,11 @@ const bool IPAddressACL::Add(const std::string &aclentry) const std::string IPAddressACL::CreateMask(const int maskbits) { +/* int bitsleft=maskbits; - //int parts[4]={255,255,255,255}; int parts[4]={0,0,0,0}; std::ostringstream ipstr; - /* - for(int i=3; i>=0; i--) - { - for(int b=0; b<8 && bitsleft>0; b++) - { - parts[i]-=pow((float)2,b); - bitsleft--; - } - } - */ for(int i=0; i<4; i++) { for(int b=7; b>=0 && bitsleft>0; b--) @@ -86,6 +76,19 @@ const std::string IPAddressACL::CreateMask(const int maskbits) bitsleft--; } } +*/ + int bits=maskbits; + bits>32 ? bits=32 : false; + bits<0 ? bits=0 : false; + int parts[4]={0,0,0,0}; + std::ostringstream ipstr; + + unsigned long maskval=(((unsigned long)pow((float)2,bits)-1) << (32-bits)); + + parts[0]=((maskval >> 24) & 0xff); + parts[1]=((maskval >> 16) & 0xff); + parts[2]=((maskval >> 8) & 0xff); + parts[3]=(maskval & 0xff); ipstr << parts[0] << "." << parts[1] << "." << parts[2] << "." << parts[3]; @@ -105,8 +108,11 @@ const bool IPAddressACL::IsAllowed(const Poco::Net::IPAddress &addr) //ip1.mask((*i).m_mask); //ip2.mask((*i).m_mask); - ip1=MaskAddress(ip1,(*i).m_mask); - ip2=MaskAddress(ip2,(*i).m_mask); + if(ip1.family()==Poco::Net::IPAddress::IPv4 && ip2.family()==Poco::Net::IPAddress::IPv4) + { + ip1=MaskAddress(ip1,(*i).m_mask); + ip2=MaskAddress(ip2,(*i).m_mask); + } if(ip1==ip2) {