diff mbox series

[4/7] rtnl: Add l_rtnl_address_get_in_addr

Message ID 20220919133105.3129080-4-andrew.zaborowski@intel.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/7] icmp6: Save SLAAC prefixes from RAs | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Andrew Zaborowski Sept. 19, 2022, 1:31 p.m. UTC
Similar to l_rtnl_route_get_dst_in_addr add a getter for the raw address
value, avoiding extra string conversions.
---
 ell/ell.sym | 1 +
 ell/rtnl.c  | 9 +++++++++
 ell/rtnl.h  | 1 +
 3 files changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/ell/ell.sym b/ell/ell.sym
index a28eb55..d76b2ea 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -626,6 +626,7 @@  global:
 	l_rtnl_address_clone;
 	l_rtnl_address_free;
 	l_rtnl_address_get_address;
+	l_rtnl_address_get_in_addr;
 	l_rtnl_address_get_family;
 	l_rtnl_address_get_prefix_length;
 	l_rtnl_address_get_broadcast;
diff --git a/ell/rtnl.c b/ell/rtnl.c
index 2483e82..5909c4b 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -180,6 +180,15 @@  LIB_EXPORT bool l_rtnl_address_get_address(const struct l_rtnl_address *addr,
 						out_buf);
 }
 
+LIB_EXPORT const void *l_rtnl_address_get_in_addr(
+					const struct l_rtnl_address *addr)
+{
+	if (unlikely(!addr))
+		return NULL;
+
+	return addr->family == AF_INET ? (void *) &addr->in_addr : &addr->in6_addr;
+}
+
 LIB_EXPORT uint8_t l_rtnl_address_get_family(const struct l_rtnl_address *addr)
 {
 	if (unlikely(!addr))
diff --git a/ell/rtnl.h b/ell/rtnl.h
index ffd1d73..1e6b1fa 100644
--- a/ell/rtnl.h
+++ b/ell/rtnl.h
@@ -44,6 +44,7 @@  void l_rtnl_address_free(struct l_rtnl_address *addr);
 DEFINE_CLEANUP_FUNC(l_rtnl_address_free);
 bool l_rtnl_address_get_address(const struct l_rtnl_address *addr,
 				char *out_buf);
+const void *l_rtnl_address_get_in_addr(const struct l_rtnl_address *addr);
 uint8_t l_rtnl_address_get_family(const struct l_rtnl_address *addr);
 uint8_t l_rtnl_address_get_prefix_length(const struct l_rtnl_address *addr);
 bool l_rtnl_address_get_broadcast(const struct l_rtnl_address *addr,