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 | |
---|
17 | libtrace_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 | |
---|
32 | int 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 | |
---|
45 | enum 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 | |
---|
51 | int 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 | |
---|
57 | libtrace_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 | |
---|
68 | char 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 | } |
---|