oui: remove unneeded assignment
[netsniff-ng.git] / proto_ethernet.c
blob94415e049f4d23739aff95748c6c34febf1974d7
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 #include <stdio.h>
9 #include <stdint.h>
10 #include <netinet/in.h>
11 #include <linux/if_ether.h>
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_eth.h"
16 #include "pkt_buff.h"
17 #include "oui.h"
19 static void ethernet(struct pkt_buff *pkt)
21 char *type;
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;
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", ntohs(eth->h_proto));
40 type = lookup_ether_type(ntohs(eth->h_proto));
41 if (type)
42 tprintf(", %s%s%s", colorize_start(bold), type, colorize_end());
44 tprintf(") ]\n");
45 tprintf(" [ Vendor ");
46 tprintf("(%s => %s)",
47 lookup_vendor_str((src_mac[0] << 16) | (src_mac[1] << 8) |
48 src_mac[2]),
49 lookup_vendor_str((dst_mac[0] << 16) | (dst_mac[1] << 8) |
50 dst_mac[2]));
51 tprintf(" ]\n");
53 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
56 static void ethernet_less(struct pkt_buff *pkt)
58 uint8_t *src_mac, *dst_mac;
59 struct ethhdr *eth = (struct ethhdr *) pkt_pull(pkt, sizeof(*eth));
61 if (eth == NULL)
62 return;
64 src_mac = eth->h_source;
65 dst_mac = eth->h_dest;
66 tprintf(" %s => %s ",
67 lookup_vendor_str((src_mac[0] << 16) | (src_mac[1] << 8) |
68 src_mac[2]),
69 lookup_vendor_str((dst_mac[0] << 16) | (dst_mac[1] << 8) |
70 dst_mac[2]));
71 tprintf("%s%s%s", colorize_start(bold),
72 lookup_ether_type(ntohs(eth->h_proto)), colorize_end());
74 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
77 struct protocol ethernet_ops = {
78 .key = 0,
79 .print_full = ethernet,
80 .print_less = ethernet_less,