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 | DLLEXPORT void decode(int link_type ,const char *pkt,unsigned len) |
---|
17 | { |
---|
18 | libtrace_sll_header_t *sll = (libtrace_sll_header_t *) pkt; |
---|
19 | libtrace_linktype_t linktype = link_type; |
---|
20 | void *ret; |
---|
21 | |
---|
22 | if (len < sizeof(*sll)) { |
---|
23 | printf(" Linux SLL: Truncated (len = %u)\n", len); |
---|
24 | return; |
---|
25 | } |
---|
26 | |
---|
27 | printf(" Linux SLL: Packet Type = "); |
---|
28 | switch(ntohs(sll->pkttype)) { |
---|
29 | case TRACE_SLL_HOST: printf("HOST\n"); break; |
---|
30 | case TRACE_SLL_BROADCAST: printf("BROADCAST\n"); break; |
---|
31 | case TRACE_SLL_MULTICAST: printf("MULTICAST\n"); break; |
---|
32 | case TRACE_SLL_OTHERHOST: printf("OTHERHOST\n"); break; |
---|
33 | case TRACE_SLL_OUTGOING: printf("OUTGOING\n"); break; |
---|
34 | default: printf("Unknown (0x%04x)\n", ntohs(sll->pkttype)); |
---|
35 | } |
---|
36 | |
---|
37 | printf(" Linux SLL: Hardware Address Type = 0x%04x\n", ntohs(sll->hatype)); |
---|
38 | printf(" Linux SLL: Hardware Address Length = %u\n", ntohs(sll->halen)); |
---|
39 | printf(" Linux SLL: Hardware Address = %s\n", trace_ether_ntoa( (sll->addr), NULL)); |
---|
40 | |
---|
41 | printf(" Linux SLL: Protocol = 0x%04x\n", ntohs(sll->protocol)); |
---|
42 | |
---|
43 | /* Decide how to continue processing... */ |
---|
44 | |
---|
45 | /* Do we recognise the hardware address type? */ |
---|
46 | ret=trace_get_payload_from_meta(pkt, &linktype, &len); |
---|
47 | |
---|
48 | if (ntohs(sll->hatype) == ARPHRD_ETHER || |
---|
49 | ntohs(sll->hatype) == ARPHRD_LOOPBACK) |
---|
50 | decode_next(pkt + sizeof(*sll), len - sizeof(*sll), "eth", ntohs(sll->protocol)); |
---|
51 | |
---|
52 | else |
---|
53 | decode_next(ret, len, "link", ntohs(sll->hatype)); |
---|
54 | |
---|
55 | return; |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | |
---|