Changeset f0fb38f for lib/format_tsh.c


Ignore:
Timestamp:
03/26/08 10:45:36 (14 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_tsh.c

    rd186e42 rf0fb38f  
    8989}
    9090
     91static int tsh_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet,
     92                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
     93        if (packet->buffer != buffer &&
     94                        packet->buf_control == TRACE_CTRL_PACKET) {
     95                free(packet->buffer);
     96        }
     97
     98        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     99                packet->buf_control = TRACE_CTRL_PACKET;
     100        } else
     101                packet->buf_control = TRACE_CTRL_EXTERNAL;
     102
     103
     104        packet->buffer = buffer;
     105        packet->header = buffer;
     106        packet->type = rt_type;
     107        packet->payload = (char *)packet->buffer + sizeof(tsh_pkt_header_t);
     108
     109        if (libtrace->format_data == NULL) {
     110                if (tsh_init_input(libtrace))
     111                        return -1;
     112        }
     113
     114        return 0;
     115}
     116
    91117static int tsh_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    92118        int numbytes;
    93119        void *buffer2 = packet->buffer;
     120        uint32_t flags = 0;
    94121
    95122        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    96123                packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    97                 packet->buf_control = TRACE_CTRL_PACKET;
    98124                if (!packet->buffer) {
    99125                        trace_set_err(libtrace, errno,
     
    103129        }
    104130
    105         packet->header = packet->buffer;
     131        flags |= TRACE_PREP_OWN_BUFFER;
    106132        packet->type = TRACE_RT_DATA_TSH;
    107133
     
    122148
    123149        buffer2 = (char*)buffer2 + numbytes;
    124         packet->payload = buffer2;
    125150
    126151        /* Read the IP header */
     
    147172                return -1;
    148173        }
     174       
     175        if (tsh_prepare_packet(libtrace, packet, packet->buffer, packet->type,
     176                                flags)) {
     177                return -1;
     178        }
     179
    149180
    150181        return 80;
     
    205236        NULL,                           /* fin_output */
    206237        tsh_read_packet,                /* read_packet */
     238        tsh_prepare_packet,             /* prepare_packet */
    207239        NULL,                           /* fin_packet */
    208240        NULL,                           /* write_packet */
     
    249281        NULL,                           /* fin_output */
    250282        tsh_read_packet,                /* read_packet */
     283        tsh_prepare_packet,             /* prepare_packet */
    251284        NULL,                           /* fin_packet */
    252285        NULL,                           /* write_packet */
Note: See TracChangeset for help on using the changeset viewer.