size_t option_data_len,
const uint8_t *option_data,
DHCP6IA *ret);
-int dhcp6_option_parse_ip6addrs(const uint8_t *optval, uint16_t optlen,
- struct in6_addr **addrs, size_t count);
+int dhcp6_option_parse_addresses(
+ const uint8_t *optval,
+ size_t optlen,
+ struct in6_addr **addrs,
+ size_t *count);
int dhcp6_option_parse_domainname_list(const uint8_t *optval, uint16_t optlen,
char ***str_arr);
int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char **str);
return 0;
}
-int dhcp6_option_parse_ip6addrs(const uint8_t *optval, uint16_t optlen,
- struct in6_addr **addrs, size_t count) {
+int dhcp6_option_parse_addresses(
+ const uint8_t *optval,
+ size_t optlen,
+ struct in6_addr **addrs,
+ size_t *count) {
+
+ assert(optval);
+ assert(addrs);
+ assert(count);
if (optlen == 0 || optlen % sizeof(struct in6_addr) != 0)
- return -EINVAL;
+ return -EBADMSG;
- if (!GREEDY_REALLOC(*addrs, count * sizeof(struct in6_addr) + optlen))
+ if (!GREEDY_REALLOC(*addrs, *count + optlen / sizeof(struct in6_addr)))
return -ENOMEM;
- memcpy(*addrs + count, optval, optlen);
+ memcpy(*addrs + *count, optval, optlen);
+ *count += optlen / sizeof(struct in6_addr);
- count += optlen / sizeof(struct in6_addr);
-
- return count;
+ return 0;
}
static int parse_domain(const uint8_t **data, uint16_t *len, char **out_domain) {
}
int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
- int r;
-
assert_return(lease, -EINVAL);
assert_return(optval, -EINVAL);
- if (!optlen)
+ if (optlen == 0)
return 0;
- r = dhcp6_option_parse_ip6addrs(optval, optlen, &lease->dns,
- lease->dns_count);
- if (r < 0)
- return r;
-
- lease->dns_count = r;
-
- return 0;
+ return dhcp6_option_parse_addresses(optval, optlen, &lease->dns, &lease->dns_count);
}
int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, const struct in6_addr **addrs) {
if (sublen != 16)
return 0;
- r = dhcp6_option_parse_ip6addrs(subval, sublen, &lease->ntp, lease->ntp_count);
+ r = dhcp6_option_parse_addresses(subval, sublen, &lease->ntp, &lease->ntp_count);
if (r < 0)
return r;
- lease->ntp_count = r;
-
break;
case DHCP6_NTP_SUBOPTION_SRV_FQDN: {
}
int dhcp6_lease_set_sntp(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
- int r;
-
assert_return(lease, -EINVAL);
assert_return(optval, -EINVAL);
- if (!optlen)
+ if (optlen == 0)
return 0;
if (lease->ntp || lease->ntp_fqdn)
/* Using deprecated SNTP information */
- r = dhcp6_option_parse_ip6addrs(optval, optlen, &lease->ntp,
- lease->ntp_count);
- if (r < 0)
- return r;
-
- lease->ntp_count = r;
-
- return 0;
+ return dhcp6_option_parse_addresses(optval, optlen, &lease->ntp, &lease->ntp_count);
}
int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease,