diff --git a/monitor/main.c b/monitor/main.c index f88fd347..6dcb971f 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -163,6 +163,7 @@ static int process_pcap(struct pcap *pcap) while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) { uint16_t arphrd_type; uint16_t proto_type; + uint16_t pkt_type; if (len < 16) { printf("Too short packet\n"); @@ -172,22 +173,37 @@ static int process_pcap(struct pcap *pcap) if (len < real_len) printf("Packet truncated from %u\n", real_len); - arphrd_type = L_GET_UNALIGNED((const uint16_t *) (buf + 2)); + pkt_type = L_GET_UNALIGNED((const uint16_t *) buf); + pkt_type = L_BE16_TO_CPU(pkt_type); - if (L_BE16_TO_CPU(arphrd_type) != ARPHRD_NETLINK) { - printf("Unsupported ARPHRD %u\n", - L_BE16_TO_CPU(arphrd_type)); - continue; - } + arphrd_type = L_GET_UNALIGNED((const uint16_t *) (buf + 2)); + arphrd_type = L_BE16_TO_CPU(arphrd_type); proto_type = L_GET_UNALIGNED((const uint16_t *) (buf + 14)); + proto_type = L_BE16_TO_CPU(proto_type); - switch (L_BE16_TO_CPU(proto_type)) { - case NETLINK_ROUTE: - nlmon_print_rtnl(nlmon, &tv, buf, len); + switch (arphrd_type) { + case ARPHRD_ETHER: + switch (proto_type) { + case ETH_P_PAE: + nlmon_print_pae(nlmon, &tv, pkt_type, -1, + buf, len); + break; + } break; - case NETLINK_GENERIC: - nlmon_print_genl(nlmon, &tv, buf + 16, len - 16); + case ARPHRD_NETLINK: + switch (proto_type) { + case NETLINK_ROUTE: + nlmon_print_rtnl(nlmon, &tv, buf, len); + break; + case NETLINK_GENERIC: + nlmon_print_genl(nlmon, &tv, + buf + 16, len - 16); + break; + } + break; + default: + printf("Unsupported ARPHRD %u\n", arphrd_type); break; } } diff --git a/monitor/nlmon.c b/monitor/nlmon.c index 8185133b..264db450 100644 --- a/monitor/nlmon.c +++ b/monitor/nlmon.c @@ -1640,7 +1640,7 @@ static struct l_io *open_packet(const char *name) } void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv, - uint8_t type, uint32_t index, + uint8_t type, int index, const void *data, uint32_t size) { char str[16]; @@ -1649,7 +1649,8 @@ void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv, print_packet(tv, (type == PACKET_HOST) ? '>' : '<', COLOR_YELLOW, "PAE Packet", str, ""); - print_attr(0, "Interface Index: %u", index); + if (index >= 0) + print_attr(0, "Interface Index: %u", index); print_hexdump(0, data, size); } diff --git a/monitor/nlmon.h b/monitor/nlmon.h index 8ca15072..7ef0d5ee 100644 --- a/monitor/nlmon.h +++ b/monitor/nlmon.h @@ -35,5 +35,5 @@ void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv, const void *data, uint32_t size); void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv, - uint8_t type, uint32_t index, + uint8_t type, int index, const void *data, uint32_t size);