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 | |
---|
14 | libtrace_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 | |
---|
32 | int 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 | |
---|
50 | enum 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 | |
---|
56 | int 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 | |
---|
62 | libtrace_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 | |
---|
73 | char 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 | } |
---|