X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9701b7ab4dc4cd709ad4dcaa750fc0021f15e231..b95edc0574dc2ebc65b197b1b1ad464821dfe519:/include/stg/user_ips.h diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h index 250520b2..a29e2812 100644 --- a/include/stg/user_ips.h +++ b/include/stg/user_ips.h @@ -41,7 +41,7 @@ #include #include -#include "common.h" +#include "stg/common.h" #include "os_int.h" using namespace std; @@ -134,6 +134,14 @@ return ips.size(); } //----------------------------------------------------------------------------- inline +uint32_t USER_IPS::CalcMask(unsigned int msk) const +{ +if (msk > 32) + return 0; +return htonl(0xFFffFFff << (32 - msk)); +} +//----------------------------------------------------------------------------- +inline bool USER_IPS::IsIPInIPS(uint32_t ip) const { if (ips.empty()) @@ -163,14 +171,6 @@ return false; } //----------------------------------------------------------------------------- inline -uint32_t USER_IPS::CalcMask(unsigned int msk) const -{ -if (msk > 32) - return 0; -return htonl(0xFFffFFff << (32 - msk)); -} -//----------------------------------------------------------------------------- -inline void USER_IPS::Add(const IP_MASK &im) { ips.push_back(im); @@ -202,7 +202,6 @@ USER_IPS ips; char * paddr; IP_MASK im; std::vector ipMask; -std::string err; if (ipsStr.empty()) { return ips; @@ -236,7 +235,6 @@ for (unsigned int i = 0; i < ipMask.size(); i++) strIp = strtok(str, "/"); if (strIp == NULL) { - err = "Incorrect IP address " + ipsStr; return ips; } strMask = strtok(NULL, "/"); @@ -244,7 +242,6 @@ for (unsigned int i = 0; i < ipMask.size(); i++) im.ip = inet_addr(strIp); if (im.ip == INADDR_NONE) { - err = "Incorrect IP address: " + std::string(strIp); return ips; } @@ -254,20 +251,17 @@ for (unsigned int i = 0; i < ipMask.size(); i++) int m = 0; if (str2x(strMask, m) != 0) { - err = "Incorrect mask: " + std::string(strMask); return ips; } im.mask = m; if (im.mask > 32) { - err = "Incorrect mask: " + std::string(strMask); return ips; } if ((im.ip & ips.CalcMask(im.mask)) != im.ip) { - err = "Address does'n match mask: " + std::string(strIp) + "/" + std::string(strMask); return ips; } }