tprintf: fix va_list arg exhaustion
[netsniff-ng-old.git] / src / proto_ethernet.c
blob3eaa25e3720bc224c922ac1470b7238910f4e958
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 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;
29 tprintf(" [ Eth ");
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());
39 tprintf(" ]\n");
41 tprintf(" [ Vendor ");
42 tprintf("(%s => %s)",
43 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
44 src_mac[2]),
45 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
46 dst_mac[2]));
47 tprintf(" ]\n");
49 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
52 static void ethernet_less(struct pkt_buff *pkt)
54 uint8_t *src_mac, *dst_mac;
55 struct ethhdr *eth = (struct ethhdr *) pkt_pull(pkt, sizeof(*eth));
57 if (eth == NULL)
58 return;
60 src_mac = eth->h_source;
61 dst_mac = eth->h_dest;
62 tprintf(" %s => %s ",
63 lookup_vendor((src_mac[0] << 16) | (src_mac[1] << 8) |
64 src_mac[2]),
65 lookup_vendor((dst_mac[0] << 16) | (dst_mac[1] << 8) |
66 dst_mac[2]));
67 tprintf("%s%s%s", colorize_start(bold),
68 lookup_ether_type(ntohs(eth->h_proto)), colorize_end());
70 pkt_set_proto(pkt, &eth_lay2, ntohs(eth->h_proto));
73 struct protocol ethernet_ops = {
74 .key = 0,
75 .print_full = ethernet,
76 .print_less = ethernet_less,
79 EXPORT_SYMBOL(ethernet_ops);