source: lib/linktypes.c @ 747c501

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

Remove reliance on pcap.h for DLT_'s (and while we're here, make them a pretty
enum, so we get warnings if we forget one somewhere)

  • Property mode set to 100644
File size: 2.0 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(libtrace_dlt_t dlt)
18{
19        switch(dlt) {
20                case TRACE_DLT_NULL: return TRACE_TYPE_NONE;
21                case TRACE_DLT_EN10MB: return TRACE_TYPE_ETH;
22                case TRACE_DLT_ATM_RFC1483: return TRACE_TYPE_ATM;
23                case TRACE_DLT_IEEE802_11: return TRACE_TYPE_80211;
24                case TRACE_DLT_LINUX_SLL: return TRACE_TYPE_LINUX_SLL;
25                case TRACE_DLT_PFLOG: return TRACE_TYPE_PFLOG;
26                default:
27                                assert(!"No pcap support");
28        }
29        return -1;
30}
31
32int libtrace_to_pcap_dlt(libtrace_linktype_t type)
33{
34        switch(type) {
35                case TRACE_TYPE_NONE: return TRACE_DLT_NULL;
36                case TRACE_TYPE_ETH: return TRACE_DLT_EN10MB;
37                case TRACE_TYPE_ATM: return TRACE_DLT_ATM_RFC1483;
38                case TRACE_TYPE_80211: return TRACE_DLT_IEEE802_11;
39                case TRACE_TYPE_LINUX_SLL: return TRACE_DLT_LINUX_SLL;
40                case TRACE_TYPE_PFLOG: return TRACE_DLT_PFLOG;
41        }
42        return -1;
43}
44
45enum rt_field_t pcap_dlt_to_rt(int dlt) 
46{
47        /* For pcap the rt type is just the dlt + a fixed value */
48        return dlt + RT_DATA_PCAP;
49}
50
51int rt_to_pcap_dlt(enum rt_field_t rt_type)
52{
53        assert(rt_type >= RT_DATA_PCAP);
54        return rt_type - RT_DATA_PCAP;
55}
56
57libtrace_linktype_t erf_type_to_libtrace(char erf)
58{
59        switch (erf) {
60                case TYPE_HDLC_POS:     return TRACE_TYPE_HDLC_POS;
61                case TYPE_ETH:          return TRACE_TYPE_ETH;
62                case TYPE_ATM:          return TRACE_TYPE_ATM;
63                case TYPE_AAL5:         return TRACE_TYPE_AAL5;
64        }
65        return -1;
66}
67
68char libtrace_to_erf_type(libtrace_linktype_t linktype)
69{
70        switch(linktype) {
71                case TRACE_TYPE_HDLC_POS: return TYPE_HDLC_POS;
72                case TRACE_TYPE_ETH:    return TYPE_ETH;
73                case TRACE_TYPE_ATM:    return TYPE_ATM;
74                case TRACE_TYPE_AAL5:   return TYPE_AAL5;
75        }
76        return -1;
77}
Note: See TracBrowser for help on using the repository browser.