There is no point in checking different address families
with each other and we do not need to compare addresses
when the prefix of the subnet does not fit into the
network to check.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
}
LOC_EXPORT int loc_network_is_subnet(struct loc_network* self, struct loc_network* other) {
+ // Check family
+ if (self->family != other->family)
+ return 0;
+
+ // The prefix must be smaller (this avoids the more complex comparisons later)
+ if (self->prefix > other->prefix)
+ return 0;
+
// 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)