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.
8 #ifndef PROTO_ETHERNET_H
9 #define PROTO_ETHERNET_H
13 #include <netinet/in.h>
14 #include <linux/if_ether.h>
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
20 static inline 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
;
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, %s%s%s)",
38 ntohs(eth
->h_proto
), colorize_start(bold
),
39 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
42 tprintf(" [ Vendor ");
44 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
46 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
50 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
53 static inline void ethernet_hex_all(struct pkt_buff
*pkt
)
59 static inline void ethernet_less(struct pkt_buff
*pkt
)
61 uint8_t *src_mac
, *dst_mac
;
62 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
67 src_mac
= eth
->h_source
;
68 dst_mac
= eth
->h_dest
;
70 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
72 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
74 tprintf("%s%s%s", colorize_start(bold
),
75 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
77 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
80 struct protocol ethernet_ops
= {
82 .print_full
= ethernet
,
83 .print_less
= ethernet_less
,
86 #endif /* PROTO_ETHERNET_H */