- assert(address);
- assert(family);
- assert(dst);
-
- /* IPv4 */
- r = inet_pton(AF_INET, address, dst);
- if (r > 0) {
- /* succsefully parsed IPv4 address */
- if (*family == AF_UNSPEC)
- *family = AF_INET;
- else if (*family != AF_INET)
- return -EINVAL;
- } else if (r < 0)
- return -errno;
- else {
- /* not an IPv4 address, so let's try IPv6 */
- r = inet_pton(AF_INET6, address, dst);
- if (r > 0) {
- /* successfully parsed IPv6 address */
- if (*family == AF_UNSPEC)
- *family = AF_INET6;
- else if (*family != AF_INET6)
- return -EINVAL;
- } else if (r < 0)
- return -errno;
+ assert(f);
+ assert(addresses);
+ assert(size);
+
+ for (i = 0; i < size; i++)
+ fprintf(f, "%s%s", inet_ntoa(addresses[i]),
+ (i < (size - 1)) ? " ": "");
+}
+
+int deserialize_in_addrs(struct in_addr **ret, const char *string) {
+ _cleanup_free_ struct in_addr *addresses = NULL;
+ int size = 0;
+ const char *word, *state;
+ size_t len;
+
+ assert(ret);
+ assert(string);
+
+ FOREACH_WORD(word, len, string, state) {
+ _cleanup_free_ char *addr_str = NULL;
+ struct in_addr *new_addresses;
+ int r;
+
+ new_addresses = realloc(addresses, (size + 1) * sizeof(struct in_addr));
+ if (!new_addresses)
+ return -ENOMEM;
+ else
+ addresses = new_addresses;
+
+ addr_str = strndup(word, len);
+ if (!addr_str)
+ return -ENOMEM;
+
+ r = inet_pton(AF_INET, addr_str, &(addresses[size]));
+ if (r <= 0)
+ continue;
+
+ size ++;
+ }
+
+ *ret = addresses;
+ addresses = NULL;
+
+ return size;
+}
+
+int deserialize_in6_addrs(struct in6_addr **ret, const char *string) {
+ _cleanup_free_ struct in6_addr *addresses = NULL;
+ int size = 0;
+ const char *word, *state;
+ size_t len;
+
+ assert(ret);
+ assert(string);
+
+ FOREACH_WORD(word, len, string, state) {
+ _cleanup_free_ char *addr_str = NULL;
+ struct in6_addr *new_addresses;
+ int r;
+
+ new_addresses = realloc(addresses, (size + 1) * sizeof(struct in6_addr));
+ if (!new_addresses)
+ return -ENOMEM;