On 2015-05-13 at 16:07:06 +0200, Vadim Kochan <[email protected]> wrote:
> From: Vadim Kochan <[email protected]>
>
> Pull & print more Netlink messages from one packet
> which can be sent with MULTI flag.
>
> Signed-off-by: Vadim Kochan <[email protected]>
> ---
> proto_nlmsg.c | 52 +++++++++++++++++++++++++++++++++++++---------------
> 1 file changed, 37 insertions(+), 15 deletions(-)
>
> diff --git a/proto_nlmsg.c b/proto_nlmsg.c
> index 136cec6..290fbf6 100644
> --- a/proto_nlmsg.c
> +++ b/proto_nlmsg.c
> @@ -133,16 +133,27 @@ 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_each(struct pkt_buff *pkt,
> + void (*do_print)(uint16_t family, struct nlmsghdr *hdr))
> +{
> + struct nlmsghdr *hdr = (struct nlmsghdr *)pkt_pull(pkt, sizeof(*hdr));
> +
> + while (hdr) {
> + do_print(ntohs(pkt->proto), hdr);
> +
> + if (!pkt_pull(pkt, NLMSG_PAYLOAD(hdr, 0)))
> + break;
> +
> + hdr = (struct nlmsghdr *)pkt_pull(pkt, sizeof(*hdr));
> + }
> +}
Why have the print function as a callback? Just inline this entire
function in nlmsg()
> +
> +static void nlmsg_print(uint16_t family, 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
> @@ -163,13 +174,15 @@ static void nlmsg(struct pkt_buff *pkt)
> 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), ", family,
> + colorize_start(bold),
> + nlmsg_family2str(family),
> + 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,
> - sizeof(type)), colorize_end());
> + nlmsg_type2str(family, hdr->nlmsg_type, type, sizeof(type)),
> + colorize_end());
> tprintf("Flags 0x%.4x (%s%s%s), ", hdr->nlmsg_flags,
> colorize_start(bold),
> nl_nlmsg_flags2str(hdr->nlmsg_flags, flags, sizeof(flags)),
> @@ -182,19 +195,28 @@ static void nlmsg(struct pkt_buff *pkt)
> tprintf(" ]\n");
> }
>
> +static void nlmsg(struct pkt_buff *pkt)
> +{
> + nlmsg_print_each(pkt, nlmsg_print);
> +}
> +
> static void nlmsg_less(struct pkt_buff *pkt)
> {
> - struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
> + struct nlmsghdr *hdr = (struct nlmsghdr *)pkt_pull(pkt, sizeof(*hdr));
Please leave the casting style intact, the above form is consistent with
(most of) the rest of the code base.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.