Add a "set_datalink" function pointer to the pcap_t structure, whichhandles
setting a filter for a pcap_t. Have "pcap_set_datalink()" call it, rather than explicitly calling "pcap_set_datalink_platform()".
This commit is contained in:
parent
cd2807e08d
commit
08658f1c93
14
pcap-bpf.c
14
pcap-bpf.c
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.64 2003-07-25 04:42:02 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.65 2003-07-25 05:07:01 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -104,6 +104,7 @@ static int odmlockid = 0;
|
|||
#include "gencode.h" /* for "no_optimize" */
|
||||
|
||||
static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
|
||||
static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
|
||||
|
||||
static int
|
||||
pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
|
||||
|
@ -733,6 +734,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
#endif
|
||||
|
||||
p->setfilter_op = pcap_setfilter_bpf;
|
||||
p->set_datalink_op = pcap_set_datalink_bpf;
|
||||
p->stats_op = pcap_stats_bpf;
|
||||
p->close_op = pcap_close_bpf;
|
||||
|
||||
|
@ -777,15 +779,9 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
static int
|
||||
pcap_set_datalink_bpf(pcap_t *p, int dlt)
|
||||
{
|
||||
#ifdef HAVE_DAG_API
|
||||
if (p->md.is_dag) {
|
||||
return dag_set_datalink_platform(p, dlt);
|
||||
}
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
#ifdef BIOCSDLT
|
||||
if (ioctl(p->fd, BIOCSDLT, &dlt) == -1) {
|
||||
(void) snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.4 2003-07-25 04:42:02 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.5 2003-07-25 05:07:01 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -62,11 +62,11 @@ static int atexit_handler_installed = 0;
|
|||
#define dag_read pcap_read
|
||||
#define dag_open_live pcap_open_live
|
||||
#define dag_platform_finddevs pcap_platform_finddevs
|
||||
#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 int dag_set_datalink(pcap_t *p, int dlt);
|
||||
|
||||
static void delete_pcap_dag(pcap_t *p) {
|
||||
pcap_dag_node_t *curr = NULL, *prev = NULL;
|
||||
|
@ -387,6 +387,7 @@ pcap_t *dag_open_live(const char *device, int snaplen, int promisc, int to_ms, c
|
|||
}
|
||||
|
||||
handle->setfilter_op = dag_setfilter;
|
||||
handle->set_datalink_op = dag_set_datalink;
|
||||
handle->stats_op = dag_stats;
|
||||
handle->close_op = dag_platform_close;
|
||||
|
||||
|
@ -529,8 +530,8 @@ static int dag_setfilter(pcap_t *p, struct bpf_program *fp) {
|
|||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
dag_set_datalink_platform(pcap_t *p, int dlt)
|
||||
static int
|
||||
dag_set_datalink(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.88 2003-07-25 04:42:02 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.89 2003-07-25 05:07:01 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -673,6 +673,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
}
|
||||
|
||||
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;
|
||||
p->close_op = pcap_close_dlpi;
|
||||
|
||||
|
@ -1477,9 +1478,3 @@ dlpi_kread(register int fd, register off_t addr,
|
|||
return (cc);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* 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.50 2003-07-25 04:42:03 guy Exp $ (LBL)
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.51 2003-07-25 05:07:02 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef pcap_int_h
|
||||
|
@ -119,6 +119,7 @@ struct pcap {
|
|||
* Methods.
|
||||
*/
|
||||
int (*setfilter_op)(pcap_t *, struct bpf_program *);
|
||||
int (*set_datalink_op)(pcap_t *, int);
|
||||
int (*stats_op)(pcap_t *, struct pcap_stat *);
|
||||
void (*close_op)(pcap_t *);
|
||||
|
||||
|
|
15
pcap-linux.c
15
pcap-linux.c
|
@ -27,7 +27,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.93 2003-07-25 04:42:03 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.94 2003-07-25 05:07:02 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -397,6 +397,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
}
|
||||
|
||||
handle->setfilter_op = pcap_setfilter_linux;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->stats_op = pcap_stats_linux;
|
||||
handle->close_op = pcap_close_linux;
|
||||
|
||||
|
@ -1957,15 +1958,3 @@ reset_kernel_filter(pcap_t *handle)
|
|||
&dummy, sizeof(dummy));
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
#ifdef HAVE_DAG_API
|
||||
if (p->md.is_dag) {
|
||||
return dag_set_datalink_platform(p, dlt);
|
||||
}
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.47 2003-07-25 04:42:03 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.48 2003-07-25 05:07:02 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -261,6 +261,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
}
|
||||
|
||||
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;
|
||||
p->close_op = pcap_close_nit;
|
||||
|
||||
|
@ -277,9 +278,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
|||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.18 2003-07-25 04:42:03 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.19 2003-07-25 05:07:02 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -59,9 +59,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
|||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.76 2003-07-25 04:42:04 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.77 2003-07-25 05:07:03 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -416,6 +416,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
|
|||
}
|
||||
|
||||
p->setfilter_op = pcap_setfilter_pf;
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->stats_op = pcap_stats_pf;
|
||||
p->close_op = pcap_close_pf;
|
||||
|
||||
|
@ -470,9 +471,3 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
|
|||
fprintf(stderr, "tcpdump: Filtering in user process\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.63 2003-07-25 04:42:04 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.64 2003-07-25 05:07:03 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -319,6 +319,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
}
|
||||
|
||||
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;
|
||||
p->close_op = pcap_close_snit;
|
||||
|
||||
|
@ -335,9 +336,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
|||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.42 2003-07-25 04:42:04 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.43 2003-07-25 05:07:03 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -295,6 +295,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
}
|
||||
|
||||
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;
|
||||
p->close_op = pcap_close_snoop;
|
||||
|
||||
|
@ -310,9 +311,3 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
|||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.11 2003-07-25 04:42:04 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.12 2003-07-25 05:07:03 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <pcap-int.h>
|
||||
|
@ -257,6 +257,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
|||
PacketSetReadTimeout(p->adapter, to_ms);
|
||||
|
||||
p->setfilter_op = pcap_setfilter_win32;
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->stats_op = pcap_stats_win32;
|
||||
p->close_op = pcap_close_win32;
|
||||
|
||||
|
@ -359,9 +360,3 @@ pcap_setmintocopy(pcap_t *p, int size)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink_platform(pcap_t *p, int dlt)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
|
9
pcap.c
9
pcap.c
|
@ -33,7 +33,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.59 2003-07-25 04:42:04 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.60 2003-07-25 05:07:04 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -228,9 +228,10 @@ pcap_set_datalink(pcap_t *p, int dlt)
|
|||
int i;
|
||||
const char *dlt_name;
|
||||
|
||||
if (p->dlt_count == 0) {
|
||||
if (p->dlt_count == 0 || p->set_datalink_op == NULL) {
|
||||
/*
|
||||
* We couldn't fetch the list of DLTs, which means
|
||||
* We couldn't fetch the list of DLTs, or we don't
|
||||
* have a "set datalink" operation, which means
|
||||
* this platform doesn't support changing the
|
||||
* DLT for an interface. Check whether the new
|
||||
* DLT is the one this interface supports.
|
||||
|
@ -248,7 +249,7 @@ pcap_set_datalink(pcap_t *p, int dlt)
|
|||
break;
|
||||
if (i >= p->dlt_count)
|
||||
goto unsupported;
|
||||
if (pcap_set_datalink_platform(p, dlt) == -1)
|
||||
if (p->set_datalink_op(p, dlt) == -1)
|
||||
return (-1);
|
||||
p->linktype = dlt;
|
||||
return (0);
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.84 2003-07-25 04:42:05 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.85 2003-07-25 05:07:04 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -533,6 +533,7 @@ pcap_open_offline(const char *fname, char *errbuf)
|
|||
#endif
|
||||
|
||||
p->setfilter_op = install_bpf_program;
|
||||
p->set_datalink_op = NULL; /* we don't support munging link-layer headers */
|
||||
p->stats_op = sf_stats;
|
||||
p->close_op = sf_close;
|
||||
|
||||
|
|
Reference in New Issue