diff options
author | Tom Gundersen <teg@jklm.no> | 2014-05-18 22:02:42 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-05-19 18:14:56 +0200 |
commit | 09bee74d7a5f266b175baa19892fa84a9da51d7f (patch) | |
tree | 75c11ceda996f9a098461ef41b0ee1de045d1ce2 /src/libsystemd-network/sd-dhcp-lease.c | |
parent | a077b666cb883213fd85be21b518c2de54cb70b1 (diff) |
sd-dhcp-lease: move in_addr (de)serialization to shared network code
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-lease.c | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 3e43ab635f..4993fe3641 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -36,6 +36,7 @@ #include "dhcp-lease-internal.h" #include "sd-dhcp-lease.h" #include "sd-dhcp-client.h" +#include "network-internal.h" int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) { assert_return(lease, -EINVAL); @@ -307,46 +308,6 @@ int dhcp_lease_new(sd_dhcp_lease **ret) { return 0; } -static void serialize_addresses(FILE *f, const char *key, struct in_addr *addresses, size_t size) { - unsigned i; - - assert(key); - assert(addresses); - assert(size); - - fputs("DNS=", f); - - for (i = 0; i < size; i++) - fprintf(f, "%s%s", inet_ntoa(addresses[i]), - (i < (size - 1)) ? " ": ""); - - fputs("\n", f); -} - -static int deserialize_addresses(struct in_addr **addresses, size_t *size, const char *string) { - char *word, *state; - size_t len; - - FOREACH_WORD(word, len, string, state) { - 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; - - r = inet_aton(word, &(new_addresses[*size])); - if (r < 0) - continue; - - (*size)++; - } - - return 0; -} - int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; @@ -399,11 +360,11 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { r = sd_dhcp_lease_get_dns(lease, &addresses, &addresses_size); if (r >= 0) - serialize_addresses(f, "DNS", addresses, addresses_size); + serialize_in_addrs(f, "DNS", addresses, addresses_size); r = sd_dhcp_lease_get_ntp(lease, &addresses, &addresses_size); if (r >= 0) - serialize_addresses(f, "NTP", addresses, addresses_size); + serialize_in_addrs(f, "NTP", addresses, addresses_size); r = sd_dhcp_lease_get_domainname(lease, &string); if (r >= 0) @@ -507,13 +468,13 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) { } if (dns) { - r = deserialize_addresses(&lease->dns, &lease->dns_size, dns); + r = deserialize_in_addrs(&lease->dns, &lease->dns_size, dns); if (r < 0) return r; } if (ntp) { - r = deserialize_addresses(&lease->ntp, &lease->ntp_size, dns); + r = deserialize_in_addrs(&lease->ntp, &lease->ntp_size, dns); if (r < 0) return r; } |