Changeset 4811b1e


Ignore:
Timestamp:
03/16/10 10:55:34 (11 years ago)
Author:
Shane Alcock <salcock@…>
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:
ac7037b
Parents:
7fc0eaa2
Message:
  • Fixed bug where the header pointer was not set correctly for packets that had no payload other than the PCAP header
  • Added a few extra asserts so that we can have a slightly more graceful exit when the header pointer isn't set correctly rather than just segfaulting :)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcapfile.c

    r238d50a r4811b1e  
    345345         * misinterpret as EOF! */
    346346        if (bytes_to_read == 0) {
     347                packet->header = packet->buffer;
    347348                return sizeof(libtrace_pcapfile_pkt_hdr_t);
    348349        }
     
    434435        assert(hdr.caplen < LIBTRACE_PACKET_BUFSIZE);
    435436        /* PCAP doesn't include the FCS in its wire length value, but we do */
    436         if (linktype==TRACE_TYPE_ETH)
     437        if (linktype==TRACE_TYPE_ETH) {
    437438                if (trace_get_wire_length(packet) >= 4) {
    438439                        hdr.wirelen = trace_get_wire_length(packet)-4;
     
    441442                        hdr.wirelen = 0;
    442443                }
     444        }
    443445        else
    444446                hdr.wirelen = trace_get_wire_length(packet);
     
    544546                const libtrace_packet_t *packet)
    545547{
    546         libtrace_pcapfile_pkt_hdr_t *hdr =
    547                 (libtrace_pcapfile_pkt_hdr_t*)packet->header;
     548        libtrace_pcapfile_pkt_hdr_t *hdr;
    548549        struct timeval ts;
     550       
     551        assert(packet->header);
     552       
     553        hdr = (libtrace_pcapfile_pkt_hdr_t*)packet->header;
    549554        ts.tv_sec = swapl(packet->trace,hdr->ts_sec);
    550555        ts.tv_usec = swapl(packet->trace,hdr->ts_usec);
     
    554559
    555560static int pcapfile_get_capture_length(const libtrace_packet_t *packet) {
    556         libtrace_pcapfile_pkt_hdr_t *pcapptr
    557                 = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
     561        libtrace_pcapfile_pkt_hdr_t *pcapptr;
     562
     563        assert(packet->header);
     564        pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    558565
    559566        return swapl(packet->trace,pcapptr->caplen);
     
    561568
    562569static int pcapfile_get_wire_length(const libtrace_packet_t *packet) {
    563         libtrace_pcapfile_pkt_hdr_t *pcapptr
    564                 = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
     570        libtrace_pcapfile_pkt_hdr_t *pcapptr;
     571         
     572        assert(packet->header);
     573
     574        pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    565575        if (packet->type==pcap_linktype_to_rt(TRACE_DLT_EN10MB))
    566576                /* Include the missing FCS */
     
    589599        libtrace_pcapfile_pkt_hdr_t *pcapptr = 0;
    590600        assert(packet);
     601        assert(packet->header);
    591602        if (size > trace_get_capture_length(packet)) {
    592603                /* Can't make a packet larger */
Note: See TracChangeset for help on using the changeset viewer.