build: Only use tput if $TERM is defined
[netsniff-ng.git] / dissector_eth.c
blob60d84293e095821f12a15e89b346fba51b18506d
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #include <stdint.h>
9 #include "hash.h"
10 #include "oui.h"
11 #include "proto.h"
12 #include "protos.h"
13 #include "dissector.h"
14 #include "dissector_eth.h"
15 #include "lookup.h"
16 #include "xmalloc.h"
18 struct hash_table eth_lay2;
19 struct hash_table eth_lay3;
21 static inline void dissector_init_entry(int type)
23 dissector_set_print_type(&ethernet_ops, type);
26 static inline void dissector_init_exit(int type)
28 dissector_set_print_type(&none_ops, type);
31 static void dissector_init_layer_2(int type)
33 init_hash(&eth_lay2);
34 INSERT_HASH_PROTOS(arp_ops, eth_lay2);
35 INSERT_HASH_PROTOS(lldp_ops, eth_lay2);
36 INSERT_HASH_PROTOS(vlan_ops, eth_lay2);
37 INSERT_HASH_PROTOS(ipv4_ops, eth_lay2);
38 INSERT_HASH_PROTOS(ipv6_ops, eth_lay2);
39 INSERT_HASH_PROTOS(QinQ_ops, eth_lay2);
40 INSERT_HASH_PROTOS(mpls_uc_ops, eth_lay2);
41 for_each_hash_int(&eth_lay2, dissector_set_print_type, type);
44 static void dissector_init_layer_3(int type)
46 init_hash(&eth_lay3);
47 INSERT_HASH_PROTOS(icmpv4_ops, eth_lay3);
48 INSERT_HASH_PROTOS(icmpv6_ops, eth_lay3);
49 INSERT_HASH_PROTOS(igmp_ops, eth_lay3);
50 INSERT_HASH_PROTOS(ip_auth_ops, eth_lay3);
51 INSERT_HASH_PROTOS(ip_esp_ops, eth_lay3);
52 INSERT_HASH_PROTOS(ipv6_dest_opts_ops, eth_lay3);
53 INSERT_HASH_PROTOS(ipv6_fragm_ops, eth_lay3);
54 INSERT_HASH_PROTOS(ipv6_hop_by_hop_ops, eth_lay3);
55 INSERT_HASH_PROTOS(ipv6_in_ipv4_ops, eth_lay3);
56 INSERT_HASH_PROTOS(ipv6_mobility_ops, eth_lay3);
57 INSERT_HASH_PROTOS(ipv6_no_next_header_ops, eth_lay3);
58 INSERT_HASH_PROTOS(ipv6_routing_ops, eth_lay3);
59 INSERT_HASH_PROTOS(tcp_ops, eth_lay3);
60 INSERT_HASH_PROTOS(udp_ops, eth_lay3);
61 for_each_hash_int(&eth_lay3, dissector_set_print_type, type);
64 void dissector_init_ethernet(int fnttype)
66 dissector_init_entry(fnttype);
67 dissector_init_layer_2(fnttype);
68 dissector_init_layer_3(fnttype);
69 dissector_init_exit(fnttype);
71 dissector_init_oui();
73 lookup_init_ports(PORTS_UDP);
74 lookup_init_ports(PORTS_TCP);
75 lookup_init_ports(PORTS_ETHER);
78 void dissector_cleanup_ethernet(void)
80 free_hash(&eth_lay2);
81 free_hash(&eth_lay3);
83 lookup_cleanup_ports(PORTS_ETHER);
84 lookup_cleanup_ports(PORTS_TCP);
85 lookup_cleanup_ports(PORTS_UDP);
87 dissector_cleanup_oui();