configure: Improve check for libnl/libnl-genl
[netsniff-ng.git] / proto_ethernet.c
blob99c9d6c1e1dce3e80052207cdcb90fd5c27afd6e
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <netinet/in.h>
10 #include <linux/if_ether.h>
12 #include "proto.h"
13 #include "protos.h"
14 #include "dissector_eth.h"
15 #include "pkt_buff.h"
16 #include "oui.h"
18 static void ethernet(struct pkt_buff *pkt)
20 char *type;
21 uint8_t *src_mac, *dst_mac;
22 struct ethhdr *eth = (struct ethhdr *) pkt_pull(pkt, sizeof(*eth));
24 if (eth == NULL)
25 return;
27 src_mac = eth->h_source;
28 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", ntohs(eth->h_proto));
39 type = lookup_ether_type(ntohs(eth->h_proto));
40 if (type)
41 tprintf(", %s%s%s", colorize_start(bold), type, colorize_end());
43 tprintf(") ]\n");
44 tprintf(" [ Vendor ");
45 tprintf("(%s => %s)",
46 lookup_vendor_str((src_mac[0] << 16) | (src_mac[1] << 8) |
47 src_mac[2]),
48 lookup_vendor_str((dst_mac[0] << 16) | (dst_mac[1] << 8) |
49 dst_mac[2]));
50 tprintf(" ]\n");
52 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
55 static void ethernet_less(struct pkt_buff *pkt)
57 uint8_t *src_mac, *dst_mac;
58 struct ethhdr *eth = (struct ethhdr *) pkt_pull(pkt, sizeof(*eth));
60 if (eth == NULL)
61 return;
63 src_mac = eth->h_source;
64 dst_mac = eth->h_dest;
65 tprintf(" %s => %s ",
66 lookup_vendor_str((src_mac[0] << 16) | (src_mac[1] << 8) |
67 src_mac[2]),
68 lookup_vendor_str((dst_mac[0] << 16) | (dst_mac[1] << 8) |
69 dst_mac[2]));
70 tprintf("%s%s%s", colorize_start(bold),
71 lookup_ether_type(ntohs(eth->h_proto)), colorize_end());
73 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
76 struct protocol ethernet_ops = {
77 .key = 0,
78 .print_full = ethernet,
79 .print_less = ethernet_less,