2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
9 #include <netinet/in.h>
10 #include <linux/if_ether.h>
14 #include "dissector_eth.h"
18 static void ethernet(struct pkt_buff
*pkt
)
21 uint8_t *src_mac
, *dst_mac
;
22 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
27 src_mac
= eth
->h_source
;
28 dst_mac
= eth
->h_dest
;
31 tprintf("MAC (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x => ",
32 src_mac
[0], src_mac
[1], src_mac
[2],
33 src_mac
[3], src_mac
[4], src_mac
[5]);
34 tprintf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x), ",
35 dst_mac
[0], dst_mac
[1], dst_mac
[2],
36 dst_mac
[3], dst_mac
[4], dst_mac
[5]);
37 tprintf("Proto (0x%.4x", ntohs(eth
->h_proto
));
39 type
= lookup_ether_type(ntohs(eth
->h_proto
));
41 tprintf(", %s%s%s", colorize_start(bold
), type
, colorize_end());
44 tprintf(" [ Vendor ");
46 lookup_vendor_str((src_mac
[0] << 16) | (src_mac
[1] << 8) |
48 lookup_vendor_str((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
52 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
55 static void ethernet_less(struct pkt_buff
*pkt
)
57 uint8_t *src_mac
, *dst_mac
;
58 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
63 src_mac
= eth
->h_source
;
64 dst_mac
= eth
->h_dest
;
66 lookup_vendor_str((src_mac
[0] << 16) | (src_mac
[1] << 8) |
68 lookup_vendor_str((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
70 tprintf("%s%s%s", colorize_start(bold
),
71 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
73 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
76 struct protocol ethernet_ops
= {
78 .print_full
= ethernet
,
79 .print_less
= ethernet_less
,