Changeset 91c9552 for lib/trace.c


Ignore:
Timestamp:
02/23/06 11:21:19 (16 years ago)
Author:
Perry Lorier <perry@…>
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:
aa62105
Parents:
c2d5f23
Message:

Documentation fixes
Make bpf return valid errors
Add trace_copy_packet()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    rc1db742 r91c9552  
    523523}
    524524
     525libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet) {
     526        libtrace_packet_t *dest = malloc(sizeof(libtrace_packet_t));
     527        dest->trace=packet->trace;
     528        dest->buffer=malloc(
     529                        trace_get_framing_length(packet)
     530                        +trace_get_capture_length(packet));
     531        dest->header=dest->buffer;
     532        dest->payload=(void*)
     533                ((char*)dest->buffer+trace_get_framing_length(packet));
     534        dest->size=packet->size;
     535        dest->type=packet->type;
     536        dest->buf_control=TRACE_CTRL_PACKET;
     537        memcpy(dest->header,packet->header,trace_get_framing_length(packet));
     538        memcpy(dest->payload,packet->payload,trace_get_capture_length(packet));
     539}
     540
    525541/** Destroy a packet object
    526542 *
     
    528544 */
    529545void trace_destroy_packet(struct libtrace_packet_t **packet) {
    530         if ((*packet)->buf_control) {
     546        if ((*packet)->buf_control == TRACE_CTRL_PACKET) {
    531547                free((*packet)->buffer);
    532548        }
     
    12891305        linkptr = trace_get_link(packet);
    12901306        if (!linkptr) {
     1307                trace_set_err(TRACE_ERR_BAD_PACKET,"Packet has no payload");
    12911308                return -1;
    12921309        }
     
    13011318                                        1, 0)) {
    13021319                        pcap_close(pcap);
     1320                        trace_set_err(TRACE_ERR_BAD_PACKET,
     1321                                        "Packet has no payload");
    13031322                        return -1;
    13041323                }
     
    13121331}
    13131332
    1314 /* apply a BPF filter
    1315  * @param filter the filter opaque pointer
    1316  * @param packet the packet opaque pointer
    1317  * @returns 0 if the filter fails, 1 if it succeeds
    1318  * @author Daniel Lawson
    1319  */
    13201333int trace_bpf_filter(struct libtrace_filter_t *filter,
    13211334                        const struct libtrace_packet_t *packet) {
     
    13331346         * link type was
    13341347         */
    1335         trace_bpf_compile(filter,packet);
     1348        if (trace_bpf_compile(filter,packet)==-1)
     1349                return -1;
    13361350       
    13371351        clen = trace_get_capture_length(packet);
Note: See TracChangeset for help on using the changeset viewer.