Ignore:
Timestamp:
03/26/08 10:45:36 (5 years ago)
Author:
spa1
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
  • trunk/lib/libtrace_int.h

    r1330 r1332  
    167167                                                                PRINTF(3,4); 
    168168 
     169 
     170/*  
     171 * 
     172 * The basic idea of this function is that it will take the data pointed to 
     173 * by 'buffer' and treat it as a packet of the same format type as the  
     174 * libtrace_t pointed to by 'trace', including the format framing (e.g. an 
     175 * erf header for erf and dag formats, a pcap header for pcap formats). 
     176 *  
     177 * The libtrace packet pointed to by 'packet' will then have its internal 
     178 * pointers and values replaced with ones that describe the packet in 'buffer'. 
     179 *  
     180 * 'rt_type' is used to set packet->type while 'flags' is relatively  
     181 * self-explanatory. Definitions of the accepted flags will be provided below. 
     182 * 
     183 * The primary use of this function is to allow rt_read_packet to nicely 
     184 * convert packets from the RT format back to the format that they were 
     185 * originally captured with, as RT essentially encapsulates the original trace 
     186 * format. We've decided to not make this function available via the API 
     187 * because there are a number of issues that can arise if it is not used 
     188 * very carefully and there are few situations outside of the RT case where 
     189 * you'd want to do something like this anyway. 
     190 * 
     191 * Returns 0 if successful, -1 if something goes horribly wrong 
     192 */ 
     193int trace_prepare_packet(libtrace_t *trace, libtrace_packet_t *packet, 
     194                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags); 
     195 
     196/* Flags for prepare_packet functions */ 
     197/*-------------------------------------*/ 
     198/* If set, the memory pointed to by 'buffer' is malloc()'d and libtrace should 
     199 * undertake ownership of that memory. If not set, the memory is treated as 
     200 * externally-owned and will not be freed by libtrace when the packet is 
     201 * destroyed. */ 
     202#define TRACE_PREP_OWN_BUFFER   1 
     203 
     204                                                                 
    169205typedef struct libtrace_sll_header_t { 
    170206        uint16_t pkttype;               /* packet type */ 
     
    247283         */ 
    248284        int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet); 
     285        /** prepares a packet for general libtrace usage 
     286         * updates internal trace and packet details, such as payload pointers, 
     287         * loss counters and packet types. 
     288         * Intended (at this stage) only for internal use, particularly by 
     289         * RT which needs to decapsulate RT packets */ 
     290        int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet, 
     291                        void *buffer, libtrace_rt_types_t rt_type,  
     292                        uint32_t flags); 
    249293        /** finalise a packet 
    250294         * cleanup any resources used by a packet that can't be reused for 
Note: See TracChangeset for help on using the changeset viewer.