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_atmhdr.c

    rf2fae49 rf0fb38f  
    5656}
    5757
     58static int atmhdr_prepare_packet(libtrace_t *libtrace,
     59                libtrace_packet_t *packet, void *buffer,
     60                libtrace_rt_types_t rt_type, uint32_t flags) {
     61
     62        if (packet->buffer != buffer &&
     63                        packet->buf_control == TRACE_CTRL_PACKET) {
     64                free(packet->buffer);
     65        }
     66
     67        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     68                packet->buf_control = TRACE_CTRL_PACKET;
     69        } else
     70                packet->buf_control = TRACE_CTRL_EXTERNAL;
     71
     72        packet->buffer = buffer;
     73        packet->header = buffer;
     74        packet->payload = (void*)((char*)packet->buffer +
     75                        libtrace->format->get_framing_length(packet));
     76        packet->type = rt_type;
     77
     78        if (libtrace->format_data == NULL) {
     79                if (atmhdr_init_input(libtrace))
     80                        return -1;
     81        }
     82        return 0;
     83}
     84
    5885static int atmhdr_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    5986        int numbytes;
    6087        void *buffer;
    61 
     88        uint32_t flags = 0;
     89       
    6290        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    63                 packet->buf_control = TRACE_CTRL_PACKET;
    6491                packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    6592        }
    6693        buffer = packet->buffer;
    67 
     94        flags |= TRACE_PREP_OWN_BUFFER;
     95       
    6896        packet->type = TRACE_RT_DATA_ATMHDR;
    6997
     
    76104        }
    77105
    78         packet->header = packet->buffer;
    79         packet->payload = (void*)((char*)packet->buffer +
    80                         libtrace->format->get_framing_length(packet));
    81 
     106        if (atmhdr_prepare_packet(libtrace, packet, buffer,
     107                                TRACE_RT_DATA_ATMHDR, flags)) {
     108                return -1;
     109        }
     110                               
     111       
    82112        return 12;
    83113}
     
    117147        NULL,                           /* fin_output */
    118148        atmhdr_read_packet,             /* read_packet */
    119         NULL,                           /* fin_packet */
     149        atmhdr_prepare_packet,          /* prepare_packet */
     150        NULL,                           /* fin_packet */
    120151        NULL,                           /* write_packet */
    121152        atmhdr_get_link_type,           /* get_link_type */
Note: See TracChangeset for help on using the changeset viewer.