Ignore:
Timestamp:
03/26/08 10:45:36 (13 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:
f52bcdd
Parents:
e632f2f
Message:
  • Added prepare_packet functions to all formats, primarily to support translating RT packets into the appropriate format. These functions are all used internally as well, as most formats still need to "prepare" packets that have been read by setting pointers, updating loss counters etc.
  • Also added a trace_prepare_packet function, but this is not made available externally at this stage
  • Added init_format_data functions to some formats to initialise format data structures in cases where the init_trace function does more than just that
  • Refactored rt packet reading code to use the new trace_prepare_packet functionality - also did a lot of tidying of the code
  • Added missing RT type for BPF format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcapfile.c

    re632f2f rf0fb38f  
    223223}
    224224
     225static int pcapfile_prepare_packet(libtrace_t *libtrace,
     226                libtrace_packet_t *packet, void *buffer,
     227                libtrace_rt_types_t rt_type, uint32_t flags) {
     228
     229        if (packet->buffer != buffer &&
     230                        packet->buf_control == TRACE_CTRL_PACKET) {
     231                free(packet->buffer);
     232        }
     233
     234        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     235                packet->buf_control = TRACE_CTRL_PACKET;
     236        } else
     237                packet->buf_control = TRACE_CTRL_EXTERNAL;
     238       
     239       
     240        packet->buffer = buffer;
     241        packet->header = buffer;
     242        packet->payload = (char*)packet->buffer
     243                + sizeof(libtrace_pcapfile_pkt_hdr_t);
     244        packet->type = rt_type;
     245
     246        if (libtrace->format_data == NULL) {
     247                if (pcapfile_init_input(libtrace))
     248                        return -1;
     249        }
     250       
     251        return 0;
     252}
     253
    225254static int pcapfile_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
    226255{
    227256        int err;
    228 
     257        uint32_t flags = 0;
     258       
    229259        assert(libtrace->format_data);
    230260
     
    234264        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    235265                packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    236                 packet->buf_control = TRACE_CTRL_PACKET;
    237         }
    238 
     266        }
     267
     268        flags |= TRACE_PREP_OWN_BUFFER;
     269       
    239270        err=libtrace_io_read(DATA(libtrace)->file,
    240271                        packet->buffer,
     
    249280                return 0;
    250281        }
    251 
    252         packet->header = packet->buffer;
    253 
    254282
    255283        err=libtrace_io_read(DATA(libtrace)->file,
     
    267295        }
    268296
    269         packet->payload = (char*)packet->buffer
    270                 + sizeof(libtrace_pcapfile_pkt_hdr_t);
     297        if (pcapfile_prepare_packet(libtrace, packet, packet->buffer,
     298                                packet->type, flags)) {
     299                return -1;
     300        }
    271301       
    272302        return sizeof(libtrace_pcapfile_pkt_hdr_t)
     
    544574        pcapfile_fin_output,            /* fin_output */
    545575        pcapfile_read_packet,           /* read_packet */
     576        pcapfile_prepare_packet,        /* prepare_packet */
    546577        NULL,                           /* fin_packet */
    547578        pcapfile_write_packet,          /* write_packet */
Note: See TracChangeset for help on using the changeset viewer.