aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/includes/hicn/compat.h12
-rw-r--r--lib/includes/hicn/util/ip_address.h17
-rw-r--r--lib/src/compat.c28
-rw-r--r--lib/src/name.c2
-rw-r--r--lib/src/util/ip_address.c4
5 files changed, 31 insertions, 32 deletions
diff --git a/lib/includes/hicn/compat.h b/lib/includes/hicn/compat.h
index b31d01a0d..2796983c6 100644
--- a/lib/includes/hicn/compat.h
+++ b/lib/includes/hicn/compat.h
@@ -234,7 +234,7 @@ int hicn_packet_get_payload (hicn_format_t format,
*/
int hicn_packet_get_locator (hicn_format_t format,
const hicn_header_t * packet,
- ip_prefix_t * prefix, bool is_interest);
+ ip_address_t * prefix, bool is_interest);
/**
* @brief Sets the locator of an interest / data packet
@@ -246,7 +246,7 @@ int hicn_packet_get_locator (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_set_locator (hicn_format_t format, hicn_header_t * packet,
- const ip_prefix_t * prefix,
+ const ip_address_t * prefix,
bool is_interest);
/**
@@ -396,9 +396,9 @@ int hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest,
const hicn_name_t * name);
int hicn_interest_get_locator (hicn_format_t format,
const hicn_header_t * interest,
- ip_prefix_t * prefix);
+ ip_address_t * prefix);
int hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest,
- const ip_prefix_t * prefix);
+ const ip_address_t * prefix);
int hicn_interest_compare (const hicn_header_t * interest_1,
const hicn_header_t * interest_2);
int hicn_interest_set_lifetime (hicn_header_t * interest, u32 lifetime);
@@ -425,9 +425,9 @@ int hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
int hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
const hicn_name_t * name);
int hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
- ip_prefix_t * prefix);
+ ip_address_t * prefix);
int hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
- const ip_prefix_t * prefix);
+ const ip_address_t * prefix);
int hicn_data_compare (const hicn_header_t * data_1,
const hicn_header_t * data_2);
int hicn_data_get_expiry_time (const hicn_header_t * data, u32 * expiry_time);
diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h
index 542e6e4c6..e39d08585 100644
--- a/lib/includes/hicn/util/ip_address.h
+++ b/lib/includes/hicn/util/ip_address.h
@@ -65,12 +65,15 @@
#define DUMMY_PORT 1234
typedef union {
- union {
- struct in_addr as_inaddr;
- u8 as_u8[4];
- u16 as_u16[2];
- u32 as_u32;
- } v4;
+ struct {
+ u32 pad[3];
+ union {
+ struct in_addr as_inaddr;
+ u8 as_u8[4];
+ u16 as_u16[2];
+ u32 as_u32;
+ } v4;
+ };
union {
struct in6_addr as_in6addr;
u8 as_u8[16];
@@ -121,7 +124,7 @@ extern const ip_address_t IP_ADDRESS_EMPTY;
/* IP address */
int ip_address_get_family (const char * ip_address);
-int ip_address_len (const ip_address_t * ip_address, int family);
+int ip_address_len (int family);
int ip_address_ntop (const ip_address_t * ip_address, char *dst,
const size_t len, int family);
int ip_address_pton (const char *ip_address_str, ip_address_t * ip_address);
diff --git a/lib/src/compat.c b/lib/src/compat.c
index 68f761ac0..8ec4c83e8 100644
--- a/lib/src/compat.c
+++ b/lib/src/compat.c
@@ -321,7 +321,7 @@ hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h,
int
hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
- ip_prefix_t * prefix, bool is_interest)
+ ip_address_t * address, bool is_interest)
{
const void *locator;
int is_ipv4 = (format & HFO_INET);
@@ -330,28 +330,24 @@ hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
if (is_ipv4)
{
locator = is_interest ? &h->v4.ip.saddr : &h->v4.ip.daddr;
- prefix->family = AF_INET;
- prefix->len = IPV4_ADDR_LEN_BITS;
}
else if (is_ipv6)
{
locator = is_interest ? &h->v6.ip.saddr : &h->v6.ip.daddr;
- prefix->family = AF_INET6;
- prefix->len = IPV6_ADDR_LEN_BITS;
}
else
{
return HICN_LIB_ERROR_NOT_IMPLEMENTED;
}
- memcpy (prefix->address.buffer, locator, ip_address_len(&prefix->address, prefix->family));
+ memcpy (address->as_u8, locator, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN);
return HICN_LIB_ERROR_NONE;
}
int
hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
- const ip_prefix_t * prefix, bool is_interest)
+ const ip_address_t * address, bool is_interest)
{
void *locator;
int is_ipv4 = (format & HFO_INET);
@@ -370,7 +366,7 @@ hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
return HICN_LIB_ERROR_INVALID_PARAMETER;
}
- memcpy (locator, prefix->address.buffer, ip_address_len(&prefix->address, prefix->family));
+ memcpy (locator, address->as_u8, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN);
return HICN_LIB_ERROR_NONE;
}
@@ -953,16 +949,16 @@ hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest,
int
hicn_interest_get_locator (hicn_format_t format,
const hicn_header_t * interest,
- ip_prefix_t * prefix)
+ ip_address_t * address)
{
- return hicn_packet_get_locator (format, interest, prefix, _INTEREST);
+ return hicn_packet_get_locator (format, interest, address, _INTEREST);
}
int
hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest,
- const ip_prefix_t * prefix)
+ const ip_address_t * address)
{
- return hicn_packet_set_locator (format, interest, prefix, _INTEREST);
+ return hicn_packet_set_locator (format, interest, address, _INTEREST);
}
int
@@ -1045,16 +1041,16 @@ hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
int
hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
- ip_prefix_t * prefix)
+ ip_address_t * address)
{
- return hicn_packet_get_locator (format, data, prefix, _DATA);
+ return hicn_packet_get_locator (format, data, address, _DATA);
}
int
hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
- const ip_prefix_t * prefix)
+ const ip_address_t * address)
{
- return hicn_packet_set_locator (format, data, prefix, _DATA);
+ return hicn_packet_set_locator (format, data, address, _DATA);
}
int
diff --git a/lib/src/name.c b/lib/src/name.c
index d5ee1d520..2e98a3532 100644
--- a/lib/src/name.c
+++ b/lib/src/name.c
@@ -96,7 +96,7 @@ hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
}
memcpy (name->buffer, prefix->address.buffer,
- ip_address_len(&prefix->address, prefix->family));
+ ip_address_len(prefix->family));
*(u32 *) (name->buffer + name->len) = id;
return HICN_LIB_ERROR_NONE;
diff --git a/lib/src/util/ip_address.c b/lib/src/util/ip_address.c
index c54b1fae6..d4fbcaae6 100644
--- a/lib/src/util/ip_address.c
+++ b/lib/src/util/ip_address.c
@@ -77,7 +77,7 @@ ip_address_get_family (const char * ip_address)
}
int
-ip_address_len (const ip_address_t * ip_address, int family)
+ip_address_len (int family)
{
return (family == AF_INET6) ? IPV6_ADDR_LEN :
(family == AF_INET) ? IPV4_ADDR_LEN : 0;
@@ -165,7 +165,7 @@ ip_address_to_sockaddr(const ip_address_t * ip_address,
int
ip_address_cmp(const ip_address_t * ip1, const ip_address_t * ip2, int family)
{
- return memcmp(ip1, ip2, ip_address_len(ip1, family));
+ return memcmp(ip1, ip2, ip_address_len(family));
}
int