From 1bf749aa3e4b0ccc40057b2587af5211926a1431 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Thu, 7 Nov 2019 16:42:01 +0100 Subject: [HICN-385] fix route removal in hicnctrl, code uniformization in hicn-light control api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id097368dcde993775f206623195cc5aa57b4fe12 Signed-off-by: Jordan Augé --- libtransport/src/hicn/transport/core/prefix.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'libtransport/src/hicn/transport/core/prefix.cc') diff --git a/libtransport/src/hicn/transport/core/prefix.cc b/libtransport/src/hicn/transport/core/prefix.cc index b7ddce73a..648c0a67b 100644 --- a/libtransport/src/hicn/transport/core/prefix.cc +++ b/libtransport/src/hicn/transport/core/prefix.cc @@ -77,7 +77,17 @@ void Prefix::buildPrefix(std::string &prefix, uint16_t prefix_length, throw errors::InvalidIpAddressException(); } - int ret = inet_pton(family, prefix.c_str(), ip_prefix_.address.buffer); + int ret; + switch (family) { + case AF_INET: + ret = inet_pton(AF_INET, prefix.c_str(), ip_prefix_.address.v4.buffer); + break; + case AF_INET6: + ret = inet_pton(AF_INET6, prefix.c_str(), ip_prefix_.address.v6.buffer); + break; + default: + throw errors::InvalidIpAddressException(); + } if (ret != 1) { throw errors::InvalidIpAddressException(); @@ -147,7 +157,7 @@ Name Prefix::getName() const { } Prefix &Prefix::setNetwork(std::string &network) { - if (!inet_pton(AF_INET6, network.c_str(), ip_prefix_.address.buffer)) { + if (!inet_pton(AF_INET6, network.c_str(), ip_prefix_.address.v6.buffer)) { throw errors::RuntimeException("The network name is not valid."); } @@ -165,8 +175,8 @@ Name Prefix::makeRandomName() const { uint32_t hash_size_bits = IPV6_ADDR_LEN_BITS - ip_prefix_.len; uint64_t ip_address[2]; - memcpy(ip_address, ip_prefix_.address.buffer, sizeof(uint64_t)); - memcpy(ip_address + 1, ip_prefix_.address.buffer + 8, sizeof(uint64_t)); + memcpy(ip_address, ip_prefix_.address.v6.buffer, sizeof(uint64_t)); + memcpy(ip_address + 1, ip_prefix_.address.v6.buffer + 8, sizeof(uint64_t)); std::string network(IPV6_ADDR_LEN * 3, 0); // Let's do the magic ;) -- cgit 1.2.3-korg