source: lib/linktypes.c @ 67a14d4

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

Move more types to the libtrace standard (typedef'd libtrace_*_t)
Add casts where appropriate
Remove default:'s from enum'd switch()'s

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