From 8416d5a6334bb6857e27ea3aad5d1f5b42e47062 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Mon, 17 Mar 2014 20:02:22 -0400 Subject: [PATCH] Make nl.c:nl_rtattr_parse() use the standard NLMSG_* and RTA_* macros. It's easier to verify correct behavior this way. --- ndhc/nl.c | 11 ++++------- ndhc/nl.h | 5 ----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ndhc/nl.c b/ndhc/nl.c index 1b277a8..5bd8b25 100644 --- a/ndhc/nl.c +++ b/ndhc/nl.c @@ -81,13 +81,10 @@ void nl_attr_parse(const struct nlmsghdr *nlh, size_t offset, void nl_rtattr_parse(const struct nlmsghdr *nlh, size_t offset, nl_rtattr_parse_fn workfn, void *data) { - struct rtattr *attr; - for (attr = (struct rtattr *) - ((char *)nlh + NLMSG_HDRLEN + NLMSG_ALIGN(offset)); - rtattr_ok(attr, (char *)nlh + NLMSG_ALIGN(nlh->nlmsg_len) - - (char *)attr); - attr = (struct rtattr *)((char *)attr + NLMSG_ALIGN(attr->rta_len))) - { + struct rtattr *attr = + (struct rtattr *)((char *)NLMSG_DATA(nlh) + NLMSG_ALIGN(offset)); + size_t rtlen = nlh->nlmsg_len - NLMSG_HDRLEN - NLMSG_ALIGN(offset); + for (; RTA_OK(attr, rtlen); attr = RTA_NEXT(attr, rtlen)) { if (workfn(attr, attr->rta_type, data) < 0) break; } diff --git a/ndhc/nl.h b/ndhc/nl.h index dee1ef3..0077c0e 100644 --- a/ndhc/nl.h +++ b/ndhc/nl.h @@ -44,11 +44,6 @@ static inline int nl_attr_ok(const struct nlattr *attr, size_t len) return 1; } -static inline int rtattr_ok(const struct rtattr *attr, size_t len) -{ - return RTA_OK(attr, len); -} - static inline size_t nlattr_get_len(const struct nlattr *attr) { return attr->nla_len;