*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.65 2003-07-25 05:07:01 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.66 2003-07-25 05:32:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
return (0);
}
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
int cc;
int n = 0;
register u_char *bp, *ep;
-#ifdef HAVE_DAG_API
- if (p->md.is_dag) {
- return dag_read(p, cnt, callback, user);
- }
-#endif /* HAVE_DAG_API */
-
again:
cc = p->cc;
if (p->cc == 0) {
memset(p->buffer, 0x0, p->bufsize);
#endif
+ p->read_op = pcap_read_bpf;
p->setfilter_op = pcap_setfilter_bpf;
p->set_datalink_op = pcap_set_datalink_bpf;
p->stats_op = pcap_stats_bpf;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.5 2003-07-25 05:07:01 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.6 2003-07-25 05:32:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "pcap-dag.h"
/* Replace dag function names with pcap equivalent. */
-#define dag_read pcap_read
#define dag_open_live pcap_open_live
#define dag_platform_finddevs pcap_platform_finddevs
#endif /* DAG_ONLY */
* for each of them. Returns the number of packets handled or -1 if an
* error occured. A blocking
*/
-int dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) {
+static int dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) {
u_char *dp = NULL;
int packet_len = 0, caplen = 0;
struct pcap_pkthdr pcap_header;
*/
handle->md.dag_mem_bottom = 0;
handle->md.dag_mem_top = 0;
- handle->md.is_dag = 1;
handle->snapshot = snaplen;
/*handle->md.timeout = to_ms; */
return NULL;
}
+ handle->read_op = dag_read;
handle->setfilter_op = dag_setfilter;
handle->set_datalink_op = dag_set_datalink;
handle->stats_op = dag_stats;
*
* Author: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.2 2003-07-25 04:04:57 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.3 2003-07-25 05:32:03 guy Exp $ (LBL)
*/
-int dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user);
pcap_t *dag_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf);
-int dag_setfilter(pcap_t *p, struct bpf_program *fp);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.89 2003-07-25 05:07:01 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.90 2003-07-25 05:32:03 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
(char *)ctlbuf
};
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n, caplen, origlen;
register u_char *bp, *ep, *pk;
goto bad;
}
+ p->read_op = pcap_read_dlpi;
p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_dlpi;
* 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.51 2003-07-25 05:07:02 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.52 2003-07-25 05:32:03 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
#endif
#ifdef HAVE_DAG_API
- int is_dag; /* this is a dag card handle */
void *dag_mem_base; /* DAG card memory base address */
u_int dag_mem_bottom; /* DAG card current memory bottom pointer */
u_int dag_mem_top; /* DAG card current memory top pointer */
/*
* Methods.
*/
+ int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
int (*setfilter_op)(pcap_t *, struct bpf_program *);
int (*set_datalink_op)(pcap_t *, int);
int (*stats_op)(pcap_t *, struct pcap_stat *);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.94 2003-07-25 05:07:02 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.95 2003-07-25 05:32:04 guy Exp $ (LBL)";
#endif
/*
static void map_arphrd_to_dlt(pcap_t *, int, int);
static int live_open_old(pcap_t *, const char *, int, int, char *);
static int live_open_new(pcap_t *, const char *, int, int, char *);
+static int pcap_read_linux(pcap_t *, int, pcap_handler, u_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 *);
return NULL;
}
+ handle->read_op = pcap_read_linux;
handle->setfilter_op = pcap_setfilter_linux;
handle->set_datalink_op = NULL; /* can't change data link type */
handle->stats_op = pcap_stats_linux;
* for each of them. Returns the number of packets handled or -1 if an
* error occured.
*/
-int
-pcap_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
+static int
+pcap_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
-#ifdef HAVE_DAG_API
- if (handle->md.is_dag) {
- return dag_read(handle, max_packets, callback, user);
- }
-#endif /* HAVE_DAG_API */
-
/*
* Currently, on Linux only one packet is delivered per read,
* so we don't loop.
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.48 2003-07-25 05:07:02 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.49 2003-07-25 05:32:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
return (0);
}
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n;
register struct bpf_insn *fcode = p->fcode.bf_insns;
goto bad;
}
+ p->read_op = pcap_read_nit;
p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_nit;
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.19 2003-07-25 05:07:02 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.20 2003-07-25 05:32:04 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
static char nosup[] = "live packet capture not supported on this system";
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
-{
- (void)snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s", nosup);
- return (-1);
-}
-
pcap_t *
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
char *ebuf)
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.77 2003-07-25 05:07:03 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.78 2003-07-25 05:32:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
*/
#define BUFSPACE (200 * 256)
-int
-pcap_read(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
{
register u_char *p, *bp;
struct bpf_insn *fcode;
goto bad;
}
+ p->read_op = pcap_read_pf;
p->setfilter_op = pcap_setfilter_pf;
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_pf;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.64 2003-07-25 05:07:03 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.65 2003-07-25 05:32:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
return (0);
}
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
register int cc, n;
register struct bpf_insn *fcode = p->fcode.bf_insns;
goto bad;
}
+ p->read_op = pcap_read_snit;
p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_snit;
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.43 2003-07-25 05:07:03 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.44 2003-07-25 05:32:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "os-proto.h"
#endif
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_snoop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
int cc;
register struct snoopheader *sh;
goto bad;
}
+ p->read_op = pcap_read_snoop;
p->setfilter_op = install_bpf_program; /* no kernel filtering */
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_snoop;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.12 2003-07-25 05:07:03 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.13 2003-07-25 05:32:05 guy Exp $ (LBL)";
#endif
#include <pcap-int.h>
return 0;
}
-int
-pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+static int
+pcap_read_win32(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
int cc;
int n = 0;
PacketSetReadTimeout(p->adapter, to_ms);
+ p->read_op = pcap_read_win32;
p->setfilter_op = pcap_setfilter_win32;
p->set_datalink_op = NULL; /* can't change data link type */
p->stats_op = pcap_stats_win32;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.60 2003-07-25 05:07:04 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.61 2003-07-25 05:32:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
- if (p->sf.rfile != NULL)
- return (pcap_offline_read(p, cnt, callback, user));
- return (pcap_read(p, cnt, callback, user));
+ return p->read_op(p, cnt, callback, user);
+}
+
+/*
+ * XXX - is this necessary?
+ */
+int
+pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+{
+
+ return p->read_op(p, cnt, callback, user);
}
int
register int n;
for (;;) {
- if (p->sf.rfile != NULL)
+ if (p->sf.rfile != NULL) {
+ /*
+ * 0 means EOF, so don't loop if we get 0.
+ */
n = pcap_offline_read(p, cnt, callback, user);
- else {
+ } else {
/*
* XXX keep reading until we get something
* (or an error occurs)
*/
do {
- n = pcap_read(p, cnt, callback, user);
+ n = p->read_op(p, cnt, callback, user);
} while (n == 0);
}
if (n <= 0)
* The first one ('0') conflicts with the return code of 0 from
* pcap_offline_read() meaning "end of file".
*/
- return (pcap_read(p, 1, pcap_fakecallback, (u_char *)&s));
+ return (p->read_op(p, 1, pcap_fakecallback, (u_char *)&s));
}
int
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.85 2003-07-25 05:07:04 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.86 2003-07-25 05:32:06 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
pcap_fddipad = 0;
#endif
+ p->read_op = pcap_offline_read;
p->setfilter_op = install_bpf_program;
p->set_datalink_op = NULL; /* we don't support munging link-layer headers */
p->stats_op = sf_stats;