bpf: indent one space for better visibility
[netsniff-ng.git] / src / proto_ethernet.h
blob8c9c33fe58d0f8487281a13b12e49c8c9fa5e40e
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 "proto_none.h"
18 #include "dissector_eth.h"
19 #include "pkt_buff.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));
26 if (eth == NULL)
27 return;
29 src_mac = eth->h_source;
30 dst_mac = eth->h_dest;
31 tprintf(" [ Eth ");
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());
41 tprintf(" ]\n");
43 tprintf(" [ Vendor ");
44 tprintf("(%s => %s)",
45 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
46 src_mac[2]),
47 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
48 dst_mac[2]));
49 tprintf(" ]\n");
51 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
54 static inline void ethernet_hex_all(struct pkt_buff *pkt)
56 tprintf(" ");
57 hex(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));
65 if (eth == NULL)
66 return;
68 src_mac = eth->h_source;
69 dst_mac = eth->h_dest;
70 tprintf(" %s => %s ",
71 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
72 src_mac[2]),
73 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
74 dst_mac[2]));
75 tprintf("%s%s%s", colorize_start(bold),
76 lookup_ether_type(ntohs(eth->h_proto)), colorize_end());
78 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
81 struct protocol ethernet_ops = {
82 .key = 0,
83 .print_full = ethernet,
84 .print_less = ethernet_less,
87 #endif /* PROTO_ETHERNET_H */