uint32_t asn;
};
+static int valid_prefix(struct in6_addr* address, unsigned int prefix) {
+ // The prefix cannot be larger than 128 bits
+ if (prefix > 128)
+ return 1;
+
+ // And the prefix cannot be zero
+ if (prefix == 0)
+ return 1;
+
+ return 0;
+}
+
LOC_EXPORT int loc_network_new(struct loc_ctx* ctx, struct loc_network** network,
struct in6_addr start_address, unsigned int prefix) {
// Address cannot be unspecified
return -EINVAL;
}
+ // Validate the prefix
+ if (valid_prefix(&start_address, prefix) != 0) {
+ DEBUG(ctx, "Invalid prefix: %u\n", prefix);
+ return -EINVAL;
+ }
+
struct loc_network* n = calloc(1, sizeof(*n));
if (!n)
return -ENOMEM;