1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | /* |
---|
27 | * Linux SLL Decoder |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #include "config.h" |
---|
32 | //#include "libtrace_int.h" |
---|
33 | #include <sys/types.h> |
---|
34 | #include <netinet/in.h> |
---|
35 | #include <stdio.h> |
---|
36 | #include "libpacketdump.h" |
---|
37 | #include "libtrace.h" |
---|
38 | |
---|
39 | #include "libtrace_arphrd.h" |
---|
40 | |
---|
41 | /* Copied this here because this isn't currently part of our external API - |
---|
42 | * maybe we need to think about doing that? */ |
---|
43 | static libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd) { |
---|
44 | switch(arphrd) { |
---|
45 | case LIBTRACE_ARPHRD_ETHER: return TRACE_TYPE_ETH; |
---|
46 | case LIBTRACE_ARPHRD_EETHER: return TRACE_TYPE_ETH; |
---|
47 | case LIBTRACE_ARPHRD_IEEE80211: return TRACE_TYPE_80211; |
---|
48 | case LIBTRACE_ARPHRD_IEEE80211_RADIOTAP: return TRACE_TYPE_80211_RADIO; |
---|
49 | case LIBTRACE_ARPHRD_PPP: return TRACE_TYPE_NONE; |
---|
50 | case LIBTRACE_ARPHRD_LOOPBACK: return TRACE_TYPE_NONE; |
---|
51 | case LIBTRACE_ARPHRD_NONE: return TRACE_TYPE_NONE; |
---|
52 | } |
---|
53 | printf("Unknown ARPHRD: %u\n", arphrd); |
---|
54 | return ~0U; |
---|
55 | } |
---|
56 | |
---|
57 | DLLEXPORT void decode(int link_type ,const char *pkt,unsigned len) |
---|
58 | { |
---|
59 | libtrace_sll_header_t *sll = (libtrace_sll_header_t *) pkt; |
---|
60 | libtrace_linktype_t linktype = link_type; |
---|
61 | void *ret; |
---|
62 | |
---|
63 | if (len < sizeof(*sll)) { |
---|
64 | printf(" Linux SLL: Truncated (len = %u)\n", len); |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | printf(" Linux SLL: Packet Type = "); |
---|
69 | switch(ntohs(sll->pkttype)) { |
---|
70 | case TRACE_SLL_HOST: printf("HOST\n"); break; |
---|
71 | case TRACE_SLL_BROADCAST: printf("BROADCAST\n"); break; |
---|
72 | case TRACE_SLL_MULTICAST: printf("MULTICAST\n"); break; |
---|
73 | case TRACE_SLL_OTHERHOST: printf("OTHERHOST\n"); break; |
---|
74 | case TRACE_SLL_OUTGOING: printf("OUTGOING\n"); break; |
---|
75 | default: printf("Unknown (0x%04x)\n", ntohs(sll->pkttype)); |
---|
76 | } |
---|
77 | |
---|
78 | printf(" Linux SLL: Hardware Address Type = 0x%04x\n", ntohs(sll->hatype)); |
---|
79 | printf(" Linux SLL: Hardware Address Length = %u\n", ntohs(sll->halen)); |
---|
80 | printf(" Linux SLL: Hardware Address = %s\n", trace_ether_ntoa( (sll->addr), NULL)); |
---|
81 | |
---|
82 | printf(" Linux SLL: Protocol = 0x%04x\n", ntohs(sll->protocol)); |
---|
83 | |
---|
84 | /* Decide how to continue processing... */ |
---|
85 | |
---|
86 | /* Do we recognise the hardware address type? */ |
---|
87 | ret=trace_get_payload_from_meta(pkt, &linktype, &len); |
---|
88 | |
---|
89 | if (ntohs(sll->hatype) == LIBTRACE_ARPHRD_ETHER || |
---|
90 | ntohs(sll->hatype) == LIBTRACE_ARPHRD_LOOPBACK) { |
---|
91 | |
---|
92 | if (ntohs(sll->protocol) == 0x0060) { |
---|
93 | decode_next(ret, len, "link", |
---|
94 | arphrd_type_to_libtrace(ntohs(sll->hatype))); |
---|
95 | } |
---|
96 | else |
---|
97 | decode_next(pkt + sizeof(*sll), len - sizeof(*sll), |
---|
98 | "eth", ntohs(sll->protocol)); |
---|
99 | } |
---|
100 | else { |
---|
101 | decode_next(ret, len, "link", |
---|
102 | arphrd_type_to_libtrace(ntohs(sll->hatype))); |
---|
103 | } |
---|
104 | return; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | |
---|