| Return Type | Function name | Arguments |
|---|---|---|
| const char* | GetIpLocation | (const hzIpaddr&,) |
Declared in file: hzIpaddr.h
Defined in file : hzIpaddr.cpp
Function Logic:
Function body:
const char* GetIpLocation (const hzIpaddr& ipa)
{
_hzfunc(__func__) ;
static hzString ip_not_found = "-- IP Location Not-found" ;
static hzString ip_error = "-- IP Location Error" ;
const uint32_t* pZones ;
uint32_t nDiv ;
uint32_t nPos ;
uint32_t nMax ;
uint32_t ipval ;
bool bFound ;
if (s_IpCity_max)
{
pZones = s_IpCity_zones ;
nDiv = s_IpCity_div ;
nPos = s_IpCity_start ;
nMax = s_IpCity_max ;
}
else
{
if (!s_IpBasic_max)
return *ip_not_found ;
pZones = s_IpBasic_zones ;
nDiv = s_IpBasic_div ;
nPos = s_IpBasic_start ;
nMax = s_IpBasic_max ;
}
bFound = false ;
ipval = (uint32_t) ipa ;
for (;;)
{
if (nPos >&eq; nMax)
{
if (!nDiv)
break ;
nPos -= nDiv ;
nDiv /= 2;
continue ;
}
if (ipval >&eq; pZones[nPos+1])
{
if (!nDiv)
break ;
nPos += nDiv ;
nDiv /= 2;
continue ;
}
if (ipval < pZones[nPos])
{
if (!nDiv)
break ;
nPos -= nDiv ;
nDiv /= 2;
continue ;
}
bFound = true ;
break ;
}
if (!bFound)
{
threadLog("Not found\n") ;
return *ip_not_found ;
}
if (s_IpCity_max)
{
return s_IpCity_text + s_IpCity_osets[nPos] ;
}
return GetCountryCode(s_IpBasic_codes[nPos]) ;
}