]> mj.ucw.cz Git - netgrind.git/blob - netgrind/link.c
TODO: A note on IPv6
[netgrind.git] / netgrind / link.c
1 /*
2  *      Netgrind -- Link Layer Analyser
3  *
4  *      (c) 2003 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "netgrind/pkt.h"
12 #include "netgrind/netgrind.h"
13
14 #include <stdio.h>
15 #include <netinet/in.h>
16 #include <net/ethernet.h>
17
18 struct pkt_stats stat_link_dwarf, stat_link_in, stat_link_unknown, stat_link_arp;
19
20 void link_eth_got_packet(struct pkt *p)
21 {
22   struct ether_header *eth;
23   uns etype;
24
25   pkt_account(&stat_link_in, p);
26   if (!(eth = pkt_pop(p, sizeof(*eth))))
27     {
28       pkt_account(&stat_link_dwarf, p);
29       return;
30     }
31   etype = ntohs(eth->ether_type);
32   switch (etype)
33     {
34     case ETHERTYPE_IP:
35       ip_got_packet(p);
36       break;
37     case ETHERTYPE_ARP:
38       pkt_account(&stat_link_arp, p);
39       pkt_free(p);
40       break;
41     default:
42       // printf("Unknown ethertype: %04x\n", etype);
43       pkt_account(&stat_link_unknown, p);
44       pkt_free(p);
45     }
46 }