source: lib/linktypes.c @ 7ac9705

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 7ac9705 was 7ac9705, checked in by Shane Alcock <salcock@…>, 16 years ago

Changed rt types so that every pcap dlt has a matching rt type
Added functions for conversion between rt type and pcap dlt
format_rt now uses trace_set_err appropriately if rt_connect fails
format_pcap will check if a trace is dead before trying to look at

format data

Dead traces now have their format_data set to NULL
packet->type is now 32 bits, not 8

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