Changeset 2137b49 for lib/libtrace.h


Ignore:
Timestamp:
08/05/04 16:14:14 (17 years ago)
Author:
Daniel Lawson <dlawson@…>
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:
670d3de
Parents:
b535184
Message:

changes to new api

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h

    rbb313ef r2137b49  
    2929 */
    3030
    31 #ifndef _LIBTRACE_H_
    32 #define _LIBTRACE_H_
     31#ifndef LIBTRACE_H
     32#define LIBTRACE_H
    3333
    3434#include <features.h>
     
    7777       
    7878/** Opaque structure holding information about a bpf filter */
    79 
    8079struct libtrace_filter_t;
     80
     81/** Opaque structure holding information about a packet */
     82#define LIBTRACE_PACKET_BUFSIZE 65536
     83struct libtrace_packet_t {
     84        struct libtrace_t *trace;
     85        char buffer[LIBTRACE_PACKET_BUFSIZE];
     86        size_t size;
     87        uint8_t status;
     88};
     89
    8190/** Structure for dealing with IP packets */
    8291struct libtrace_ip
     
    197206 *  and an error is output to stdout.
    198207 */
    199 struct libtrace_t *create_trace(char *uri);
     208struct libtrace_t *trace_create(char *uri);
    200209
    201210/** Close a trace file, freeing up any resources it may have been using
    202211 *
    203212 */
    204 void destroy_trace(struct libtrace_t *rtclient);
     213void trace_destroy(struct libtrace_t *trace);
    205214
    206215/** Read one packet from the trace into buffer
    207216 *
    208  * @param libtrace      the trace to read from
    209  * @param buffer        the buffer to read into
    210  * @param len           the length of the buffer
    211  * @param status        status of the trace (only used for RTClients)
    212  * @returns number of bytes copied, -1 on error, or 0 at EOF
    213  *
    214  * @note the buffer must be at least as large as the largest packet (plus
    215  * link layer, and trace packet metadata overhead)
    216  */
    217 int libtrace_read_packet(struct libtrace_t *rtclient, void *buffer, size_t len, int *status);
     217 * @param libtrace      the libtrace opaque pointer
     218 * @param packet        the packet opaque pointer
     219 * @returns false if it failed to read a packet
     220 *
     221 */
     222int trace_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet);
    218223
    219224/** get a pointer to the link layer
    220  * @param libtrace      a pointer to the trace object returned from gettrace
    221  * @param buffer        a pointer to a filled in buffer
    222  * @param buflen        a pointer to the size of the buffer
     225 * @param packet        the packet opaque pointer
    223226 *
    224227 * @returns a pointer to the link layer, or NULL if there is no link layer
     
    227230 * this is
    228231 */
    229 void *get_link(struct libtrace_t *libtrace, void *buffer, int buflen);
     232void *trace_get_link(struct libtrace_packet_t *packet);
    230233
    231234/** get a pointer to the IP header (if any)
    232  * @param libtrace      a pointer to the trace object returned from gettrace
    233  * @param buffer        a pointer to a filled in buffer
    234  * @param buflen        a pointer to the size of the buffer
     235 * @param packet        the packet opaque pointer
    235236 *
    236237 * @returns a pointer to the IP header, or NULL if there is not an IP packet
    237238 */
    238 struct libtrace_ip *get_ip(struct libtrace_t *libtrace, void *buffer, int buflen);
     239struct libtrace_ip *trace_get_ip(struct libtrace_packet_t *packet);
    239240
    240241/** get a pointer to the TCP header (if any)
    241  * @param libtrace      a pointer to the trace object returned from gettrace
    242  * @param buffer        a pointer to a filled in buffer
    243  * @param buflen        a pointer to the size of the buffer
     242 * @param packet        the packet opaque pointer
    244243 *
    245244 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet
    246245 */
    247 struct libtrace_tcp *get_tcp(struct libtrace_t *libtrace, void *buffer, int buflen);
     246struct libtrace_tcp *trace_get_tcp(struct libtrace_packet_t *packet);
    248247
    249248/** get a pointer to the UDP header (if any)
    250  * @param libtrace      a pointer to the trace object returned from gettrace
    251  * @param buffer        a pointer to a filled in buffer
    252  * @param buflen        a pointer to the size of the buffer
     249 * @param packet        the packet opaque pointer
    253250 *
    254251 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet
    255252 */
    256 struct libtrace_udp *get_udp(struct libtrace_t *libtrace, void *buffer, int buflen);
     253struct libtrace_udp *trace_get_udp(struct libtrace_packet_t *packet);
    257254
    258255/** get a pointer to the ICMP header (if any)
    259  * @param libtrace      a pointer to the trace object returned from gettrace
    260  * @param buffer        a pointer to a filled in buffer
    261  * @param buflen        a pointer to the size of the buffer
     256 * @param packet        the packet opaque pointer
    262257 *
    263258 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet
    264259 */
    265 struct libtrace_icmp *get_icmp(struct libtrace_t *libtrace, void *buffer, int buflen);
     260struct libtrace_icmp *trace_get_icmp(struct libtrace_packet_t *packet);
    266261
    267262/** Get the current time in DAG time format
    268  * @param libtrace the libtrace opaque pointer
    269  * @param buffer a pointer to a filled in buffer
    270  * @param buflen the length of the buffer
     263 * @param packet        the packet opaque pointer
     264 *
    271265 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
    272266 * past 1970-01-01, the lower 32bits are partial seconds)
    273267 * @author Daniel Lawson
    274268 */
    275 uint64_t get_erf_timestamp(struct libtrace_t *libtrace, void *buffer, int buflen);
     269uint64_t trace_get_erf_timestamp(struct libtrace_packet_t *packet);
    276270
    277271/** Get the current time in struct timeval
    278  * @param libtrace the libtrace opaque pointer
    279  * @param buffer a pointer to a filled in buffer
    280  * @param buflen the length of the buffer
     272 * @param packet        the packet opaque pointer
     273 *
    281274 * @returns time that this packet was seen in a struct timeval
    282275 * @author Daniel Lawson
    283276 * @author Perry Lorier
    284277 */
    285 
    286 struct timeval get_timeval(struct libtrace_t *libtrace, void *buffer, int buflen);
     278struct timeval trace_get_timeval(struct libtrace_packet_t *packet);
    287279
    288280/** Get the current time in floating point seconds
    289  * @param libtrace the libtrace opaque pointer
    290  * @param buffer a pointer to a filled in buffer
    291  * @param buflen the length of the buffer
     281 * @param packet        the packet opaque pointer
     282 *
    292283 * @returns time that this packet was seen in 64bit floating point seconds
    293284 * @author Perry Lorier
    294285 */
    295 double get_seconds(struct libtrace_t *libtrace, void *buffer, int buflen);
     286double trace_get_seconds(struct libtrace_packet_t *packet);
    296287
    297288/** Get the size of the packet in the trace
    298  * @param libtrace the libtrace opaque pointer
    299  * @param buffer a pointer to a filled in buffer
    300  * @param buflen the length of the buffer
     289 * @param packet        the packet opaque pointer
    301290 * @returns the size of the packet in the trace
    302291 * @author Perry Lorier
     
    309298 */
    310299
    311 int get_capture_length(struct libtrace_t *libtrace, void *buffer, int buflen);
     300int trace_get_capture_length(struct libtrace_packet_t *packet);
    312301
    313302/** Get the size of the packet as it was seen on the wire.
    314  * @param libtrace the libtrace opaque pointer
    315  * @param buffer a pointer to a filled in buffer
    316  * @param buflen the length of the buffer
     303 * @param packet        the packet opaque pointer
    317304 * @returns the size of the packet as it was on the wire.
    318305 * @author Perry Lorier
     
    322309 */
    323310
    324 int get_wire_length(struct libtrace_t *libtrace, void *buffer, int buflen);
     311int trace_get_wire_length(struct libtrace_packet_t *packet);
    325312
    326313/** Link layer types
     
    335322
    336323/** Get the type of the link layer
    337  * @param libtrace the libtrace opaque pointer
    338  * @param buffer a pointer to a filled in buffer
    339  * @param buflen the length of the buffer
     324 * @param packet        the packet opaque pointer
    340325 * @returns libtrace_linktype_t
    341326 * @author Perry Lorier
     
    343328 */
    344329
    345 inline libtrace_linktype_t get_link_type(
    346                 struct libtrace_t *libtrace,
    347                 void *buffer,
    348                 int buflen);   
     330inline libtrace_linktype_t trace_get_link_type(struct libtrace_packet_t *packet);
    349331
    350332/** Get the destination MAC addres
    351  * @param libtrace the libtrace opaque pointer
    352  * @param buffer a pointer to a filled in buffer
    353  * @param buflen the length of the buffer
     333 * @param packet        the packet opaque pointer
    354334 * @returns a pointer to the destination mac, (or NULL if there is no
    355335 * destination MAC)
    356336 * @author Perry Lorier
    357337 */
    358 uint8_t *get_destination_mac(struct libtrace_t *libtrace,
    359                         void *buffer,
    360                         int buflen);
     338uint8_t *trace_get_destination_mac(struct libtrace_packet_t *packet);
    361339
    362340/** Get the source MAC addres
    363  * @param libtrace the libtrace opaque pointer
    364  * @param buffer a pointer to a filled in buffer
    365  * @param buflen the length of the buffer
     341 * @param packet        the packet opaque pointer
    366342 * @returns a pointer to the source mac, (or NULL if there is no source MAC)
    367343 * @author Perry Lorier
    368344 */
    369 uint8_t *get_source_mac(struct libtrace_t *libtrace,
    370                         void *buffer,
    371                         int buflen);
     345uint8_t *trace_get_source_mac(struct libtrace_packet_t *packet);
    372346
    373347/** Get the direction flag, if it has one
    374  * @param libtrace the libtrace opaque pointer
    375  * @param buffer a point to a fille in buffer
    376  * @param buflen the length of the buffer
     348 * @param packet        the packet opaque pointer
    377349 * @returns a signed value containing the direction flag, or -1 if this is not supported
    378350 * @author Daniel Lawson
    379351 */
    380 int8_t get_direction(struct libtrace_t *libtrace,
    381                       void *buffer,
    382                       int buflen);
     352int8_t trace_get_direction(struct libtrace_packet_t *packet);
    383353
    384354/** Event types */
     
    395365 *  TRACE_EVENT_PACKET  Packet arrived in <buffer> with size <size>
    396366 */
    397 libtrace_event_t libtrace_event(struct libtrace_t *trace,
    398                         int *fd,double *seconds,
    399                         void *buffer, size_t len, int *size);
     367libtrace_event_t trace_event(struct libtrace_packet_t *packet,
     368                int *fd,double *seconds);
    400369
    401370/** setup a BPF filter
     
    404373 * @author Daniel Lawson
    405374 */
    406 struct libtrace_filter_t *libtrace_bpf_setfilter(const char *filterstring);
     375struct libtrace_filter_t *trace_bpf_setfilter(const char *filterstring);
    407376
    408377/** apply a BPF filter
    409  * @param libtrace the libtrace opaque pointer
    410  * @param filter the filter opaque pointer
    411  * @param buffer a pointer to a filled buffer
    412  * @param buflen the length of the buffer
     378 * @param filter        the filter opaque pointer
     379 * @param packet        the packet opaque pointer
    413380 * @returns the return value from bpf_filter
    414381 * @author Daniel Lawson
    415382 */
    416 int libtrace_bpf_filter(struct libtrace_t *trace,
    417                         struct libtrace_filter_t *filter,
    418                         void *buffer,
    419                         int buflen);
     383int trace_bpf_filter(struct libtrace_filter_t *filter,
     384                struct libtrace_packet_t *packet);
    420385
    421386#ifdef __cplusplus
    422387} // extern "C"
    423 #endif // #ifdef _cplusplus
    424 #endif // _LIBTRACE_H_
     388#endif // #ifdef __cplusplus
     389#endif // LIBTRACE_H_
Note: See TracChangeset for help on using the changeset viewer.