From b3a9f17eb9c7a47e6c4aee3649179b2a54d17eca Mon Sep 17 00:00:00 2001 From: Ken-ichirou MATSUZAWA Date: Fri, 11 Sep 2015 16:58:44 +0900 Subject: netsniff-ng: nlmsg: mmaped packet check The size of mmaped netlink packet is equals to its frame size, so may be different from actual size. It can be checked by the next nlmsg len is 0 or not, and trim it in that case. Signed-off-by: Ken-ichirou MATSUZAWA Signed-off-by: Tobias Klauser --- proto_nlmsg.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/proto_nlmsg.c b/proto_nlmsg.c index 76253ca..b621728 100644 --- a/proto_nlmsg.c +++ b/proto_nlmsg.c @@ -751,18 +751,29 @@ static void nlmsg_print(uint16_t family, struct nlmsghdr *hdr) static void nlmsg(struct pkt_buff *pkt) { struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, NLMSG_HDRLEN); + unsigned int trim_len = pkt_len(pkt); while (hdr) { + trim_len -= hdr->nlmsg_len; nlmsg_print(ntohs(pkt->sll->sll_protocol), hdr); if (!pkt_pull(pkt, NLMSG_ALIGN(hdr->nlmsg_len) - NLMSG_HDRLEN)) break; hdr = (struct nlmsghdr *) pkt_pull(pkt, NLMSG_HDRLEN); - if (hdr && hdr->nlmsg_type != NLMSG_DONE && - (hdr->nlmsg_flags & NLM_F_MULTI)) + if (hdr == NULL) + break; + if (hdr->nlmsg_len == 0) + break; + + if (hdr->nlmsg_type != NLMSG_DONE && + (hdr->nlmsg_flags & NLM_F_MULTI)) tprintf("\n"); } + + /* mmaped packet? */ + if (hdr && hdr->nlmsg_len == 0) + pkt_trim(pkt, trim_len); } static void nlmsg_less(struct pkt_buff *pkt) -- cgit v1.2.3-54-g00ecf