2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
10 #include <netinet/in.h>
11 #include <linux/if_ether.h>
15 #include "dissector_eth.h"
19 static void ethernet(struct pkt_buff
*pkt
)
22 uint8_t *src_mac
, *dst_mac
;
23 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
28 src_mac
= eth
->h_source
;
29 dst_mac
= eth
->h_dest
;
32 tprintf("MAC (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x => ",
33 src_mac
[0], src_mac
[1], src_mac
[2],
34 src_mac
[3], src_mac
[4], src_mac
[5]);
35 tprintf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x), ",
36 dst_mac
[0], dst_mac
[1], dst_mac
[2],
37 dst_mac
[3], dst_mac
[4], dst_mac
[5]);
38 tprintf("Proto (0x%.4x", ntohs(eth
->h_proto
));
40 type
= lookup_ether_type(ntohs(eth
->h_proto
));
42 tprintf(", %s%s%s", colorize_start(bold
), type
, colorize_end());
45 tprintf(" [ Vendor ");
47 lookup_vendor_str((src_mac
[0] << 16) | (src_mac
[1] << 8) |
49 lookup_vendor_str((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
53 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
56 static void ethernet_less(struct pkt_buff
*pkt
)
58 uint8_t *src_mac
, *dst_mac
;
59 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
64 src_mac
= eth
->h_source
;
65 dst_mac
= eth
->h_dest
;
67 lookup_vendor_str((src_mac
[0] << 16) | (src_mac
[1] << 8) |
69 lookup_vendor_str((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
71 tprintf("%s%s%s", colorize_start(bold
),
72 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
74 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
77 struct protocol ethernet_ops
= {
79 .print_full
= ethernet
,
80 .print_less
= ethernet_less
,