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 "proto_none.h"
18 #include "dissector_eth.h"
21 static inline void ethernet(struct pkt_buff
*pkt
)
23 uint8_t *src_mac
, *dst_mac
;
24 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
29 src_mac
= eth
->h_source
;
30 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, %s%s%s)",
39 ntohs(eth
->h_proto
), colorize_start(bold
),
40 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
43 tprintf(" [ Vendor ");
45 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
47 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
51 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
54 static inline void ethernet_hex_all(struct pkt_buff
*pkt
)
60 static inline void ethernet_less(struct pkt_buff
*pkt
)
62 uint8_t *src_mac
, *dst_mac
;
63 struct ethhdr
*eth
= (struct ethhdr
*) pkt_pull(pkt
, sizeof(*eth
));
68 src_mac
= eth
->h_source
;
69 dst_mac
= eth
->h_dest
;
71 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
73 lookup_vendor((dst_mac
[0] << 16) | (dst_mac
[1] << 8) |
75 tprintf("%s%s%s", colorize_start(bold
),
76 lookup_ether_type(ntohs(eth
->h_proto
)), colorize_end());
78 pkt_set_proto(pkt
, ð_lay2
, ntohs(eth
->h_proto
));
81 struct protocol ethernet_ops
= {
83 .print_full
= ethernet
,
84 .print_less
= ethernet_less
,
87 #endif /* PROTO_ETHERNET_H */