trafgen: fix resource leaks
[netsniff-ng.git] / dissector_sll.c
blob10fd7d912fcf726568cba0b67da3e20aad3b2fd9
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Subject to the GPL, version 2.
4 */
6 #include <arpa/inet.h>
8 #include "protos.h"
9 #include "pcap_io.h"
10 #include "pkt_buff.h"
11 #include "dissector.h"
12 #include "dissector_sll.h"
13 #include "dissector_eth.h"
14 #include "dissector_netlink.h"
15 #include "lookup.h"
17 static char *pkt_type2str(uint8_t pkttype)
19 switch (pkttype) {
20 case PACKET_HOST:
21 return "host";
22 case PACKET_BROADCAST:
23 return "broadcast";
24 case PACKET_MULTICAST:
25 return "multicast";
26 case PACKET_OTHERHOST:
27 return "other host";
28 case PACKET_OUTGOING:
29 return "outgoing";
30 case PACKET_USER:
31 return "user";
32 case PACKET_KERNEL:
33 return "kernel";
36 return "Unknown";
39 static void sll_print_full(struct pkt_buff *pkt)
41 struct sockaddr_ll *sll = pkt->sll;
42 char addr_str[40] = {};
44 tprintf(" [ Linux \"cooked\"");
45 tprintf(" Pkt Type %d (%s)", sll->sll_pkttype,
46 pkt_type2str(sll->sll_pkttype));
47 tprintf(", If Type %d (%s)", sll->sll_hatype,
48 device_type2str(sll->sll_hatype));
49 tprintf(", Addr Len %d", sll->sll_halen);
50 tprintf(", Src (%s)", device_addr2str(sll->sll_addr, sll->sll_halen,
51 sll->sll_hatype, addr_str, sizeof(addr_str)));
52 tprintf(", Proto 0x%x", ntohs(sll->sll_protocol));
53 tprintf(" ]\n");
55 switch (pcap_devtype_to_linktype(sll->sll_hatype)) {
56 case LINKTYPE_EN10MB:
57 case ___constant_swab32(LINKTYPE_EN10MB):
58 pkt_set_dissector(pkt, &eth_lay2, ntohs(sll->sll_protocol));
59 break;
60 case LINKTYPE_NETLINK:
61 case ___constant_swab32(LINKTYPE_NETLINK):
62 pkt->dissector = dissector_get_netlink_entry_point();
63 break;
64 default:
65 tprintf(" [ Unknown protocol ]\n");
69 static void sll_print_less(struct pkt_buff *pkt)
71 struct sockaddr_ll *sll = pkt->sll;
72 char addr_str[40] = {};
74 tprintf(" Pkt Type %d (%s)", sll->sll_pkttype,
75 pkt_type2str(sll->sll_pkttype));
76 tprintf(", If Type %d (%s)", sll->sll_hatype,
77 device_type2str(sll->sll_hatype));
78 tprintf(", Addr Len %d", sll->sll_halen);
79 tprintf(", Src (%s)", device_addr2str(sll->sll_addr, sll->sll_halen,
80 sll->sll_hatype, addr_str, sizeof(addr_str)));
81 tprintf(", Proto 0x%x", ntohs(sll->sll_protocol));
84 struct protocol sll_ops = {
85 .key = 0,
86 .print_full = sll_print_full,
87 .print_less = sll_print_less,
90 struct protocol *dissector_get_sll_entry_point(void)
92 return &sll_ops;
95 struct protocol *dissector_get_sll_exit_point(void)
97 return &none_ops;
100 void dissector_init_sll(int fnttype)
102 dissector_set_print_type(&sll_ops, fnttype);
103 dissector_set_print_type(&none_ops, fnttype);
104 lookup_init(LT_OUI);
107 void dissector_cleanup_sll(void)
109 lookup_cleanup(LT_OUI);