*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.63 2003-07-25 04:04:56 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.64 2003-07-25 04:42:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "os-proto.h"
#endif
-#include "gencode.h"
+#include "gencode.h" /* for "no_optimize" */
+
+static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
static int
pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
memset(p->buffer, 0x0, p->bufsize);
#endif
+ p->setfilter_op = pcap_setfilter_bpf;
p->stats_op = pcap_stats_bpf;
p->close_op = pcap_close_bpf;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
+static int
+pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
{
-#ifdef HAVE_DAG_API
- if (p->md.is_dag) {
- return dag_setfilter(p, fp);
- }
-#endif /* HAVE_DAG_API */
-
/*
* It looks that BPF code generated by gen_protochain() is not
* compatible with some of kernel BPF code (for example BSD/OS 3.1).
if (no_optimize) {
if (install_bpf_program(p, fp) < 0)
return (-1);
- } else if (p->sf.rfile != NULL) {
- if (install_bpf_program(p, fp) < 0)
- return (-1);
} else if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
pcap_strerror(errno));
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.3 2003-07-25 04:04:57 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.4 2003-07-25 04:42:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "pcap-dag.h"
/* Replace dag function names with pcap equivalent. */
-#define dag_stats pcap_stats
#define dag_read pcap_read
#define dag_open_live pcap_open_live
#define dag_platform_finddevs pcap_platform_finddevs
-#define dag_setfilter pcap_setfilter
#define dag_set_datalink_platform pcap_set_datalink_platform
#endif /* DAG_ONLY */
+static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
static int dag_stats(pcap_t *p, struct pcap_stat *ps);
static void delete_pcap_dag(pcap_t *p) {
return NULL;
}
+ handle->setfilter_op = dag_setfilter;
handle->stats_op = dag_stats;
handle->close_op = dag_platform_close;
* no attempt to store the filter in kernel memory as that is not supported
* with DAG cards.
*/
-int dag_setfilter(pcap_t *p, struct bpf_program *fp) {
+static int dag_setfilter(pcap_t *p, struct bpf_program *fp) {
if (!p)
return -1;
if (!fp) {
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.87 2003-07-25 04:04:57 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.88 2003-07-25 04:42:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
goto bad;
}
+ p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->stats_op = pcap_stats_dlpi;
p->close_op = pcap_close_dlpi;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
-{
-
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- return (0);
-}
-
static int
send_request(int fd, char *ptr, int len, char *what, char *ebuf)
{
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.49 2003-07-25 04:04:57 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.50 2003-07-25 04:42:03 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
/*
* Methods.
*/
+ int (*setfilter_op)(pcap_t *, struct bpf_program *);
int (*stats_op)(pcap_t *, struct pcap_stat *);
void (*close_op)(pcap_t *);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.92 2003-07-25 04:04:58 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.93 2003-07-25 04:42:03 guy Exp $ (LBL)";
#endif
/*
static int live_open_new(pcap_t *, const char *, int, int, char *);
static int pcap_read_packet(pcap_t *, pcap_handler, u_char *);
static int pcap_stats_linux(pcap_t *, struct pcap_stat *);
+static int pcap_setfilter_linux(pcap_t *, struct bpf_program *);
static void pcap_close_linux(pcap_t *);
/*
return NULL;
}
+ handle->setfilter_op = pcap_setfilter_linux;
handle->stats_op = pcap_stats_linux;
handle->close_op = pcap_close_linux;
/*
* Attach the given BPF code to the packet capture device.
*/
-int
-pcap_setfilter(pcap_t *handle, struct bpf_program *filter)
+static int
+pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
{
#ifdef SO_ATTACH_FILTER
struct sock_fprog fcode;
int err = 0;
#endif
-#ifdef HAVE_DAG_API
- if (handle->md.is_dag) {
- return dag_setfilter(handle, filter);
- }
-#endif /* HAVE_DAG_API */
-
if (!handle)
return -1;
if (!filter) {
*/
handle->md.use_bpf = 0;
- /*
- * If we're reading from a savefile, don't try to install
- * a kernel filter.
- */
- if (handle->sf.rfile != NULL)
- return 0;
-
/* Install kernel level filter if possible */
#ifdef SO_ATTACH_FILTER
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.46 2003-07-25 04:04:58 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.47 2003-07-25 04:42:03 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
goto bad;
}
+ p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->stats_op = pcap_stats_nit;
p->close_op = pcap_close_nit;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
-{
-
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- return (0);
-}
-
int
pcap_set_datalink_platform(pcap_t *p, int dlt)
{
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.17 2003-07-25 04:04:58 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.18 2003-07-25 04:42:03 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
-{
- if (p->sf.rfile == NULL) {
- (void)snprintf(p->errbuf, sizeof(p->errbuf),
- "pcap_setfilter: %s", nosup);
- return (-1);
- }
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- return (0);
-}
-
int
pcap_set_datalink_platform(pcap_t *p, int dlt)
{
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.75 2003-07-25 04:04:59 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.76 2003-07-25 04:42:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "os-proto.h"
#endif
+static int pcap_setfilter_pf(pcap_t *, struct bpf_program *);
+
/*
* BUFSPACE is the size in bytes of the packet read buffer. Most tcpdump
* applications aren't going to need more than 200 bytes of packet header
goto bad;
}
+ p->setfilter_op = pcap_setfilter_pf;
p->stats_op = pcap_stats_pf;
p->close_op = pcap_close_pf;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
+static int
+pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
{
/*
* See if BIOCSETF works. If it does, the kernel supports
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.62 2003-07-25 04:04:59 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.63 2003-07-25 04:42:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
goto bad;
}
+ p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->stats_op = pcap_stats_snit;
p->close_op = pcap_close_snit;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
-{
-
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- return (0);
-}
-
int
pcap_set_datalink_platform(pcap_t *p, int dlt)
{
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.41 2003-07-25 04:04:59 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.42 2003-07-25 04:42:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
goto bad;
}
+ p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->stats_op = pcap_stats_snoop;
p->close_op = pcap_close_snoop;
return (0);
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
-{
-
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- return (0);
-}
-
int
pcap_set_datalink_platform(pcap_t *p, int dlt)
{
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.10 2003-07-25 04:04:59 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.11 2003-07-25 04:42:04 guy Exp $ (LBL)";
#endif
#include <pcap-int.h>
#define errno (*_errno())
#endif /* __MINGW32__ */
+static int pcap_setfilter_win32(pcap_t *, struct bpf_program *);
+
#define PcapBufSize 256000 /*dimension of the buffer in the pcap_t structure*/
#define SIZE_BUF 1000000
PacketSetReadTimeout(p->adapter, to_ms);
+ p->setfilter_op = pcap_setfilter_win32;
p->stats_op = pcap_stats_win32;
p->close_op = pcap_close_win32;
}
-int
-pcap_setfilter(pcap_t *p, struct bpf_program *fp)
+static int
+pcap_setfilter_win32(pcap_t *p, struct bpf_program *fp)
{
- if(p->adapter==NULL){
- /* Offline capture: make our own copy of the filter */
- if (install_bpf_program(p, fp) < 0)
- return (-1);
- }
- else if(PacketSetBpf(p->adapter,fp)==FALSE){
+ if(PacketSetBpf(p->adapter,fp)==FALSE){
/* kernel filter not installed. */
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Driver error: cannot set bpf filter: %s", pcap_win32strerror());
return (-1);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.58 2003-07-25 04:05:00 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.59 2003-07-25 04:42:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#endif
}
+int
+pcap_setfilter(pcap_t *p, struct bpf_program *fp)
+{
+ return p->setfilter_op(p, fp);
+}
+
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.83 2003-07-25 04:05:00 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.84 2003-07-25 04:42:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
pcap_fddipad = 0;
#endif
+ p->setfilter_op = install_bpf_program;
p->stats_op = sf_stats;
p->close_op = sf_close;