source: libpacketdump/link_6.c @ 528eb6e

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 528eb6e was 528eb6e, checked in by Shane Alcock <salcock@…>, 8 years ago
  • A very cut-down version of int: and ring: is now built on non-Linux systems, enabling them to be able to decode packets captured using those formats and exported via RT
  • Replaced arphrd.h with a new header file (libtrace_arphrd.h) that provides our own #defines for the various ARPHRD types. The inconsistency between what is available on different OS's was becoming problematic.
  • Increased RT buffer size so we can always fit a complete libtrace buffer into it - int: over RT tends to result in very large "packets".
  • Fixed copy-paste error in the failure case when creating a dummy linux trace in format_rt.c
  • Updated various bits of code to use the new LIBTRACE_ARPHRD types where sensible
  • Removed unneeded #include in protocols_pktmeta.c
  • Replaced u32 and u16 types in format_linux with more portable uint32_t and uint16_t types
  • Removed unneeded calls to linuxnative_init_input in the prepare_packet functions in format_linux.c
  • Don't call the fin_input function on a trace if the format does not provide one
  • Property mode set to 100644
File size: 2.6 KB
Line 
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 "libtrace_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? */
18static libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd) {
19        switch(arphrd) {
20                case LIBTRACE_ARPHRD_ETHER: return TRACE_TYPE_ETH;
21                case LIBTRACE_ARPHRD_EETHER: return TRACE_TYPE_ETH;
22                case LIBTRACE_ARPHRD_IEEE80211: return TRACE_TYPE_80211;
23                case LIBTRACE_ARPHRD_IEEE80211_RADIOTAP: return TRACE_TYPE_80211_RADIO;
24                case LIBTRACE_ARPHRD_PPP: return TRACE_TYPE_NONE;
25                case LIBTRACE_ARPHRD_LOOPBACK: return TRACE_TYPE_NONE;
26                case LIBTRACE_ARPHRD_NONE: return TRACE_TYPE_NONE;
27        }
28        printf("Unknown ARPHRD: %u\n", arphrd);
29        return ~0U;
30}
31
32DLLEXPORT 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) == LIBTRACE_ARPHRD_ETHER || 
65                                ntohs(sll->hatype) == LIBTRACE_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
Note: See TracBrowser for help on using the repository browser.