improving dissector_fuzz
[netsniff-ng.git] / src / proto_ethernet.h
blob34fdb26e4d07cb3c5e015e13e6366917be0d6c7a
1 /*
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.
6 */
8 #ifndef PROTO_ETHERNET_H
9 #define PROTO_ETHERNET_H
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <netinet/in.h>
14 #include <linux/if_ether.h>
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
18 #include "pkt_buff.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));
25 if (eth == NULL)
26 return;
28 src_mac = eth->h_source;
29 dst_mac = eth->h_dest;
30 tprintf(" [ Eth ");
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());
40 tprintf(" ]\n");
42 tprintf(" [ Vendor ");
43 tprintf("(%s => %s)",
44 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
45 src_mac[2]),
46 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
47 dst_mac[2]));
48 tprintf(" ]\n");
50 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
53 static inline void ethernet_hex_all(struct pkt_buff *pkt)
55 tprintf(" ");
56 hex(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));
64 if (eth == NULL)
65 return;
67 src_mac = eth->h_source;
68 dst_mac = eth->h_dest;
69 tprintf(" %s => %s ",
70 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
71 src_mac[2]),
72 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
73 dst_mac[2]));
74 tprintf("%s%s%s", colorize_start(bold),
75 lookup_ether_type(ntohs(eth->h_proto)), colorize_end());
77 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
80 struct protocol ethernet_ops = {
81 .key = 0,
82 .print_full = ethernet,
83 .print_less = ethernet_less,
86 #endif /* PROTO_ETHERNET_H */