2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2014 Tobias Klauser
5 * Subject to the GPL, version 2.
10 #include <netinet/in.h>
11 #include <linux/if_ether.h>
14 #include "dissector_eth.h"
18 static inline bool is_multicast_ether_addr(const uint8_t *mac
)
23 static inline bool is_broadcast_ether_addr(const uint8_t *mac
)
25 return (mac
[0] & mac
[1] & mac
[2] & mac
[3] & mac
[4] & mac
[5]) == 0xff;
28 static inline bool is_local_ether_addr(const u8
*mac
)
33 static const char *ether_lookup_addr(const uint8_t *mac
)
35 if (is_multicast_ether_addr(mac
)) {
36 if (is_broadcast_ether_addr(mac
))
40 } else if (is_local_ether_addr(mac
)) {
41 return "Locally Administered";
44 /* found no matching address, so look up the vendor from OUI */
45 return lookup_vendor_str((mac
[0] << 16) | (mac
[1] << 8) | mac
[2]);
48 static void ethernet(struct pkt_buff
*pkt
)
51 uint8_t *src_mac
, *dst_mac
;
52 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
57 src_mac
= eth
->h_source
;
58 dst_mac
= eth
->h_dest
;
61 tprintf("MAC (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x => ",
62 src_mac
[0], src_mac
[1], src_mac
[2],
63 src_mac
[3], src_mac
[4], src_mac
[5]);
64 tprintf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x), ",
65 dst_mac
[0], dst_mac
[1], dst_mac
[2],
66 dst_mac
[3], dst_mac
[4], dst_mac
[5]);
67 tprintf("Proto (0x%.4x", ntohs(eth
->h_proto
));
69 type
= lookup_ether_type(ntohs(eth
->h_proto
));
71 tprintf(", %s%s%s", colorize_start(bold
), type
, colorize_end());
74 tprintf(" [ Vendor ");
75 tprintf("(%s => %s)", ether_lookup_addr(src_mac
), ether_lookup_addr(dst_mac
));
78 pkt_set_dissector(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
81 static void ethernet_less(struct pkt_buff
*pkt
)
83 uint8_t *src_mac
, *dst_mac
;
84 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
89 src_mac
= eth
->h_source
;
90 dst_mac
= eth
->h_dest
;
91 tprintf(" %s => %s ", ether_lookup_addr(src_mac
),
92 ether_lookup_addr(dst_mac
));
93 tprintf("%s%s%s", colorize_start(bold
),
94 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
96 pkt_set_dissector(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
99 struct protocol ethernet_ops
= {
101 .print_full
= ethernet
,
102 .print_less
= ethernet_less
,