source: lib/linktypes.c @ 97e39a7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 97e39a7 was 97e39a7, checked in by Perry Lorier <perry@…>, 15 years ago

Port new linux native capture type from libtrace 2.
Fail if we try and decode a pcap link type and we don't have pcap installed.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include "libtrace.h"
2#include "config.h"
3#ifdef HAVE_PCAP
4#include <pcap.h>
5#endif
6#include "dagformat.h"
7#include "rt_protocol.h"
8#include <assert.h>
9
10/* This file maps libtrace types to/from pcap DLT and erf types
11 *
12 * When adding a new linktype to libtrace, add the mapping(s) here,
13 * and add the understanding of the type to get_ip(), and perhaps
14 * get_{source,destination}_mac (if your linklayer has mac's)
15 */
16
17libtrace_linktype_t pcap_dlt_to_libtrace(int dlt)
18{
19        switch(dlt) {
20#if HAVE_PCAP
21                case DLT_NULL: return TRACE_TYPE_NONE;
22                case DLT_EN10MB: return TRACE_TYPE_ETH;
23                case DLT_ATM_RFC1483: return TRACE_TYPE_ATM;
24                case DLT_IEEE802_11: return TRACE_TYPE_80211;
25#ifdef DLT_LINUX_SLL
26                case DLT_LINUX_SLL: return TRACE_TYPE_LINUX_SLL;
27#endif
28#ifdef DLT_PFLOG
29                case DLT_PFLOG: return TRACE_TYPE_PFLOG;
30#endif
31#else
32                default:
33                                assert(!"No pcap support");
34#endif
35        }
36        return -1;
37}
38
39int libtrace_to_pcap_dlt(libtrace_linktype_t type)
40{
41        switch(type) {
42#ifdef HAVE_PCAP
43                case TRACE_TYPE_NONE: return DLT_NULL;
44                case TRACE_TYPE_ETH: return DLT_EN10MB;
45                case TRACE_TYPE_ATM: return DLT_ATM_RFC1483;
46                case TRACE_TYPE_80211: return DLT_IEEE802_11;
47#ifdef DLT_LINUX_SLL
48                case TRACE_TYPE_LINUX_SLL: return DLT_LINUX_SLL;
49#endif
50#ifdef DLT_PFLOG
51                case TRACE_TYPE_PFLOG: return DLT_PFLOG;
52#endif
53#endif
54        }
55        return -1;
56}
57
58enum rt_field_t pcap_dlt_to_rt(int dlt) 
59{
60        /* For pcap the rt type is just the dlt + a fixed value */
61        return dlt + RT_DATA_PCAP;
62}
63
64int rt_to_pcap_dlt(enum rt_field_t rt_type)
65{
66        assert(rt_type >= RT_DATA_PCAP);
67        return rt_type - RT_DATA_PCAP;
68}
69
70libtrace_linktype_t erf_type_to_libtrace(char erf)
71{
72        switch (erf) {
73                case TYPE_LEGACY:       return TRACE_TYPE_LEGACY;
74                case TYPE_HDLC_POS:     return TRACE_TYPE_HDLC_POS;
75                case TYPE_ETH:          return TRACE_TYPE_ETH;
76                case TYPE_ATM:          return TRACE_TYPE_ATM;
77                case TYPE_AAL5:         return TRACE_TYPE_AAL5;
78        }
79        return -1;
80}
81
82char libtrace_to_erf_type(libtrace_linktype_t linktype)
83{
84        switch(linktype) {
85                case TRACE_TYPE_LEGACY: return TYPE_LEGACY;
86                case TRACE_TYPE_HDLC_POS: return TYPE_HDLC_POS;
87                case TRACE_TYPE_ETH:    return TYPE_ETH;
88                case TRACE_TYPE_ATM:    return TYPE_ATM;
89                case TRACE_TYPE_AAL5:   return TYPE_AAL5;
90        }
91        return -1;
92}
Note: See TracBrowser for help on using the repository browser.