Commit 17e3d8fd authored by Michael Tremer's avatar Michael Tremer

address: Set default prefix if none is given

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 95b6a8e4
......@@ -138,11 +138,22 @@ int loc_address_parse(struct in6_addr* address, unsigned int* prefix, const char
// Did the user request a prefix?
if (prefix) {
// Set the prefix to the default value
*prefix = loc_address_family_bit_length(family);
const unsigned int max_prefix = loc_address_family_bit_length(family);
// Parse the actual string
if (p)
if (p) {
*prefix = strtol(p, NULL, 10);
// Check if prefix is within bounds
if (*prefix > max_prefix) {
errno = EINVAL;
return 1;
}
// If the string didn't contain a prefix, we set the maximum
} else {
*prefix = max_prefix;
}
}
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment