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 | |
---|
16 | libtrace_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 | default: |
---|
32 | return -1; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | int libtrace_to_pcap_dlt(libtrace_linktype_t type) |
---|
37 | { |
---|
38 | switch(type) { |
---|
39 | #ifdef HAVE_PCAP |
---|
40 | case TRACE_TYPE_NONE: return DLT_NULL; |
---|
41 | case TRACE_TYPE_ETH: return DLT_EN10MB; |
---|
42 | case TRACE_TYPE_ATM: return DLT_ATM_RFC1483; |
---|
43 | case TRACE_TYPE_80211: return DLT_IEEE802_11; |
---|
44 | #ifdef DLT_LINUX_SLL |
---|
45 | case TRACE_TYPE_LINUX_SLL: return DLT_LINUX_SLL; |
---|
46 | #endif |
---|
47 | #ifdef DLT_PFLOG |
---|
48 | case TRACE_TYPE_PFLOG: return DLT_PFLOG; |
---|
49 | #endif |
---|
50 | #endif |
---|
51 | default: |
---|
52 | return -1; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | enum rt_field_t pcap_dlt_to_rt(int dlt) |
---|
57 | { |
---|
58 | /* For pcap the rt type is just the dlt + a fixed value */ |
---|
59 | return dlt + RT_DATA_PCAP; |
---|
60 | } |
---|
61 | |
---|
62 | int rt_to_pcap_dlt(enum rt_field_t rt_type) |
---|
63 | { |
---|
64 | assert(rt_type >= RT_DATA_PCAP); |
---|
65 | return rt_type - RT_DATA_PCAP; |
---|
66 | } |
---|
67 | |
---|
68 | libtrace_linktype_t erf_type_to_libtrace(char erf) |
---|
69 | { |
---|
70 | switch (erf) { |
---|
71 | case TYPE_LEGACY: return TRACE_TYPE_LEGACY; |
---|
72 | case TYPE_ETH: return TRACE_TYPE_ETH; |
---|
73 | case TYPE_ATM: return TRACE_TYPE_ATM; |
---|
74 | default: |
---|
75 | return -1; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | char libtrace_to_erf_type(libtrace_linktype_t linktype) |
---|
80 | { |
---|
81 | switch(linktype) { |
---|
82 | case TRACE_TYPE_LEGACY: return TYPE_LEGACY; |
---|
83 | case TRACE_TYPE_ETH: return TYPE_ETH; |
---|
84 | case TRACE_TYPE_ATM: return TYPE_ATM; |
---|
85 | default: |
---|
86 | return -1; |
---|
87 | } |
---|
88 | } |
---|