From f4e884dd1c4cc4bc6d5f068f96b14ceda46f3962 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 10 May 2014 16:06:23 +0200 Subject: [PATCH] sd-rtnl: message - add support for getting prefixlen from address messages --- src/libsystemd/sd-rtnl/rtnl-message.c | 15 +++++++++++++++ src/systemd/sd-rtnl.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index 9043c67..d611207 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -290,6 +290,21 @@ int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, unsigned char *family) { return 0; } +int sd_rtnl_message_addr_get_prefixlen(sd_rtnl_message *m, unsigned char *prefixlen) { + struct ifaddrmsg *ifa; + + assert_return(m, -EINVAL); + assert_return(m->hdr, -EINVAL); + assert_return(rtnl_message_type_is_addr(m->hdr->nlmsg_type), -EINVAL); + assert_return(prefixlen, -EINVAL); + + ifa = NLMSG_DATA(m->hdr); + + *prefixlen = ifa->ifa_prefixlen; + + return 0; +} + int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope) { struct ifaddrmsg *ifa; diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h index 93f5ab9..9059ed4 100644 --- a/src/systemd/sd-rtnl.h +++ b/src/systemd/sd-rtnl.h @@ -86,6 +86,7 @@ int sd_rtnl_message_addr_set_prefixlen(sd_rtnl_message *m, unsigned char prefixl int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope); int sd_rtnl_message_addr_set_flags(sd_rtnl_message *m, unsigned char flags); int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, unsigned char *family); +int sd_rtnl_message_addr_get_prefixlen(sd_rtnl_message *m, unsigned char *prefixlen); int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope); int sd_rtnl_message_addr_get_flags(sd_rtnl_message *m, unsigned char *flags); int sd_rtnl_message_addr_get_ifindex(sd_rtnl_message *m, int *ifindex); -- 2.7.4