bool LocalIPAddresses::IsWithinLoopbackRange(const IPAddress &address) { if (address.GetType() == IPAddress::IPV4) { unsigned __int64 longAddress = address.GetAddress1(); // 127.0.0.1 - 127.255.255.255 if (longAddress >= 2130706433 && longAddress <= 2147483647) return true; else return false; } else if (address.GetType() == IPAddress::IPV6) { if (address.GetAddress1() == 0 && address.GetAddress2() == 1) return true; else return false; } return true; /* */ }
bool IPAddress::operator<(const IPAddress &other) { bool inputIsGreater = other.GetAddress1() > GetAddress1() || (other.GetAddress1() == GetAddress1() && other.GetAddress2() > GetAddress2()); return inputIsGreater; }
AnsiString IPAddressSQLHelper::GetAddress2Equals(const IPAddress &address) const { if (address.GetType() == IPAddress::IPV4) return "IS NULL"; String s; s.Format(_T("= %I64d"), address.GetAddress2()); return s; }
void IPAddressSQLHelper::AppendStatement(SQLStatement &statement, const IPAddress &address, const AnsiString &address1Column, const AnsiString &address2Column) const { statement.AddColumnInt64(address1Column, address.GetAddress1()); if (address.GetType() == IPAddress::IPV6) statement.AddColumnInt64(address2Column, address.GetAddress2()); else statement.AddColumnNULL(address2Column); }
bool IPAddress::WithinRange(const IPAddress &lower, const IPAddress &upper) const { #ifdef _DEBUG String lower1 = lower.ToString(); String lower2 = upper.ToString(); String thisIP = ToString(); #endif if (GetAddress1() < lower.GetAddress1() || GetAddress1() > upper.GetAddress1()) return false; // If it's an IPv4 address, we don't need to compare the second part. if (_address.is_v4()) return true; if (GetAddress2() < lower.GetAddress2() || GetAddress2() > upper.GetAddress2()) return false; return true; }