]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
network: Fix loc_network_is_subnet()
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Nov 2020 16:24:40 +0000 (16:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Nov 2020 16:24:40 +0000 (16:24 +0000)
This function always returned false.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/network.c

index 4c8787acc98cfa6b0e05251dbdff1b5956f1f1eb..b440d7610312b112b95f5be8e4294db71c45a8d0 100644 (file)
@@ -491,12 +491,12 @@ LOC_EXPORT int loc_network_overlaps(struct loc_network* self, struct loc_network
 LOC_EXPORT int loc_network_is_subnet(struct loc_network* self, struct loc_network* other) {
        // If the start address of the other network is smaller than this network,
        // it cannot be a subnet.
-       if (in6_addr_cmp(&self->first_address, &other->first_address) < 0)
+       if (in6_addr_cmp(&self->first_address, &other->first_address) > 0)
                return 0;
 
        // If the end address of the other network is greater than this network,
        // it cannot be a subnet.
-       if (in6_addr_cmp(&self->last_address, &other->last_address) > 0)
+       if (in6_addr_cmp(&self->last_address, &other->last_address) < 0)
                return 0;
 
        return 1;
@@ -504,17 +504,7 @@ LOC_EXPORT int loc_network_is_subnet(struct loc_network* self, struct loc_networ
 
 // XXX DEPRECATED - I find this too difficult to use
 LOC_EXPORT int loc_network_is_subnet_of(struct loc_network* self, struct loc_network* other) {
-       // If the start address of the other network is smaller than this network,
-       // it cannot be a subnet.
-       if (in6_addr_cmp(&self->first_address, &other->first_address) < 0)
-               return 0;
-
-       // If the end address of the other network is greater than this network,
-       // it cannot be a subnet.
-       if (in6_addr_cmp(&self->last_address, &other->last_address) > 0)
-               return 0;
-
-       return 1;
+       return loc_network_is_subnet(other, self);
 }
 
 LOC_EXPORT struct loc_network_list* loc_network_subnets(struct loc_network* network) {