/** * Calculate the number of hosts covered by the ranges in the database. * * @param db the IP range database * * @return The number of IPv4 hosts listed. */ unsigned iprange_get_host_count4(const struct iprange_db *idb) { size_t i, n; unsigned hosts = 0; n = sorted_array_size(idb->tab4); for (i = 0; i < n; i++) { struct iprange_net4 *item = sorted_array_item(idb->tab4, i); hosts += 1 << item->bits; } return hosts; }
/** * Calculate the number of hosts covered by the ranges in the database. * * @param db the IP range database * @return The number of hosts listed. */ guint iprange_get_host_count(const struct iprange_db *idb) { size_t i, n; guint hosts = 0; n = iprange_get_item_count(idb); for (i = 0; i < n; i++) { struct iprange_net *item = sorted_array_item(idb->tab, i); hosts += ~item->mask + 1; } return hosts; }