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
)
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
;
30 tprintf("MAC (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x => ",
31 src_mac
[0], src_mac
[1], src_mac
[2],
32 src_mac
[3], src_mac
[4], src_mac
[5]);
33 tprintf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x), ",
34 dst_mac
[0], dst_mac
[1], dst_mac
[2],
35 dst_mac
[3], dst_mac
[4], dst_mac
[5]);
36 tprintf("Proto (0x%.4x, %s%s%s)",
37 ntohs(eth
->h_proto
), colorize_start(bold
),
38 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
41 tprintf(" [ Vendor ");
43 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
45 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
49 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
52 static void ethernet_less(struct pkt_buff
*pkt
)
54 uint8_t *src_mac
, *dst_mac
;
55 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
60 src_mac
= eth
->h_source
;
61 dst_mac
= eth
->h_dest
;
63 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
65 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
67 tprintf("%s%s%s", colorize_start(bold
),
68 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
70 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
73 struct protocol ethernet_ops
= {
75 .print_full
= ethernet
,
76 .print_less
= ethernet_less
,
79 EXPORT_SYMBOL(ethernet_ops
);