From e00d77ddd598ea6cbc2d512d143e9e4d98e62256 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 14 Apr 2014 12:41:13 +0200 Subject: [PATCH] sd-rtnl: message_addr - expose a few more getters --- src/libsystemd/sd-rtnl/rtnl-message.c | 60 +++++++++++++++++++++++++++++++++++ src/systemd/sd-rtnl.h | 4 +++ 2 files changed, 64 insertions(+) diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index c9f3487..fc71ed9 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -259,6 +259,66 @@ int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope) { return 0; } +int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, unsigned char *family) { + 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(family, -EINVAL); + + ifa = NLMSG_DATA(m->hdr); + + *family = ifa->ifa_family; + + return 0; +} + +int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope) { + 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(scope, -EINVAL); + + ifa = NLMSG_DATA(m->hdr); + + *scope = ifa->ifa_scope; + + return 0; +} + +int sd_rtnl_message_addr_get_flags(sd_rtnl_message *m, unsigned char *flags) { + 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(flags, -EINVAL); + + ifa = NLMSG_DATA(m->hdr); + + *flags = ifa->ifa_flags; + + return 0; +} + +int sd_rtnl_message_addr_get_ifindex(sd_rtnl_message *m, int *ifindex) { + 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(ifindex, -EINVAL); + + ifa = NLMSG_DATA(m->hdr); + + *ifindex = ifa->ifa_index; + + return 0; +} + int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlmsg_type, int index, unsigned char family) { diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h index f7f7074..c32c5e2 100644 --- a/src/systemd/sd-rtnl.h +++ b/src/systemd/sd-rtnl.h @@ -84,6 +84,10 @@ int sd_rtnl_message_is_broadcast(sd_rtnl_message *m); int sd_rtnl_message_addr_set_prefixlen(sd_rtnl_message *m, unsigned char prefixlen); 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_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); int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned change); int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type); -- 2.7.4