1 | /* |
---|
2 | * Linux SLL Decoder |
---|
3 | * |
---|
4 | */ |
---|
5 | |
---|
6 | #include "config.h" |
---|
7 | #include "libtrace_int.h" |
---|
8 | #include <sys/types.h> |
---|
9 | #include <netinet/in.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include "libpacketdump.h" |
---|
12 | #include "libtrace.h" |
---|
13 | |
---|
14 | #include "arphrd.h" |
---|
15 | |
---|
16 | /* Copied this here because this isn't currently part of our external API - |
---|
17 | * maybe we need to think about doing that? */ |
---|
18 | libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd) { |
---|
19 | switch(arphrd) { |
---|
20 | case ARPHRD_ETHER: return TRACE_TYPE_ETH; |
---|
21 | case ARPHRD_EETHER: return TRACE_TYPE_ETH; |
---|
22 | case ARPHRD_IEEE80211: return TRACE_TYPE_80211; |
---|
23 | case ARPHRD_80211_RADIOTAP: return TRACE_TYPE_80211_RADIO; |
---|
24 | case ARPHRD_PPP: return TRACE_TYPE_NONE; |
---|
25 | case ARPHRD_LOOPBACK: return TRACE_TYPE_NONE; |
---|
26 | case ARPHRD_NONE: return TRACE_TYPE_NONE; |
---|
27 | } |
---|
28 | printf("Unknown ARPHRD: %u\n", arphrd); |
---|
29 | return ~0U; |
---|
30 | } |
---|
31 | |
---|
32 | DLLEXPORT void decode(int link_type ,const char *pkt,unsigned len) |
---|
33 | { |
---|
34 | libtrace_sll_header_t *sll = (libtrace_sll_header_t *) pkt; |
---|
35 | libtrace_linktype_t linktype = link_type; |
---|
36 | void *ret; |
---|
37 | |
---|
38 | if (len < sizeof(*sll)) { |
---|
39 | printf(" Linux SLL: Truncated (len = %u)\n", len); |
---|
40 | return; |
---|
41 | } |
---|
42 | |
---|
43 | printf(" Linux SLL: Packet Type = "); |
---|
44 | switch(ntohs(sll->pkttype)) { |
---|
45 | case TRACE_SLL_HOST: printf("HOST\n"); break; |
---|
46 | case TRACE_SLL_BROADCAST: printf("BROADCAST\n"); break; |
---|
47 | case TRACE_SLL_MULTICAST: printf("MULTICAST\n"); break; |
---|
48 | case TRACE_SLL_OTHERHOST: printf("OTHERHOST\n"); break; |
---|
49 | case TRACE_SLL_OUTGOING: printf("OUTGOING\n"); break; |
---|
50 | default: printf("Unknown (0x%04x)\n", ntohs(sll->pkttype)); |
---|
51 | } |
---|
52 | |
---|
53 | printf(" Linux SLL: Hardware Address Type = 0x%04x\n", ntohs(sll->hatype)); |
---|
54 | printf(" Linux SLL: Hardware Address Length = %u\n", ntohs(sll->halen)); |
---|
55 | printf(" Linux SLL: Hardware Address = %s\n", trace_ether_ntoa( (sll->addr), NULL)); |
---|
56 | |
---|
57 | printf(" Linux SLL: Protocol = 0x%04x\n", ntohs(sll->protocol)); |
---|
58 | |
---|
59 | /* Decide how to continue processing... */ |
---|
60 | |
---|
61 | /* Do we recognise the hardware address type? */ |
---|
62 | ret=trace_get_payload_from_meta(pkt, &linktype, &len); |
---|
63 | |
---|
64 | if (ntohs(sll->hatype) == ARPHRD_ETHER || |
---|
65 | ntohs(sll->hatype) == ARPHRD_LOOPBACK) { |
---|
66 | |
---|
67 | if (ntohs(sll->protocol) == 0x0060) { |
---|
68 | decode_next(ret, len, "link", |
---|
69 | arphrd_type_to_libtrace(ntohs(sll->hatype))); |
---|
70 | } |
---|
71 | else |
---|
72 | decode_next(pkt + sizeof(*sll), len - sizeof(*sll), |
---|
73 | "eth", ntohs(sll->protocol)); |
---|
74 | } |
---|
75 | else { |
---|
76 | decode_next(ret, len, "link", |
---|
77 | arphrd_type_to_libtrace(ntohs(sll->hatype))); |
---|
78 | } |
---|
79 | return; |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | |
---|