flowtop: Simplify assignment of flow_entry->is_visible
[netsniff-ng.git] / dissector_sll.c
blobe2e5bfad51d9b43d2eb95b951269f5c4d053e4e5
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Subject to the GPL, version 2.
4 */
6 #include "oui.h"
7 #include "protos.h"
8 #include "pcap_io.h"
9 #include "pkt_buff.h"
10 #include "dissector.h"
11 #include "dissector_sll.h"
12 #include "dissector_eth.h"
14 static char *pkt_type2str(uint8_t pkttype)
16 switch (pkttype) {
17 case PACKET_HOST:
18 return "host";
19 case PACKET_BROADCAST:
20 return "broadcast";
21 case PACKET_MULTICAST:
22 return "multicast";
23 case PACKET_OTHERHOST:
24 return "other host";
25 case PACKET_OUTGOING:
26 return "outgoing";
27 case PACKET_USER:
28 return "user";
29 case PACKET_KERNEL:
30 return "kernel";
33 return "Unknown";
36 static void sll_print_full(struct pkt_buff *pkt)
38 struct sockaddr_ll *sll = pkt->sll;
39 char addr_str[40] = {};
41 if (!pkt || !sll)
42 return;
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 = &nlmsg_ops;
63 break;
64 default:
65 tprintf(" [ Uknown 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 if (!pkt || !sll)
75 return;
77 tprintf(" Pkt Type %d (%s)", sll->sll_pkttype,
78 pkt_type2str(sll->sll_pkttype));
79 tprintf(", If Type %d (%s)", sll->sll_hatype,
80 device_type2str(sll->sll_hatype));
81 tprintf(", Addr Len %d", sll->sll_halen);
82 tprintf(", Src (%s)", device_addr2str(sll->sll_addr, sll->sll_halen,
83 sll->sll_hatype, addr_str, sizeof(addr_str)));
84 tprintf(", Proto 0x%x", ntohs(sll->sll_protocol));
87 struct protocol sll_ops = {
88 .key = 0,
89 .print_full = sll_print_full,
90 .print_less = sll_print_less,
93 struct protocol *dissector_get_sll_entry_point(void)
95 return &sll_ops;
98 struct protocol *dissector_get_sll_exit_point(void)
100 return &none_ops;
103 void dissector_init_sll(int fnttype)
105 dissector_set_print_type(&sll_ops, fnttype);
106 dissector_set_print_type(&none_ops, fnttype);
107 dissector_init_oui();
110 void dissector_cleanup_sll(void)
112 dissector_cleanup_oui();