summaryrefslogtreecommitdiff
path: root/proto_nlmsg.c
diff options
context:
space:
mode:
authorKen-ichirou MATSUZAWA <chamaken@gmail.com>2015-09-11 16:58:44 +0900
committerTobias Klauser <tklauser@distanz.ch>2015-09-15 10:49:56 +0200
commitb3a9f17eb9c7a47e6c4aee3649179b2a54d17eca (patch)
tree168b64bdf71b17bc1f612ce3ea666dce4253ade5 /proto_nlmsg.c
parent67728607d5144cd36d056c4289c7e53f9113329a (diff)
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 <chamas@h4.dion.ne.jp> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'proto_nlmsg.c')
-rw-r--r--proto_nlmsg.c15
1 files 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)