Changeset 3a14f3b for lib/trace.c


Ignore:
Timestamp:
09/14/07 16:05:43 (14 years ago)
Author:
Scott Raynel <smr26@…>
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:
a81d2fc
Parents:
4c1302b
Message:

Allow libtrace applications to create filters based on pre-compiled BPF
bytecode as well as filterstrings. See trace_create_filter_from_bytecode()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r9e6b38b r3a14f3b  
    964964}
    965965
     966/** Setup a BPF filter based on pre-compiled byte-code.
     967 * @param bf_insns      A pointer to the start of the byte-code
     968 * @param bf_len        The number of BPF instructions
     969 * @returns             an opaque pointer to a libtrace_filter_t object
     970 * @note                The supplied byte-code is not checked for correctness.
     971 * @author              Scott Raynel
     972 */
     973DLLEXPORT libtrace_filter_t *
     974trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len)
     975{
     976#ifndef HAVE_BPF
     977        fprintf(stderr, "This version of libtrace does not have BPF support\n");
     978        return NULL;
     979#else
     980        struct libtrace_filter_t *filter = (struct libtrace_filter_t *)
     981                malloc(sizeof(struct libtrace_filter_t));
     982        filter->filter.bf_insns = (struct bpf_insn *)
     983                malloc(sizeof(struct bpf_insn) * bf_len);
     984       
     985        memcpy(filter->filter.bf_insns, bf_insns,
     986                        bf_len * sizeof(struct bpf_insn));
     987       
     988        filter->filter.bf_len = bf_len;
     989        filter->filterstring = NULL;
     990        /* "flag" indicates that the filter member is valid */
     991        filter->flag = 1;
     992       
     993        return filter;
     994#endif
     995}
     996
    966997/* setup a BPF filter
    967998 * @param filterstring a char * containing the bpf filter string
Note: See TracChangeset for help on using the changeset viewer.