From: Vadim Kochan <vadi...@gmail.com>

Print similar header fields in less mode as it is done in
full mode.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
---
 proto_nlmsg.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/proto_nlmsg.c b/proto_nlmsg.c
index e8706a2..6d24fef 100644
--- a/proto_nlmsg.c
+++ b/proto_nlmsg.c
@@ -133,16 +133,12 @@ static char *nlmsg_type2str(uint16_t proto, uint16_t 
type, char *buf, int len)
        return nl_nlmsgtype2str(type, buf, len);
 }
 
-static void nlmsg(struct pkt_buff *pkt)
+static void nlmsg_print_hdr(uint16_t proto, struct nlmsghdr *hdr)
 {
-       struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
        char type[32];
        char flags[128];
        char procname[PATH_MAX];
 
-       if (hdr == NULL)
-               return;
-
        /* Look up the process name if message is not coming from the kernel.
         *
         * Note that the port id is not necessarily equal to the PID of the
@@ -162,13 +158,12 @@ static void nlmsg(struct pkt_buff *pkt)
        } else
                snprintf(procname, sizeof(procname), "kernel");
 
-       tprintf(" [ NLMSG ");
-       tprintf("Family %d (%s%s%s), ", ntohs(pkt->proto), colorize_start(bold),
-               nlmsg_family2str(ntohs(pkt->proto)), colorize_end());
+       tprintf("Family %d (%s%s%s), ", ntohs(proto), colorize_start(bold),
+               nlmsg_family2str(ntohs(proto)), colorize_end());
        tprintf("Len %u, ", hdr->nlmsg_len);
        tprintf("Type 0x%.4x (%s%s%s), ", hdr->nlmsg_type,
                colorize_start(bold),
-               nlmsg_type2str(ntohs(pkt->proto), hdr->nlmsg_type, type,
+               nlmsg_type2str(ntohs(proto), hdr->nlmsg_type, type,
                        sizeof(type)), colorize_end());
        tprintf("Flags 0x%.4x (%s%s%s), ", hdr->nlmsg_flags,
                colorize_start(bold),
@@ -179,20 +174,29 @@ static void nlmsg(struct pkt_buff *pkt)
        if (procname[0])
                tprintf(" (%s%s%s)", colorize_start(bold), basename(procname),
                        colorize_end());
+}
+
+static void nlmsg(struct pkt_buff *pkt)
+{
+       struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
+
+       if (hdr == NULL)
+               return;
+
+       tprintf(" [ NLMSG ");
+       nlmsg_print_hdr(pkt->proto, hdr);
        tprintf(" ]\n");
 }
 
 static void nlmsg_less(struct pkt_buff *pkt)
 {
        struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
-       char type[32];
 
        if (hdr == NULL)
                return;
 
-       tprintf(" NLMSG %u (%s%s%s)", hdr->nlmsg_type, colorize_start(bold),
-               nl_nlmsgtype2str(hdr->nlmsg_type, type, sizeof(type)),
-               colorize_end());
+       tprintf(" NLMSG ");
+       nlmsg_print_hdr(pkt->proto, hdr);
 }
 
 struct protocol nlmsg_ops = {
-- 
2.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to