diff options
author | Jordan Augé <jordan.auge+fdio@cisco.com> | 2019-11-07 16:42:01 +0100 |
---|---|---|
committer | Jordan Augé <jordan.auge+fdio@cisco.com> | 2019-11-08 01:36:45 +0100 |
commit | 1bf749aa3e4b0ccc40057b2587af5211926a1431 (patch) | |
tree | 1e59105d64e7dc13f4f1cd4ae8437bb8bb932292 /libtransport/src/hicn/transport/core/prefix.cc | |
parent | a30d495f6e91f3bed0420bf76c19315fe0de8801 (diff) |
[HICN-385] fix route removal in hicnctrl, code uniformization in hicn-light control api
Change-Id: Id097368dcde993775f206623195cc5aa57b4fe12
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/core/prefix.cc')
-rw-r--r-- | libtransport/src/hicn/transport/core/prefix.cc | 18 |
1 files changed, 14 insertions, 4 deletions
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 ;) |