icmp6: Add l_icmp6_router_get_address
PATCH 1/3 icmp6: Add l_icmp6_router_get_address
Add a getter for the router's address and make a small formatting change while there.
--- ell/ell.sym | 1 + ell/icmp6.c | 15 ++++++++++++++- ell/icmp6.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-)
ell/ell.sym +1 -0
@@ -657,6 +657,7 @@ global: l_icmp6_client_set_nodelay; l_icmp6_client_set_rtnl; l_icmp6_client_set_route_priority; + l_icmp6_router_get_address; l_icmp6_router_get_managed; l_icmp6_router_get_other; /* acd */
ell/icmp6.c +14 -1
@@ -728,12 +728,25 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra, } opts += l; - opts_len -= l ; + opts_len -= l; }return r; } +LIB_EXPORT char *l_icmp6_router_get_address(const struct l_icmp6_router *r) +{ +char buf[INET6_ADDRSTRLEN ]; + +if (unlikely (!r)) +return NULL ; + +if (!inet_ntop (AF_INET6 , r->address, buf,sizeof (buf))) +return NULL ; + +return l_strdup (buf); +} + LIB_EXPORT bool l_icmp6_router_get_managed(const struct l_icmp6_router *r) {if (unlikely (!r))
ell/icmp6.h +1 -0
@@ -66,6 +66,7 @@ bool l_icmp6_client_set_rtnl(struct l_icmp6_client *client,bool l_icmp6_client_set_route_priority (struct l_icmp6_client *client,uint32_t priority); +char *l_icmp6_router_get_address (const struct l_icmp6_router *r);bool l_icmp6_router_get_managed (const struct l_icmp6_router *r);bool l_icmp6_router_get_other (const struct l_icmp6_router *r);
Signature · 1 line
2.30.2
PATCH 2/3 rtnl: Add l_rtnl_route_get_gateway
--- ell/ell.sym | 1 + ell/rtnl.c | 10 ++++++++++ ell/rtnl.h | 1 + 3 files changed, 12 insertions(+)
ell/ell.sym +1 -0
@@ -607,6 +607,7 @@ global: l_rtnl_route_new_prefix; l_rtnl_route_free; l_rtnl_route_get_family; + l_rtnl_route_get_gateway; l_rtnl_route_get_lifetime; l_rtnl_route_set_lifetime; l_rtnl_route_get_mtu;
ell/rtnl.c +10 -0
@@ -389,6 +389,16 @@ LIB_EXPORT uint8_t l_rtnl_route_get_family(const struct l_rtnl_route *rt)return rt->family; } +LIB_EXPORT bool l_rtnl_route_get_gateway(const struct l_rtnl_route *rt, +char *out_buf) +{ +if (unlikely (!rt)) +return false; + +return !address_to_string (rt->family, &rt->gw.in_addr, &rt->gw.in6_addr, + out_buf); +} + LIB_EXPORT uint32_t l_rtnl_route_get_lifetime(const struct l_rtnl_route *rt) {if (unlikely (!rt))
ell/rtnl.h +1 -0
@@ -61,6 +61,7 @@ struct l_rtnl_route *l_rtnl_route_new_prefix(const char *ip, uint8_t prefix_len);void l_rtnl_route_free (struct l_rtnl_route *rt);uint8_t l_rtnl_route_get_family (const struct l_rtnl_route *rt); +bool l_rtnl_route_get_gateway (const struct l_rtnl_route *rt,char *out_buf);uint32_t l_rtnl_route_get_lifetime (const struct l_rtnl_route *rt);bool l_rtnl_route_set_lifetime (struct l_rtnl_route *rt,uint32_t lt);uint32_t l_rtnl_route_get_mtu (const struct l_rtnl_route *rt);
Signature · 1 line
2.30.2
PATCH 3/3 util: Add l_streq0
In reply to Andrew ZaborowskiAdd a glib/nm-utils -style utility for comparing two strings that handles NULL values (unlike strcmp). Two NULL strings are treated as equal.
--- ell/util.c | 13 +++++++++++++ ell/util.h | 1 + 2 files changed, 14 insertions(+)
ell/util.c +13 -0
@@ -342,6 +342,19 @@ LIB_EXPORT bool l_str_has_suffix(const char *str, const char *suffix)return !strcmp (&str[len_diff], suffix); } +/** +* l_streq0: +* @a: First operand +* @b: Second operand +* +* Returns: True if @a and @b are both NULL or both non-NULL and identical +* according to strcmp. False otherwise. +*/ +LIB_EXPORT bool l_streq0(const char *a, const char *b) +{ +return a == b || (a && b && !strcmp (a, b)); +} +static char *hexstring_common (const unsigned char *buf,size_t len,const char hexdigits[static 16 ]) {
ell/util.h +1 -0
@@ -276,6 +276,7 @@ size_t l_strlcpy(char* dst, const char *src, size_t len);bool l_str_has_prefix (const char *str,const char *prefix);bool l_str_has_suffix (const char *str,const char *suffix); +bool l_streq0 (const char *a,const char *b);char *l_util_hexstring (const unsigned char *buf,size_t len);char *l_util_hexstring_upper (const unsigned char *buf,size_t len);
Signature · 1 line
2.30.2
Re: [PATCH 3/3] util: Add l_streq0
ell/util.h size_t l_strlcpy(char* dst, const char *src, size_t len); · line 279
Quoted 9 lines · Andrew Zaborowski
ell/util.h +1
-0@@ -276,6 +276,7 @@ size_t l_strlcpy(char* dst, const char *src, size_t len);bool l_str_has_prefix (const char *str,const char *prefix);bool l_str_has_suffix (const char *str,const char *suffix); +bool l_streq0 (const char *a,const char *b);
Should l_streq0 be added to ell.sym?
// Martin
Re: [PATCH 3/3] util: Add l_streq0
Hi Martin,
Quoted 4 lines · Martin Hundebøll
Quoted 1 line · Andrew Zaborowski
+bool
l_streq0(const char *a, const char *b);Should
l_streq0be added to ell.sym?
It should and I realised it too late so I resent the patch including this change.
Best regards
Hi Andrew,
Quoted 8 lines · Andrew Zaborowski
Add a getter for the router's address and make a small formatting change while there.
--- ell/ell.sym | 1 + ell/icmp6.c | 15 ++++++++++++++- ell/icmp6.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-)
Patch 1 & 2 applied from this series and the follow-up 3/3 as well.
Regards,
-Denis