Changeset d47ca18 for lib


Ignore:
Timestamp:
06/21/17 15:41:47 (4 years ago)
Author:
Richard Sanger <rsanger@…>
Branches:
cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
Children:
e9c089a
Parents:
f398c61
Message:

Fix issue #49 compile issues when missing BPF header file

If pcap was installed but somehow the BPF header was missing.
Libtrace was using two different macros HAVE_BPF and HAVE_BPF_FILTER
to determine if BPF was installed.

HAVE_BPF_FILTER was set if pcap was found, wereas HAVE_BPF was
set if the BPF header was found.

This removes and replaces HAVE_BPF_FILTER with HAVE_BPF.
It also adds ifdef blocks around formats that try to install
BPF filters directly as needed.

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux_common.c

    rdb84bb2 rd47ca18  
    6161static int linuxnative_configure_bpf(libtrace_t *libtrace,
    6262                libtrace_filter_t *filter) {
    63 #ifdef HAVE_LIBPCAP
     63#if defined(HAVE_LIBPCAP) && defined(HAVE_BPF)
    6464        struct ifreq ifr;
    6565        unsigned int arphrd;
     
    125125        return 0;
    126126#else
    127         return -1
     127        return -1;
    128128#endif
    129129}
     
    404404         * pre-compiled.
    405405         */
     406#ifdef HAVE_BPF
    406407        if (filter != NULL) {
    407408                /* Check if the filter was successfully compiled. If not,
     
    424425                }
    425426        }
     427#endif
    426428
    427429        /* Consume any buffered packets that were received before the socket
  • lib/format_pcap.c

    r5e3f16c rd47ca18  
    128128
    129129        /* If a filter has been configured, compile and apply it */
     130#ifdef HAVE_BPF
    130131        if (DATA(libtrace)->filter) {
    131132                if (DATA(libtrace)->filter->flag == 0) {
     
    143144                }
    144145        }
     146#endif
    145147        return 0;
    146148}
     
    152154        switch(option) {
    153155                case TRACE_OPTION_FILTER:
     156#ifdef HAVE_BPF
    154157                        DATA(libtrace)->filter=data;
    155158                        return 0;
     159#else
     160                        return -1;
     161#endif
    156162                case TRACE_OPTION_SNAPLEN:
    157163                        /* Snapping isn't supported directly, so fall thru
     
    211217        switch(option) {
    212218                case TRACE_OPTION_FILTER:
     219#ifdef HAVE_BPF
    213220                        DATA(libtrace)->filter=(libtrace_filter_t*)data;
    214221                        return 0;
     222#else
     223                        return -1;
     224#endif
    215225                case TRACE_OPTION_SNAPLEN:
    216226                        DATA(libtrace)->snaplen=*(int*)data;
     
    298308#endif
    299309        /* Set a filter if one is defined */
     310#ifdef HAVE_BPF
    300311        if (DATA(libtrace)->filter) {
    301312                struct pcap_pkthdr *pcap_hdr = NULL;
     
    342353                        return -1;
    343354        }
     355#endif
    344356        return 0; /* success */
    345357}
  • lib/trace.c

    radb2c4c rd47ca18  
    13501350trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len)
    13511351{
    1352 #ifndef HAVE_BPF_FILTER
     1352#ifndef HAVE_BPF
    13531353        fprintf(stderr, "This version of libtrace does not have BPF support\n");
    13541354        return NULL;
     
    13771377 */
    13781378DLLEXPORT libtrace_filter_t *trace_create_filter(const char *filterstring) {
    1379 #ifdef HAVE_BPF_FILTER
     1379#ifdef HAVE_BPF
    13801380        libtrace_filter_t *filter = (libtrace_filter_t*)
    13811381                                malloc(sizeof(libtrace_filter_t));
     
    13921392DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter)
    13931393{
    1394 #ifdef HAVE_BPF_FILTER
     1394#ifdef HAVE_BPF
    13951395        free(filter->filterstring);
    13961396        if (filter->flag)
     
    14171417                void *linkptr,
    14181418                libtrace_linktype_t linktype    ) {
    1419 #ifdef HAVE_BPF_FILTER
     1419#ifdef HAVE_BPF
    14201420        /* It just so happens that the underlying libs used by pthread arn't
    14211421         * thread safe, namely lex/flex thingys, so single threaded compile
     
    14811481DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
    14821482                        const libtrace_packet_t *packet) {
    1483 #ifdef HAVE_BPF_FILTER
     1483#ifdef HAVE_BPF
    14841484        void *linkptr = 0;
    14851485        uint32_t clen = 0;
Note: See TracChangeset for help on using the changeset viewer.