On 2015-05-19 at 06:42:50 +0200, Vadim Kochan <[email protected]> wrote:
> From: Vadim Kochan <[email protected]>
>
> Dump RTnetlink interface related info with attributes.
>
> Signed-off-by: Vadim Kochan <[email protected]>
> ---
> netsniff-ng/Makefile | 2 +
> proto_nlmsg.c | 232
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 234 insertions(+)
>
> diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
> index 9fe2ffe..92990ff 100644
> --- a/netsniff-ng/Makefile
> +++ b/netsniff-ng/Makefile
> @@ -1,5 +1,6 @@
> netsniff-ng-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH)
> $(PKG_CONFIG) --libs libnl-3.0) \
> $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH)
> $(PKG_CONFIG) --libs libnl-genl-3.0) \
> + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH)
> $(PKG_CONFIG) --libs libnl-route-3.0) \
> -lpthread
>
> ifeq ($(CONFIG_LIBPCAP), 1)
> @@ -78,6 +79,7 @@ endif
>
> netsniff-ng-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH)
> $(PKG_CONFIG) --cflags libnl-3.0) \
> $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG)
> --cflags libnl-genl-3.0) \
> + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG)
> --cflags libnl-route-3.0) \
> -DNEED_TCPDUMP_LIKE_FILTER
>
> netsniff-ng-confs = ether.conf \
> diff --git a/proto_nlmsg.c b/proto_nlmsg.c
> index 1b0eed7..c482df1 100644
> --- a/proto_nlmsg.c
> +++ b/proto_nlmsg.c
> @@ -9,6 +9,9 @@
> #include <limits.h>
> #include <libgen.h>
> #include <netlink/msg.h>
> +#include <netlink/route/link.h>
> +#include <linux/if_arp.h>
> +#include <arpa/inet.h>
>
> #include "pkt_buff.h"
> #include "proto.h"
> @@ -120,6 +123,114 @@ static const char *nlmsg_rtnl_type2str(uint16_t type)
> }
> }
>
> +static char *if_type2str(uint16_t type)
> +{
> + switch (type) {
> + case ARPHRD_ETHER: return "ether";
> + case ARPHRD_EETHER: return "eether";
> + case ARPHRD_AX25: return "ax25";
> + case ARPHRD_PRONET: return "pronet";
> + case ARPHRD_CHAOS: return "chaos";
> + case ARPHRD_IEEE802: return "ieee802";
> + case ARPHRD_ARCNET: return "arcnet";
> + case ARPHRD_APPLETLK: return "appletlk";
> + case ARPHRD_DLCI: return "dlci";
> + case ARPHRD_ATM: return "atm";
> + case ARPHRD_METRICOM: return "metricom";
> + case ARPHRD_IEEE1394: return "ieee1394";
> + case ARPHRD_INFINIBAND: return "infiniband";
> + case ARPHRD_SLIP: return "slip";
> + case ARPHRD_CSLIP: return "cslip";
> + case ARPHRD_SLIP6: return "slip6";
> + case ARPHRD_CSLIP6: return "cslip6";
> + case ARPHRD_RSRVD: return "RSRVD";
> + case ARPHRD_ADAPT: return "adapt";
> + case ARPHRD_ROSE: return "rose";
> + case ARPHRD_X25: return "x25";
> + case ARPHRD_HWX25: return "hwx25";
> + case ARPHRD_CAN: return "can";
> + case ARPHRD_PPP: return "ppp";
> + case ARPHRD_HDLC: return "hdlc";
> + case ARPHRD_LAPB: return "lapb";
> + case ARPHRD_DDCMP: return "ddcmp";
> + case ARPHRD_RAWHDLC: return "rawhdlc";
> + case ARPHRD_TUNNEL: return "tunnel";
> + case ARPHRD_TUNNEL6: return "tunnel6";
> + case ARPHRD_FRAD: return "frad";
> + case ARPHRD_SKIP: return "skip";
> + case ARPHRD_LOOPBACK: return "loopback";
> + case ARPHRD_LOCALTLK: return "localtlk";
> + case ARPHRD_FDDI: return "fddi";
> + case ARPHRD_BIF: return "bif";
> + case ARPHRD_SIT: return "sit";
> + case ARPHRD_IPDDP: return "ipddp";
> + case ARPHRD_IPGRE: return "ipgre";
> + case ARPHRD_PIMREG: return "pimreg";
> + case ARPHRD_HIPPI: return "hippi";
> + case ARPHRD_ASH: return "ash";
> + case ARPHRD_ECONET: return "econet";
> + case ARPHRD_IRDA: return "irda";
> + case ARPHRD_FCPP: return "fcpp";
> + case ARPHRD_FCAL: return "fcal";
> + case ARPHRD_FCPL: return "fcpl";
> + case ARPHRD_FCFABRIC: return "fcfb0";
> + case ARPHRD_FCFABRIC + 1: return "fcfb1";
> + case ARPHRD_FCFABRIC + 2: return "fcfb2";
> + case ARPHRD_FCFABRIC + 3: return "fcfb3";
> + case ARPHRD_FCFABRIC + 4: return "fcfb4";
> + case ARPHRD_FCFABRIC + 5: return "fcfb5";
> + case ARPHRD_FCFABRIC + 6: return "fcfb6";
> + case ARPHRD_FCFABRIC + 7: return "fcfb7";
> + case ARPHRD_FCFABRIC + 8: return "fcfb8";
> + case ARPHRD_FCFABRIC + 9: return "fcfb9";
> + case ARPHRD_FCFABRIC + 10: return "fcfb10";
> + case ARPHRD_FCFABRIC + 11: return "fcfb11";
> + case ARPHRD_FCFABRIC + 12: return "fcfb12";
> + case ARPHRD_IEEE802_TR: return "ieee802_tr";
> + case ARPHRD_IEEE80211: return "ieee80211";
> + case ARPHRD_IEEE80211_PRISM: return "ieee80211_prism";
> + case ARPHRD_IEEE80211_RADIOTAP: return "ieee80211_radiotap";
> + case ARPHRD_IEEE802154: return "ieee802154";
> + case ARPHRD_PHONET: return "phonet";
> + case ARPHRD_PHONET_PIPE: return "phonet_pipe";
> + case ARPHRD_CAIF: return "caif";
> + case ARPHRD_IP6GRE: return "ip6gre";
> + case ARPHRD_NETLINK: return "netlink";
> + case ARPHRD_NONE: return "none";
> + case ARPHRD_VOID: return "void";
> +
> + default: return "Unknown";
> + }
> +}
Please use nl_llproto2str() instead of reimplementing it (currently some
types are missing but I just sent a patch adding them to libnl).
> +
> +static const char *if_addr2str(const unsigned char *addr, int alen, int type,
> + char *buf, int blen)
> +{
> + int i;
> + int l;
> +
> + if (alen == 4 &&
> + (type == ARPHRD_TUNNEL || type == ARPHRD_SIT || type ==
> ARPHRD_IPGRE)) {
> + return inet_ntop(AF_INET, addr, buf, blen);
> + }
> + if (alen == 16 && type == ARPHRD_TUNNEL6) {
> + return inet_ntop(AF_INET6, addr, buf, blen);
> + }
> + l = 0;
> + for (i=0; i<alen; i++) {
> + if (i==0) {
> + snprintf(buf+l, blen, "%02x", addr[i]);
> + blen -= 2;
> + l += 2;
> + } else {
> + snprintf(buf+l, blen, ":%02x", addr[i]);
> + blen -= 3;
> + l += 3;
> + }
> + }
> + return buf;
> +}
This is ll_addr_n2a from iproute2, isn't about it? I'd suggest to keep the
name intact and add a short comment about where you took it from.
> +
> static char *nlmsg_type2str(uint16_t proto, uint16_t type, char *buf, int
> len)
> {
> if (proto == NETLINK_ROUTE && type < RTM_MAX) {
> @@ -133,6 +244,124 @@ static char *nlmsg_type2str(uint16_t proto, uint16_t
> type, char *buf, int len)
> return nl_nlmsgtype2str(type, buf, len);
> }
>
> +static void rtnl_print_ifinfo(struct nlmsghdr *hdr)
> +{
> + struct ifinfomsg *ifi = NLMSG_DATA(hdr);
> + struct rtattr *attr = IFLA_RTA(ifi);
> + uint32_t attrs_len = IFLA_PAYLOAD(hdr);
> + char flags[256];
> + char if_addr[64] = {};
> + char *af_link = "Unknown";
> +
> + if (ifi->ifi_family == 0)
Please compare against AF_UNSPEC instead of 0.
--
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.