/** * Retrieves the country an address is assigned to. * * @param ha the host address to look up. * @return the country mapped to this IP address as a numerically-encoded * country code, or ISO3166_INVALID when unknown. */ uint16 gip_country(const host_addr_t ha) { uint16 code; if G_UNLIKELY(NULL == geo_db) return ISO3166_INVALID; code = iprange_get_addr(geo_db, ha); return 0 == code ? ISO3166_INVALID : (code >> 1) - 1; }
/** * Check the given IP against the entries in the bogus IP database. * * @returns TRUE if found, and FALSE if not. */ bool bogons_check(const host_addr_t ha) { if G_UNLIKELY(NULL == bogons_db) return FALSE; /* * If the bogons file is too ancient, there is a risk it may flag an * IP as bogus whereas it is no longer reserved. IPv4 address shortage * makes that likely. * --RAM, 2010-11-07 */ if (delta_time(tm_time(), bogons_mtime) > 15552000) /* ~6 months */ return !host_addr_is_routable(ha); return 0 != iprange_get_addr(bogons_db, ha); }