]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/database.c
location-query: Allow filtering networks by family
[people/ms/libloc.git] / src / database.c
index f126c607c48d1aea35de4e0329552b10a2aff561..933f1c5d6c79ad622cdf068a8342f6fd672d39fe 100644 (file)
@@ -99,6 +99,7 @@ struct loc_database_enumerator {
        char country_code[3];
        uint32_t asn;
        enum loc_network_flags flags;
+       int family;
 
        // Index of the AS we are looking at
        unsigned int as_index;
@@ -943,6 +944,13 @@ LOC_EXPORT int loc_database_enumerator_set_flag(
        return 0;
 }
 
+LOC_EXPORT int loc_database_enumerator_set_family(
+               struct loc_database_enumerator* enumerator, int family) {
+       enumerator->family = family;
+
+       return 0;
+}
+
 LOC_EXPORT int loc_database_enumerator_next_as(
                struct loc_database_enumerator* enumerator, struct loc_as** as) {
        *as = NULL;
@@ -1070,6 +1078,14 @@ LOC_EXPORT int loc_database_enumerator_next_network(
 
                        // Check if we are interested in this network
 
+                       // Skip if the family does not match
+                       if (enumerator->family && loc_network_address_family(*network) != enumerator->family) {
+                               loc_network_unref(*network);
+                               *network = NULL;
+
+                               continue;
+                       }
+
                        // Skip if the country code does not match
                        if (*enumerator->country_code &&
                                        !loc_network_match_country_code(*network, enumerator->country_code)) {