Changeset 73dd29f for lib/linktypes.c


Ignore:
Timestamp:
04/02/07 21:44:53 (15 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
11f2df7
Parents:
02bd77e
Message:

Sooo, pcap has two types of DLT's "pure" DLT's that are platform dependant,
and "linktype" DLT's that are portable and are what are written to pcap files.

Instead of fudging the two concepts together so much, attempt to disintangle
this mess without exposing too much of the god awful mess to the end user.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/linktypes.c

    rbe22b51 r73dd29f  
    3232 */
    3333
    34 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt)
    35 {
    36         switch(dlt) {
    37                 case TRACE_DLT_RAW: return TRACE_TYPE_NONE;
     34libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype)
     35{
     36        switch(linktype) {
     37                case TRACE_DLT_RAW:
     38                case TRACE_DLT_LINKTYPE_RAW: return TRACE_TYPE_NONE;
    3839                case TRACE_DLT_EN10MB: return TRACE_TYPE_ETH;
    3940                case TRACE_DLT_IEEE802_11: return TRACE_TYPE_80211;
     
    5354}
    5455
    55 
    56 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type)
     56libtrace_linktype_t libtrace_to_pcap_dlt(libtrace_linktype_t type)
    5757{
    5858        /* If pcap doesn't have a DLT, you can either ask pcap to register
     
    6161         */
    6262        switch(type) {
    63                 case TRACE_TYPE_NONE: return TRACE_DLT_RAW;
     63                case TRACE_TYPE_NONE: return TRACE_DLT_RAW; 
    6464                case TRACE_TYPE_ETH: return TRACE_DLT_EN10MB;
    6565                case TRACE_TYPE_80211: return TRACE_DLT_IEEE802_11;
     
    9393}
    9494
    95 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt)
    96 {
    97         /* For pcap the rt type is just the dlt + a fixed value */
    98         return dlt + TRACE_RT_DATA_DLT;
    99 }
    100 
    101 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type)
     95libtrace_linktype_t libtrace_to_pcap_linktype(libtrace_linktype_t type)
     96{
     97        return pcap_dlt_to_pcap_linktype(libtrace_to_pcap_dlt(type));
     98}
     99
     100static libtrace_dlt_t pcap_dlt_to_pcap_linktype(libtrace_dlt_t linktype)
     101{
     102        switch (linktype) {
     103                case TRACE_DLT_RAW: return TRACE_DLT_LINKTYPE_RAW;
     104                default:
     105                                    return linktype;
     106        }
     107}
     108
     109libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype)
     110{
     111        /* For pcap the rt type is just the linktype + a fixed value */
     112        return pcap_dlt_to_pcap_linktype(linktype) + TRACE_RT_DATA_DLT;
     113}
     114
     115libtrace_linktype_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type)
    102116{
    103117        assert(rt_type >= TRACE_RT_DATA_DLT);
     
    173187                libtrace_sll_header_t *hdr;
    174188
    175                 if (pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type))
     189                if (pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))
    176190                        == TRACE_TYPE_LINUX_SLL) {
    177191                        /* This is already been promoted, so ignore it */
     
    192206                hdr->pkttype=TRACE_SLL_OUTGOING;
    193207
    194                 switch(pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type))) {
     208                switch(pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))) {
    195209                        case TRACE_TYPE_NONE:
    196210                                trace_get_payload_from_link(
     
    226240                packet->header=tmpbuffer;
    227241                packet->payload=tmpbuffer+trace_get_framing_length(packet);
    228                 packet->type=pcap_dlt_to_rt(TRACE_DLT_LINUX_SLL);
     242                packet->type=pcap_linktype_to_rt(TRACE_DLT_LINUX_SLL);
    229243                ((struct libtrace_pcapfile_pkt_hdr_t*) packet->header)->caplen+=
    230244                        sizeof(libtrace_sll_header_t);
     
    277291                        packet->header=tmp;
    278292                        packet->payload=tmp+sizeof(libtrace_pcapfile_pkt_hdr_t);
    279                         packet->type=pcap_dlt_to_rt(TRACE_DLT_ATM_RFC1483);
     293                        packet->type=pcap_linktype_to_rt(TRACE_DLT_ATM_RFC1483);
    280294                       
    281295                        if (trace == NULL) {
     
    291305                                        ->hatype)) {
    292306                                case ARPHRD_PPP:
    293                                         packet->type=pcap_dlt_to_rt(TRACE_DLT_RAW);
     307                                        packet->type=pcap_linktype_to_rt(TRACE_DLT_RAW);
    294308                                        break;
    295309                                case ARPHRD_ETHER:
    296                                         packet->type=pcap_dlt_to_rt(TRACE_DLT_EN10MB);
     310                                        packet->type=pcap_linktype_to_rt(TRACE_DLT_EN10MB);
    297311                                        break;
    298312                                default:
Note: See TracChangeset for help on using the changeset viewer.