]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
libnetlink: add attribute access inline functions
authorStephen Hemminger <shemminger@vyatta.com>
Thu, 29 Dec 2011 17:29:33 +0000 (09:29 -0800)
committerStephen Hemminger <shemminger@vyatta.com>
Thu, 29 Dec 2011 17:29:33 +0000 (09:29 -0800)
Based on idea in libmnl, add attribute access functions instead
of explicitly exposing casts. Also handle possible alignment issues
of u64.

include/libnetlink.h

index a828032df7c95f9f39f25aeb9853dd540e36792a..b2375798340bbb48708c9a8196fff773579e7b0a 100644 (file)
@@ -70,6 +70,25 @@ extern int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rta
        ({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL;       \
                __parse_rtattr_nested_compat(tb, max, rta, len); })
 
+static inline __u16 rta_getattr_u16(const struct rtattr *rta)
+{
+       return *(__u16 *)RTA_DATA(rta);
+}
+static inline __u16 rta_getattr_u32(const struct rtattr *rta)
+{
+       return *(__u32 *)RTA_DATA(rta);
+}
+static inline __u64 rta_getattr_u64(const struct rtattr *rta)
+{
+       __u64 tmp;
+       memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
+       return tmp;
+}
+static inline const char *rta_getattr_str(const struct rtattr *rta)
+{
+       return RTA_DATA(rta);
+}
+
 extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler,
                       void *jarg);
 extern int rtnl_from_file(FILE *, rtnl_filter_t handler,