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;