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/network | |
parent | sd-login: add C API to query primary session of a user (diff) | |
download | systemd-09bee74d7a5f266b175baa19892fa84a9da51d7f.tar.xz systemd-09bee74d7a5f266b175baa19892fa84a9da51d7f.zip |
sd-dhcp-lease: move in_addr (de)serialization to shared network code
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/test-network.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/network/test-network.c b/src/network/test-network.c index a0e04f8fd2..eb6ebe70b3 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -20,6 +20,38 @@ ***/ #include "networkd.h" +#include "network-internal.h" + +static void test_deserialize_in_addr(void) { + _cleanup_free_ struct in_addr *addresses = NULL; + _cleanup_free_ struct in6_addr *addresses6 = NULL; + struct in_addr a, b, c; + struct in6_addr d, e, f; + size_t size; + const char *addresses_string = "192.168.0.1 0:0:0:0:0:FFFF:204.152.189.116 192.168.0.2 ::1 192.168.0.3 1:0:0:0:0:0:0:8"; + + assert_se(inet_pton(AF_INET, "0:0:0:0:0:FFFF:204.152.189.116", &a) == 0); + assert_se(inet_pton(AF_INET6, "192.168.0.1", &d) == 0); + + assert_se(inet_pton(AF_INET, "192.168.0.1", &a) == 1); + assert_se(inet_pton(AF_INET, "192.168.0.2", &b) == 1); + assert_se(inet_pton(AF_INET, "192.168.0.3", &c) == 1); + assert_se(inet_pton(AF_INET6, "0:0:0:0:0:FFFF:204.152.189.116", &d) == 1); + assert_se(inet_pton(AF_INET6, "::1", &e) == 1); + assert_se(inet_pton(AF_INET6, "1:0:0:0:0:0:0:8", &f) == 1); + + assert_se(deserialize_in_addrs(&addresses, &size, addresses_string) >= 0); + assert_se(size == 3); + assert_se(!memcmp(&a, &addresses[0], sizeof(struct in_addr))); + assert_se(!memcmp(&b, &addresses[1], sizeof(struct in_addr))); + assert_se(!memcmp(&c, &addresses[2], sizeof(struct in_addr))); + + assert_se(deserialize_in6_addrs(&addresses6, &size, addresses_string) >= 0); + assert_se(size == 3); + assert_se(!memcmp(&d, &addresses6[0], sizeof(struct in6_addr))); + assert_se(!memcmp(&e, &addresses6[1], sizeof(struct in6_addr))); + assert_se(!memcmp(&f, &addresses6[2], sizeof(struct in6_addr))); +} static void test_load_config(Manager *manager) { /* TODO: should_reload, is false if the config dirs do not exist, so @@ -43,7 +75,7 @@ static void test_network_get(Manager *manager, struct udev_device *loopback) { } static void test_address_equality(void) { - Address *a1, *a2; + _cleanup_address_free_ Address *a1 = NULL, *a2 = NULL; assert_se(address_new_dynamic(&a1) >= 0); assert_se(address_new_dynamic(&a2) >= 0); @@ -92,6 +124,7 @@ int main(void) { struct udev *udev; struct udev_device *loopback; + test_deserialize_in_addr(); test_address_equality(); assert_se(manager_new(&manager) >= 0); |