source: lib/linktypes.c @ aa67e26

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since aa67e26 was 67a14d4, checked in by Perry Lorier <perry@…>, 16 years ago

Move more types to the libtrace standard (typedef'd libtrace_*_t)
Add casts where appropriate
Remove default:'s from enum'd switch()'s

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[643105b]1#include "libtrace.h"
[0220eb1]2#ifdef HAVE_PCAP
[643105b]3#include <pcap.h>
[0220eb1]4#endif
[643105b]5#include "dagformat.h"
[7ac9705]6#include "rt_protocol.h"
7#include <assert.h>
[643105b]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
16libtrace_linktype_t pcap_dlt_to_libtrace(int dlt)
17{
18        switch(dlt) {
[0220eb1]19#if HAVE_PCAP
[643105b]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
[0220eb1]30#endif
[643105b]31        }
[67a14d4]32        return -1;
[643105b]33}
34
35int libtrace_to_pcap_dlt(libtrace_linktype_t type)
36{
37        switch(type) {
[0220eb1]38#ifdef HAVE_PCAP
[643105b]39                case TRACE_TYPE_NONE: return DLT_NULL;
40                case TRACE_TYPE_ETH: return DLT_EN10MB;
41                case TRACE_TYPE_ATM: return DLT_ATM_RFC1483;
42                case TRACE_TYPE_80211: return DLT_IEEE802_11;
43#ifdef DLT_LINUX_SLL
44                case TRACE_TYPE_LINUX_SLL: return DLT_LINUX_SLL;
45#endif
46#ifdef DLT_PFLOG
47                case TRACE_TYPE_PFLOG: return DLT_PFLOG;
48#endif
[0220eb1]49#endif
[643105b]50        }
[67a14d4]51        return -1;
[643105b]52}
53
[7ac9705]54enum rt_field_t pcap_dlt_to_rt(int dlt) 
55{
56        /* For pcap the rt type is just the dlt + a fixed value */
57        return dlt + RT_DATA_PCAP;
58}
59
60int rt_to_pcap_dlt(enum rt_field_t rt_type)
61{
62        assert(rt_type >= RT_DATA_PCAP);
63        return rt_type - RT_DATA_PCAP;
64}
65
[643105b]66libtrace_linktype_t erf_type_to_libtrace(char erf)
67{
68        switch (erf) {
69                case TYPE_LEGACY:       return TRACE_TYPE_LEGACY;
[67a14d4]70                case TYPE_HDLC_POS:     return TRACE_TYPE_HDLC_POS;
[643105b]71                case TYPE_ETH:          return TRACE_TYPE_ETH;
72                case TYPE_ATM:          return TRACE_TYPE_ATM;
[67a14d4]73                case TYPE_AAL5:         return TRACE_TYPE_AAL5;
[643105b]74        }
[67a14d4]75        return -1;
[643105b]76}
77
78char libtrace_to_erf_type(libtrace_linktype_t linktype)
79{
80        switch(linktype) {
81                case TRACE_TYPE_LEGACY: return TYPE_LEGACY;
82                case TRACE_TYPE_ETH:    return TYPE_ETH;
83                case TRACE_TYPE_ATM:    return TYPE_ATM;
84        }
[67a14d4]85        return -1;
[643105b]86}
Note: See TracBrowser for help on using the repository browser.