On Mon, Apr 27, 2015 at 04:29:40PM +0300, Vadim Kochan wrote:
> From: Vadim Kochan <[email protected]>
> 
> Print nlmsg type name for rtnetlink messages
> 
> Signed-off-by: Vadim Kochan <[email protected]>
> ---
>  proto_nlmsg.c | 84 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 82 insertions(+), 2 deletions(-)
> 
> diff --git a/proto_nlmsg.c b/proto_nlmsg.c
> index b219867..c5ef9d5 100644
> --- a/proto_nlmsg.c
> +++ b/proto_nlmsg.c
> @@ -47,6 +47,86 @@ static const char *nl_proto2str(uint16_t proto)
>       }
>  }
>  
> +static char * rtnl_types2str[RTM_MAX] = {
> +     [RTM_NEWLINK] = "NEW LINK",
> +     [RTM_DELLINK] = "DEL LINK",
> +     [RTM_GETLINK] = "GET LINK",
> +     [RTM_SETLINK] = "SET LINK",
> +
> +     [RTM_NEWADDR] = "NEW ADDR",
> +     [RTM_DELADDR] = "DEL ADDR",
> +     [RTM_GETADDR] = "GET ADDR",
> +
> +     [RTM_NEWROUTE] = "NEW ROUTE",
> +     [RTM_DELROUTE] = "DEL ROUTE",
> +     [RTM_GETROUTE] = "GET ROUTE",
> +
> +     [RTM_NEWNEIGH] = "NEW NEIGH",
> +     [RTM_DELNEIGH] = "DEL NEIGH",
> +     [RTM_GETNEIGH] = "GET NEIGH",
> +
> +     [RTM_NEWRULE] = "NEW RULE",
> +     [RTM_DELRULE] = "DEL RULE",
> +     [RTM_GETRULE] = "GET RULE",
> +
> +     [RTM_NEWQDISC] = "NEW QDISC",
> +     [RTM_DELQDISC] = "DEL QDISC",
> +     [RTM_GETQDISC] = "GET QDISC",
> +
> +     [RTM_NEWTCLASS] = "NEW TCLASS",
> +     [RTM_DELTCLASS] = "DEL TCLASS",
> +     [RTM_GETTCLASS] = "GET TCLASS",
> +
> +     [RTM_NEWTFILTER] = "NEW TFILTER",
> +     [RTM_DELTFILTER] = "DEL TFILTER",
> +     [RTM_GETTFILTER] = "GET TFILTER",
> +
> +     [RTM_NEWACTION] = "NEW ACTION",
> +     [RTM_DELACTION] = "DEL ACTION",
> +     [RTM_GETACTION] = "GET ACTION",
> +
> +     [RTM_NEWPREFIX] = "NEW PREFIX",
> +
> +     [RTM_GETMULTICAST] = "GET MULTICAST",
> +
> +     [RTM_GETANYCAST] = "GET ANYCAST",
> +
> +     [RTM_NEWNEIGHTBL] = "NEW NEIGHTBL",
> +     [RTM_GETNEIGHTBL] = "GET NEIGHTBL",
> +     [RTM_SETNEIGHTBL] = "SET NEIGHTBL",
> +
> +     [RTM_NEWNDUSEROPT] = "NEW NDUSEROPT",
> +
> +     [RTM_NEWADDRLABEL] = "NEW ADDRLABEL",
> +     [RTM_DELADDRLABEL] = "DEL ADDRLABEL",
> +     [RTM_GETADDRLABEL] = "GET ADDRLABEL",
> +
> +     [RTM_GETDCB] = "GET DCB",
> +     [RTM_SETDCB] = "SET DCB",
> +
> +     [RTM_NEWNETCONF] = "NEW NETCONF",
> +     [RTM_GETNETCONF] = "GET NETCONF",
> +
> +     [RTM_NEWMDB] = "NEW MDB",
> +     [RTM_DELMDB] = "DEL MDB",
> +     [RTM_GETMDB] = "GET MDB",
> +};
> +
> +static char *nl_msgtype2str(uint16_t proto, uint16_t type, char *buf, int 
> len)
> +{
> +     char *name = NULL;
> +
> +     if (proto == NETLINK_ROUTE && type < RTM_MAX)
> +             name = rtnl_types2str[type];
> +
> +     if (name) {
> +             strncpy(buf, name, len);
> +             return buf;
> +     }
> +
> +     return nl_nlmsgtype2str(type, buf, len);
> +}
> +
>  static void nlmsg(struct pkt_buff *pkt)
>  {
>       struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
> @@ -82,8 +162,8 @@ static void nlmsg(struct pkt_buff *pkt)
>       tprintf("Len %u, ", hdr->nlmsg_len);
>       tprintf("Type 0x%.4x (%s%s%s), ", hdr->nlmsg_type,
>               colorize_start(bold),
> -             nl_nlmsgtype2str(hdr->nlmsg_type, type, sizeof(type)),
> -             colorize_end());
> +             nl_msgtype2str(ntohs(pkt->proto), 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)),
> -- 
> 2.3.1
> 

Ok, I will re-work this one to v2 with func renaming & make NETLINK_ROUTE type 
names more
understandable.

Sorry for the noise.

Regards,

-- 
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.

Reply via email to