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.
13 #include <netinet/in.h>
14 #include <linux/if_ether.h>
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
19 static inline void ethernet(uint8_t *packet
, size_t len
)
21 uint8_t *src_mac
, *dst_mac
;
22 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
24 if (len
< sizeof(struct ethhdr
))
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) |
50 static inline void ethernet_hex_all(uint8_t *packet
, size_t len
)
56 static inline void ethernet_less(uint8_t *packet
, size_t len
)
58 uint8_t *src_mac
, *dst_mac
;
59 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
61 if (len
< sizeof(struct ethhdr
))
63 src_mac
= eth
->h_source
;
64 dst_mac
= eth
->h_dest
;
66 lookup_vendor((src_mac
[0] << 16) | (src_mac
[1] << 8) |
68 lookup_vendor((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());
74 static inline void ethernet_next(uint8_t *packet
, size_t len
,
75 struct hash_table
**table
,
76 unsigned int *key
, size_t *off
)
78 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
80 if (len
< sizeof(struct ethhdr
))
83 (*off
) = sizeof(struct ethhdr
);
84 (*key
) = ntohs(eth
->h_proto
);
88 struct protocol ethernet_ops
= {
90 .offset
= sizeof(struct ethhdr
),
91 .print_full
= ethernet
,
92 .print_less
= ethernet_less
,
93 .print_pay_ascii
= empty
,
94 .print_pay_hex
= empty
,
95 .print_pay_none
= ethernet
,
96 .print_all_hex
= ethernet_hex_all
,
97 .proto_next
= ethernet_next
,
100 #endif /* ETHERNET_H */