Changeset 1269

Show
Ignore:
Timestamp:
06/09/07 01:07:07 (1 year ago)
Author:
perry
Message:

Move everything over to using the newer API's

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/format_pcap.c

    r1247 r1269  
    313313{ 
    314314        struct pcap_pkthdr pcap_pkt_hdr; 
     315        void *link; 
     316        libtrace_linktype_t linktype; 
     317        uint32_t remaining; 
     318 
     319        link = trace_get_packet_buffer(packet,&linktype,&remaining); 
    315320 
    316321        /* If this packet cannot be converted to a pcap linktype then 
    317322         * pop off the top header until it can be converted 
    318323         */ 
    319         while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) { 
     324        while (libtrace_to_pcap_linktype(linktype)==~0U) { 
    320325                if (!demote_packet(packet)) { 
    321326                        trace_set_err_out(libtrace,  
     
    324329                        return -1; 
    325330                } 
     331 
     332                link = trace_get_packet_buffer(packet,&linktype,&remaining); 
    326333        } 
    327334 
     
    346353 
    347354        /* Corrupt packet, or other "non data" packet, so skip it */ 
    348         if (trace_get_link(packet) == NULL) { 
     355        if (link == NULL) { 
    349356                /* Return "success", but nothing written */ 
    350357                return 0; 
     
    363370                pcap_pkt_hdr.ts.tv_sec = ts.tv_sec; 
    364371                pcap_pkt_hdr.ts.tv_usec = ts.tv_usec; 
    365                 pcap_pkt_hdr.caplen = trace_get_capture_length(packet)
     372                pcap_pkt_hdr.caplen = remaining
    366373                /* trace_get_wire_length includes FCS, while pcap doesn't */ 
    367374                if (trace_get_link_type(packet)==TRACE_TYPE_ETH) 
     
    442449                { 
    443450                        libtrace_sll_header_t *sll; 
    444                         sll = trace_get_link(packet); 
     451                        sll = trace_get_packet_buffer(packet, NULL, NULL); 
     452                        /* TODO: should check remaining>=sizeof(*sll) */ 
    445453                        if (!sll) { 
    446454                                trace_set_err(packet->trace, 
     
    471479                { 
    472480                        libtrace_pflog_header_t *pflog; 
    473                         pflog = trace_get_link(packet); 
     481                        pflog = trace_get_packet_buffer(packet, NULL, NULL); 
     482                        /* TODO: should check remaining >= sizeof(*pflog) */ 
    474483                        if (!pflog) { 
    475484                                trace_set_err(packet->trace, 
     
    518527                return pcapptr->len+4; /* Include the missing FCS */ 
    519528        else if (packet->type==pcap_linktype_to_rt(TRACE_DLT_IEEE802_11_RADIO)) { 
     529                libtrace_linktype_t linktype; 
     530                void *link = trace_get_packet_buffer(packet,&linktype,NULL); 
    520531                /* If the packet is Radiotap and the flags field indicates 
    521532                 * that the FCS is not included in the 802.11 frame, then 
     
    523534                 */ 
    524535                uint8_t flags; 
    525                 trace_get_wireless_flags(trace_get_link(packet),  
    526                                 trace_get_link_type(packet), &flags); 
     536                trace_get_wireless_flags(link,  
     537                                linktype, &flags); 
    527538                if ((flags & TRACE_RADIOTAP_F_FCS) == 0) 
    528539                        return pcapptr->len + 4; 
  • trunk/lib/format_pcapfile.c

    r1246 r1269  
    281281        int numbytes; 
    282282        int ret; 
     283        void *ptr; 
     284        uint32_t remaining; 
     285        libtrace_linktype_t linktype; 
     286 
     287        ptr = trace_get_packet_buffer(packet,&linktype,&remaining); 
    283288 
    284289        /* If this packet cannot be converted to a pcap linktype then 
    285290         * pop off the top header until it can be converted 
    286291         */ 
    287         while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) { 
     292        while (libtrace_to_pcap_linktype(linktype)==~0U) { 
    288293                if (!demote_packet(packet)) { 
    289294                        trace_set_err_out(out,  
     
    292297                        return -1; 
    293298                } 
     299 
     300                ptr = trace_get_packet_buffer(packet,&linktype,&remaining); 
    294301        } 
    295302 
     
    314321                pcaphdr.snaplen = 65536; 
    315322                pcaphdr.network =  
    316                         libtrace_to_pcap_linktype(trace_get_link_type(packet)); 
    317  
    318                 libtrace_io_write(DATAOUT(out)->file, &pcaphdr, sizeof(pcaphdr)); 
     323                        libtrace_to_pcap_linktype(linktype); 
     324 
     325                libtrace_io_write(DATAOUT(out)->file,  
     326                                &pcaphdr, sizeof(pcaphdr)); 
    319327        } 
    320328 
     
    323331        hdr.caplen = trace_get_capture_length(packet); 
    324332        /* PCAP doesn't include the FCS, we do */ 
    325         if (trace_get_link_type(packet)==TRACE_TYPE_ETH) 
     333        if (linktype==TRACE_TYPE_ETH) 
    326334                if (trace_get_wire_length(packet) >= 4) { 
    327                         hdr.wirelen = 
    328                                         trace_get_wire_length(packet)-4; 
     335                        hdr.wirelen = trace_get_wire_length(packet)-4; 
    329336                } 
    330337                else { 
     
    342349 
    343350        ret=libtrace_io_write(DATAOUT(out)->file, 
    344                         trace_get_link(packet)
    345                         trace_get_capture_length(packet)); 
    346  
    347         if (ret!=(int)trace_get_capture_length(packet)
     351                        link
     352                        remaining); 
     353 
     354        if (ret!=(int)remaining
    348355                return -1; 
    349356 
     
    371378                { 
    372379                        libtrace_sll_header_t *sll; 
    373                         sll = (libtrace_sll_header_t*)trace_get_link(packet); 
     380                        libtrace_linktype_t linktype; 
     381 
     382                        sll = (libtrace_sll_header_t*)trace_get_packet_buffer( 
     383                                        packet, 
     384                                        &linktype, 
     385                                        NULL); 
    374386                        if (!sll) { 
    375387                                trace_set_err(packet->trace, 
     
    400412                { 
    401413                        libtrace_pflog_header_t *pflog; 
    402                         pflog=(libtrace_pflog_header_t*)trace_get_link(packet); 
     414                        libtrace_linktype_t linktype; 
     415 
     416                        pflog=(libtrace_pflog_header_t*)trace_get_packet_buffer( 
     417                                        packet,&linktype,NULL); 
    403418                        if (!pflog) { 
    404419                                trace_set_err(packet->trace, 
     
    455470                 */ 
    456471                uint8_t flags; 
    457                 trace_get_wireless_flags(trace_get_link(packet), 
    458                                 trace_get_link_type(packet), &flags); 
     472                void *link; 
     473                libtrace_linktype_t linktype; 
     474                link = trace_get_packet_buffer(packet, &linktype, NULL); 
     475                trace_get_wireless_flags(link, linktype, &flags); 
    459476                if ((flags & TRACE_RADIOTAP_F_FCS) == 0) 
    460477                        return swapl(packet->trace,pcapptr->wirelen)+4; 
  • trunk/lib/libtrace.h.in

    r1268 r1269  
    397397    int16_t  ip_id;                     /**< Identification */ 
    398398#if BYTE_ORDER == LITTLE_ENDIAN 
    399     LT_BITFIELD16 ip_off:12;          /**< Fragment Offset */ 
     399    LT_BITFIELD16 ip_off:13;          /**< Fragment Offset */ 
    400400    LT_BITFIELD16 ip_mf:1;              /**< More Fragments Flag */ 
    401401    LT_BITFIELD16 ip_df:1;              /**< Dont Fragment Flag */ 
     
    405405    LT_BITFIELD16 ip_df:1;              /**< More Fragments Flag */ 
    406406    LT_BITFIELD16 ip_mf:1;              /**< Dont Fragment Flag */ 
    407     LT_BITFIELD16 ip_off:12;          /**< Reserved Fragment Flag */ 
     407    LT_BITFIELD16 ip_off:13;          /**< Reserved Fragment Flag */ 
    408408#else 
    409409#   error "Adjust your <bits/endian.h> defines" 
     
    10631063                uint32_t *remaining); 
    10641064 
     1065/** Gets a pointer to the next header given a pointer to a layer2 header 
     1066 * 
     1067 * @param l2                    The pointer to the current layer2 header 
     1068 * @param linktype              The type of the layer2 header 
     1069 * @param[out] ethertype        An optional output variable of the ethernet type 
     1070 * @param[in,out] remaining     Optionally updated with the length remaining 
     1071 * 
     1072 * @return a pointer to the transport layer header, or NULL if header isn't 
     1073 * present. 
     1074 * 
     1075 * type may be NULL if not needed. 
     1076 * 
     1077 * Remaining may be NULL.  If Remaining is not NULL it must point to the number 
     1078 * of bytes captured of the layer2 header and beyond.  It will be updated after 
     1079 * this function to the number of bytes remaining after the layer2 header 
     1080 * was removed. 
     1081 * 
     1082 */ 
     1083DLLEXPORT void *trace_get_payload_from_layer2(void *l2, 
     1084                libtrace_linktype_t linktype, 
     1085                uint16_t *ethertype, 
     1086                uint32_t *remaining); 
     1087 
     1088 
    10651089/** Get a pointer to the layer 3 header. 
    10661090 * @param packet                The packet opaque pointer 
     
    10741098 */ 
    10751099DLLEXPORT SIMPLE_FUNCTION 
    1076 void *trace_get_layer3(libtrace_packet_t *packet, 
     1100void *trace_get_layer3(const libtrace_packet_t *packet, 
    10771101                uint16_t *ethertype, uint32_t *remaining); 
    10781102 
     
    10851109 * @note proto may be NULL if proto is unneeded. 
    10861110 */ 
    1087 DLLEXPORT void *trace_get_transport(libtrace_packet_t *packet, uint8_t *proto,  
     1111DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet, uint8_t *proto,  
    10881112                uint32_t *remaining); 
    10891113 
     
    14261450 */ 
    14271451DLLEXPORT SIMPLE_FUNCTION 
    1428 size_t trace_get_capture_length(libtrace_packet_t *packet); 
     1452size_t trace_get_capture_length(const libtrace_packet_t *packet); 
    14291453 
    14301454/** Get the size of the packet as it was seen on the wire. 
  • trunk/lib/libtrace_int.h

    r1266 r1269  
    373373bool demote_packet(libtrace_packet_t *packet); 
    374374 
    375 void *trace_get_payload_from_linux_sll(void *, uint16_t *, uint32_t *); 
     375void *trace_get_payload_from_linux_sll(const void *, uint16_t *, uint32_t *); 
    376376void *trace_get_payload_from_pos(void *, uint16_t *, uint32_t *); 
    377377DLLEXPORT void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *); 
  • trunk/lib/linktypes.c

    r1242 r1269  
    210210                switch(pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))) { 
    211211                        case TRACE_TYPE_NONE: 
    212                                 trace_get_payload_from_link( 
    213                                         trace_get_link(packet), 
    214                                         trace_get_link_type(packet), 
    215                                         &hdr->protocol, 
    216                                         NULL); 
     212                                trace_get_layer3(packet, &hdr->protocol, NULL); 
    217213                                hdr->hatype = htons(ARPHRD_PPP); 
    218214                                hdr->protocol=htons(hdr->protocol); 
  • trunk/lib/protocols.c

    r1268 r1269  
    156156 
    157157/* NB: type is returned as an ARPHRD_ type for SLL*/ 
    158 void *trace_get_payload_from_linux_sll(void *link, 
     158void *trace_get_payload_from_linux_sll(const void *link, 
    159159                uint16_t *type, uint32_t *remaining)  
    160160{ 
     
    257257 
    258258/* Returns the 'payload' of the prism header, which is the 802.11 frame */ 
    259 static void *trace_get_payload_from_prism (void *link, 
    260                 uint16_t *type, uint32_t *remaining) 
     259static void *trace_get_payload_from_prism (const void *link, 
     260                libtrace_linktype_t *type, uint32_t *remaining) 
    261261{ 
    262262        if (remaining) { 
     
    272272 
    273273/* Returns the 'payload' of the radiotap header, which is the 802.11 frame */ 
    274 static void *trace_get_payload_from_radiotap (void *link,  
    275                 uint16_t *type, uint32_t *remaining) 
     274static void *trace_get_payload_from_radiotap (const void *link,  
     275                libtrace_linktype_t *type, uint32_t *remaining) 
    276276{ 
    277277        struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t*)link; 
     
    296296        switch(linktype) { 
    297297                case TRACE_TYPE_80211_PRISM: 
    298                         l = trace_get_payload_from_prism(link,type,remaining); 
     298                        l = trace_get_payload_from_prism(link,&linktype,remaining); 
    299299                        return (l ? trace_get_payload_from_link(l, TRACE_TYPE_80211, type, remaining) : NULL); 
    300300                case TRACE_TYPE_80211_RADIO: 
    301                         l = trace_get_payload_from_radiotap(link,type,remaining); 
     301                        l = trace_get_payload_from_radiotap(link,&linktype,remaining); 
    302302                        return (l ? trace_get_payload_from_link(l, TRACE_TYPE_80211, type, remaining) : NULL); 
    303303                case TRACE_TYPE_80211: 
     
    446446                uint32_t *remaining) 
    447447{ 
    448         uint32_t dummyrem = trace_get_capture_length(packet)
     448        uint32_t dummyrem
    449449 
    450450        assert(packet != NULL); 
     
    474474                        return NULL; 
    475475        } 
     476 
     477        /* Shouldn't get here */ 
     478        return NULL; 
    476479} 
    477480 
     
    519522                        return NULL; 
    520523        } 
     524        /* Shouldn't get here */ 
     525        return NULL; 
    521526} 
    522527 
     
    553558} 
    554559 
    555 DLLEXPORT void *trace_get_layer3(libtrace_packet_t *packet, 
     560DLLEXPORT void *trace_get_payload_from_layer2(void *link, 
     561                libtrace_linktype_t linktype, 
     562                uint16_t *ethertype, 
     563                uint32_t *remaining) 
     564
     565        void *l; 
     566        switch(linktype) { 
     567                /* Packet Metadata headers, not layer2 headers */ 
     568                case TRACE_TYPE_80211_PRISM: 
     569                case TRACE_TYPE_80211_RADIO: 
     570                case TRACE_TYPE_LINUX_SLL: 
     571                        return NULL; 
     572 
     573                /* duck packets have no payload! */ 
     574                case TRACE_TYPE_DUCK: 
     575                        return NULL; 
     576 
     577                /* The payload is in these packets does 
     578                   not correspond to a genuine link-layer 
     579                   */ 
     580                case TRACE_TYPE_METADATA: 
     581                        return NULL; 
     582 
     583                case TRACE_TYPE_80211: 
     584                        return trace_get_payload_from_80211(link,ethertype,remaining); 
     585                case TRACE_TYPE_ETH: 
     586                        return trace_get_payload_from_ethernet(link,ethertype,remaining); 
     587                case TRACE_TYPE_NONE: 
     588                        if ((*(char*)link&0xF0) == 0x40) 
     589                                *ethertype=0x0800; 
     590                        else if ((*(char*)link&0xF0) == 0x60) 
     591                                *ethertype=0x86DD; 
     592                        return link; /* I love the simplicity */ 
     593                case TRACE_TYPE_PFLOG: 
     594                        return trace_get_payload_from_pflog(link,ethertype,remaining); 
     595                case TRACE_TYPE_PPP: 
     596                        return trace_get_payload_from_ppp(link,ethertype,remaining); 
     597                case TRACE_TYPE_ATM: 
     598                        l=trace_get_payload_from_atm(link,NULL,remaining); 
     599                        /* FIXME: We shouldn't skip llcsnap here, we should return 
     600                         * an ethertype for it (somehow) 
     601                         */ 
     602                        return (l ? trace_get_payload_from_llcsnap(l, 
     603                                                ethertype, remaining):NULL); 
     604                case TRACE_TYPE_LLCSNAP: 
     605                        return trace_get_payload_from_llcsnap(link,ethertype,remaining); 
     606 
     607                /* TODO: Unsupported */ 
     608                case TRACE_TYPE_HDLC_POS: 
     609                case TRACE_TYPE_POS: 
     610                case TRACE_TYPE_AAL5: 
     611                        return NULL; 
     612        } 
     613        return NULL; 
     614 
     615
     616 
     617DLLEXPORT void *trace_get_layer3(const libtrace_packet_t *packet, 
    556618                uint16_t *ethertype, 
    557619                uint32_t *remaining) 
     
    561623        void *link; 
    562624        uint32_t dummy_remaining; 
     625        libtrace_linktype_t linktype; 
     626 
     627        if (!ethertype) ethertype=&dummy_ethertype; 
     628 
     629        if (!remaining) remaining=&dummy_remaining; 
    563630 
    564631        /* use l3 cache */ 
    565632        if (packet->l3_header) 
    566633        { 
     634                link = trace_get_packet_buffer(packet,&linktype,remaining); 
     635 
     636                if (!link) 
     637                        return NULL; 
     638 
    567639                *ethertype = packet->l3_ethertype; 
    568                 *remaining -= (packet->l3_header - trace_get_link(packet)); 
     640                *remaining -= (packet->l3_header - link); 
     641 
    569642                return packet->l3_header; 
    570643        } 
    571644 
    572         if (!ethertype) ethertype=&dummy_ethertype; 
    573  
    574         if (!remaining) remaining=&dummy_remaining; 
    575  
    576         *remaining = trace_get_capture_length(packet); 
    577  
    578         link=trace_get_link(packet); 
    579  
    580         if (!link) 
    581                 return NULL; 
    582  
    583         iphdr = trace_get_payload_from_link( 
     645        link = trace_get_layer2(packet,&linktype,remaining); 
     646 
     647        iphdr = trace_get_payload_from_layer2( 
    584648                        link, 
    585                         trace_get_link_type(packet)
     649                        linktype
    586650                        ethertype, 
    587651                        remaining); 
     
    613677 
    614678        /* Store values in the cache for later */ 
    615         packet->l3_ethertype = *ethertype; 
    616         packet->l3_header = iphdr; 
     679        /* Cast away constness, nasty, but this is just a cache */ 
     680        ((libtrace_packet_t*)packet)->l3_ethertype = *ethertype; 
     681        ((libtrace_packet_t*)packet)->l3_header = iphdr; 
    617682 
    618683        return iphdr; 
    619684} 
    620685 
    621 DLLEXPORT void *trace_get_transport(libtrace_packet_t *packet,  
     686DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet,  
    622687                uint8_t *proto, 
    623688                uint32_t *remaining 
     
    632697 
    633698        if (!remaining) remaining=&dummy_remaining; 
    634  
    635         *remaining = trace_get_capture_length(packet); 
    636699 
    637700        transport = trace_get_layer3(packet,&ethertype,remaining); 
     
    829892} 
    830893 
    831 static 
    832 uint8_t *__trace_get_source_mac(void *link, libtrace_linktype_t *linktype, uint32_t *rem) { 
    833         libtrace_ether_t *ethptr = (libtrace_ether_t *) link; 
    834         uint16_t arphrd; 
     894DLLEXPORT uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { 
     895        void *link; 
     896        uint32_t remaining; 
     897        libtrace_linktype_t linktype; 
     898        assert(packet); 
     899        link = trace_get_layer2(packet,&linktype,&remaining); 
     900 
    835901        if (!link) 
    836902                return NULL; 
    837903         
    838         switch (*linktype) { 
     904        switch (linktype) { 
    839905                case TRACE_TYPE_ETH: 
    840                         return (uint8_t *)&ethptr->ether_shost
     906                        return (uint8_t *)&(((libtrace_ether_t*)link)->ether_shost)
    841907                case TRACE_TYPE_80211: 
    842908                        return get_source_mac_from_wifi(link); 
    843                 case TRACE_TYPE_80211_RADIO: 
    844                         link = trace_get_payload_from_radiotap( 
    845                                         link, linktype, rem); 
    846                         return __trace_get_source_mac(link, linktype, rem); 
    847                 case TRACE_TYPE_80211_PRISM: 
    848                         link = trace_get_payload_from_prism( 
    849                                         link, linktype, rem); 
    850                         return __trace_get_source_mac(link, linktype, rem); 
    851                 case TRACE_TYPE_LINUX_SLL: 
    852                         link = trace_get_payload_from_linux_sll( 
    853                                         link, &arphrd, rem); 
    854                         *linktype = arphrd_type_to_libtrace(arphrd); 
    855                         return __trace_get_source_mac(link, linktype, rem); 
     909                /* These packets don't have MAC addresses */ 
    856910                case TRACE_TYPE_POS: 
    857911                case TRACE_TYPE_NONE: 
     
    861915                case TRACE_TYPE_DUCK: 
    862916                case TRACE_TYPE_METADATA: 
    863                         return NULL; 
    864                 default: 
     917                case TRACE_TYPE_AAL5: 
     918                case TRACE_TYPE_LLCSNAP: 
     919                case TRACE_TYPE_PPP: 
     920                        return NULL; 
     921 
     922                /* Metadata headers should already be skipped */ 
     923                case TRACE_TYPE_LINUX_SLL: 
     924                case TRACE_TYPE_80211_PRISM: 
     925                case TRACE_TYPE_80211_RADIO: 
     926                        assert(!"Metadata headers should already be skipped"); 
    865927                        break; 
    866928        } 
    867         fprintf(stderr,"%s not implemented for linktype %i\n", __func__, *linktype); 
     929        fprintf(stderr,"%s not implemented for linktype %i\n", __func__, linktype); 
    868930        assert(0); 
    869931        return NULL; 
    870932} 
    871933 
    872 DLLEXPORT uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { 
    873         if (packet == NULL)  
    874                 return NULL; 
    875         void *link = trace_get_link(packet); 
    876         uint32_t len = trace_get_capture_length(packet); 
    877         libtrace_linktype_t lt = trace_get_link_type(packet); 
    878         return __trace_get_source_mac(link, &lt, &len); 
    879 
    880  
    881 DLLEXPORT uint8_t *trace_get_destination_mac(libtrace_packet_t *packet) { 
    882         void *link = trace_get_link(packet); 
     934DLLEXPORT uint8_t *trace_get_destination_mac(libtrace_packet_t *packet)  
     935
     936        void *link; 
     937        libtrace_linktype_t linktype; 
     938        uint32_t remaining; 
     939 
     940        link = trace_get_layer2(packet,&linktype,&remaining); 
     941 
    883942        libtrace_80211_t *wifi; 
    884943        libtrace_ether_t *ethptr = (libtrace_ether_t*)link; 
     944 
     945 
    885946        if (!link) 
    886947                return NULL; 
    887         switch (trace_get_link_type(packet)) { 
     948 
     949        switch (linktype) { 
    888950                case TRACE_TYPE_80211: 
    889951                        wifi=(libtrace_80211_t*)link; 
     
    928990                addr=(struct sockaddr*)&dummy; 
    929991 
    930         remaining = trace_get_capture_length(packet); 
    931  
    932992        l3 = trace_get_layer3(packet,&ethertype,&remaining); 
    933993 
     
    9811041        if (!addr) 
    9821042                addr=(struct sockaddr*)&dummy; 
    983  
    984         remaining = trace_get_capture_length(packet); 
    9851043 
    9861044        l3 = trace_get_layer3(packet,&ethertype,&remaining); 
  • trunk/lib/trace.c

    r1268 r1269  
    646646                (libtrace_packet_t *)malloc(sizeof(libtrace_packet_t)); 
    647647        dest->trace=packet->trace; 
    648         dest->buffer=malloc( 
    649                         trace_get_framing_length(packet) 
    650                         +trace_get_capture_length(packet)); 
     648        dest->buffer=malloc(65536); 
    651649        dest->header=dest->buffer; 
    652650        dest->payload=(void*) 
     
    869867} 
    870868 
    871 DLLEXPORT size_t trace_get_capture_length(libtrace_packet_t *packet)  
     869DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet)  
    872870{ 
    873871        /* Cache the capture length */ 
     
    875873                if (!packet->trace->format->get_capture_length) 
    876874                        return ~0U; 
    877                 packet->capture_length =  
     875                /* Cast away constness because this is "just" a cache */ 
     876                ((libtrace_packet_t*)packet)->capture_length =  
    878877                        packet->trace->format->get_capture_length(packet); 
    879878        } 
     
    10021001#ifdef HAVE_BPF 
    10031002        void *linkptr = 0; 
     1003        libtrace_linktype_t linktype; 
    10041004        assert(filter); 
    10051005 
    10061006        /* If this isn't a real packet, then fail */ 
    1007         linkptr = trace_get_link(packet); 
     1007        linkptr = trace_get_packet_buffer(packet,&linktype,NULL); 
    10081008        if (!linkptr) { 
    10091009                trace_set_err(packet->trace, 
     
    10141014        if (filter->filterstring && ! filter->flag) { 
    10151015                pcap_t *pcap = NULL; 
    1016                 libtrace_linktype_t linktype=trace_get_link_type(packet); 
    10171016                if (linktype==(libtrace_linktype_t)-1) { 
    10181017                        trace_set_err(packet->trace, 
     
    10561055#ifdef HAVE_BPF 
    10571056        void *linkptr = 0; 
    1058         unsigned int clen = 0; 
     1057        uint32_t clen = 0; 
    10591058        bool free_packet_needed = false; 
    10601059        int ret; 
     
    10841083        } 
    10851084         
    1086         linkptr = trace_get_link(packet_copy); 
     1085        linkptr = trace_get_packet_buffer(packet_copy,NULL,&clen); 
    10871086        if (!linkptr) { 
    10881087                if (free_packet_needed) { 
     
    11021101        } 
    11031102 
    1104         clen = trace_get_capture_length(packet_copy); 
    1105  
    11061103        assert(filter->flag); 
    1107         ret=bpf_filter(filter->filter.bf_insns,(u_char*)linkptr,clen,clen); 
     1104        ret=bpf_filter(filter->filter.bf_insns,(u_char*)linkptr,(unsigned int)clen,(unsigned int)clen); 
    11081105        if (free_packet_needed) { 
    11091106                trace_destroy_packet(packet_copy);