dect
/
libpcap
Archived
13
0
Fork 0

Add a "stats" function pointer to the pcap_t structure, which handles

getting statistics for a pcap_t.  Have "pcap_stats()" call it, rather
than being a per-platform function; have stats routines for non-live
pcap_t's that return an error.
This commit is contained in:
guy 2003-07-25 04:04:56 +00:00
parent e648c9e593
commit 9792990eb8
14 changed files with 69 additions and 53 deletions

View File

@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.62 2003-07-25 03:25:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.63 2003-07-25 04:04:56 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -103,17 +103,11 @@ static int odmlockid = 0;
#include "gencode.h"
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
{
struct bpf_stat s;
#ifdef HAVE_DAG_API
if (p->md.is_dag) {
return dag_stats(p, ps);
}
#endif /* HAVE_DAG_API */
/*
* "ps_recv" counts packets handed to the filter, not packets
* that passed the filter. This includes packets later dropped
@ -736,6 +730,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
memset(p->buffer, 0x0, p->bufsize);
#endif
p->stats_op = pcap_stats_bpf;
p->close_op = pcap_close_bpf;
return (p);

View File

@ -19,7 +19,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.2 2003-07-25 03:25:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.3 2003-07-25 04:04:57 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -67,6 +67,8 @@ static int atexit_handler_installed = 0;
#define dag_set_datalink_platform pcap_set_datalink_platform
#endif /* DAG_ONLY */
static int dag_stats(pcap_t *p, struct pcap_stat *ps);
static void delete_pcap_dag(pcap_t *p) {
pcap_dag_node_t *curr = NULL, *prev = NULL;
@ -385,12 +387,13 @@ pcap_t *dag_open_live(const char *device, int snaplen, int promisc, int to_ms, c
return NULL;
}
handle->stats_op = dag_stats;
handle->close_op = dag_platform_close;
return handle;
}
int dag_stats(pcap_t *p, struct pcap_stat *ps) {
static int dag_stats(pcap_t *p, struct pcap_stat *ps) {
/* This needs to be filled out correctly. Hopefully a dagapi call will
provide all necessary information.
*/

View File

@ -7,12 +7,10 @@
*
* Author: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.1 2003-07-23 05:29:21 guy Exp $ (LBL)
* @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.2 2003-07-25 04:04:57 guy Exp $ (LBL)
*/
int dag_stats(pcap_t *p, struct pcap_stat *ps);
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);
void dag_platform_close(pcap_t *p);

View File

@ -38,7 +38,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.86 2003-07-25 03:25:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.87 2003-07-25 04:04:57 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -151,8 +151,8 @@ static int dlpi_kread(int, off_t, void *, u_int, char *);
static int get_dlpi_ppa(int, const char *, int, char *);
#endif
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
{
/*
@ -672,6 +672,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
goto bad;
}
p->stats_op = pcap_stats_dlpi;
p->close_op = pcap_close_dlpi;
return (p);

View File

@ -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.48 2003-07-25 03:25:46 guy Exp $ (LBL)
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.49 2003-07-25 04:04:57 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
@ -118,6 +118,7 @@ struct pcap {
/*
* Methods.
*/
int (*stats_op)(pcap_t *, struct pcap_stat *);
void (*close_op)(pcap_t *);
/*

View File

@ -27,7 +27,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.91 2003-07-25 03:25:46 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.92 2003-07-25 04:04:58 guy Exp $ (LBL)";
#endif
/*
@ -187,7 +187,8 @@ 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_packet(pcap_t *, pcap_handler, u_char *);
static void pcap_close_linux(pcap_t *handle);
static int pcap_stats_linux(pcap_t *, struct pcap_stat *);
static void pcap_close_linux(pcap_t *);
/*
* Wrap some ioctl calls
@ -394,6 +395,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
return NULL;
}
handle->stats_op = pcap_stats_linux;
handle->close_op = pcap_close_linux;
return handle;
@ -659,20 +661,14 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
* patches); otherwise, that information isn't available, and we lie
* and report 0 as the count of dropped packets.
*/
int
pcap_stats(pcap_t *handle, struct pcap_stat *stats)
static int
pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
#ifdef HAVE_TPACKET_STATS
struct tpacket_stats kstats;
socklen_t len = sizeof (struct tpacket_stats);
#endif
#ifdef HAVE_DAG_API
if (handle->md.is_dag) {
return dag_stats(handle, stats);
}
#endif /* HAVE_DAG_API */
#ifdef HAVE_TPACKET_STATS
/*
* Try to get the packet counts from the kernel.

View File

@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.45 2003-07-25 03:25:46 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.46 2003-07-25 04:04:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -71,8 +71,8 @@ static const char rcsid[] =
/* Forwards */
static int nit_setflags(int, int, int, char *);
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_nit(pcap_t *p, struct pcap_stat *ps)
{
/*
@ -260,6 +260,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
goto bad;
}
p->stats_op = pcap_stats_nit;
p->close_op = pcap_close_nit;
return (p);

View File

@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.16 2002-12-22 02:36:49 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.17 2003-07-25 04:04:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -39,13 +39,6 @@ static const char rcsid[] =
static char nosup[] = "live packet capture not supported on this system";
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
(void)snprintf(p->errbuf, sizeof(p->errbuf), "pcap_stats: %s", nosup);
return (-1);
}
int
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{

View File

@ -24,7 +24,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.74 2003-07-25 03:25:47 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.75 2003-07-25 04:04:59 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -198,8 +198,8 @@ pcap_read(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
return (n);
}
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
{
/*
@ -413,6 +413,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
goto bad;
}
p->stats_op = pcap_stats_pf;
p->close_op = pcap_close_pf;
return (p);

View File

@ -25,7 +25,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.61 2003-07-25 03:25:47 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.62 2003-07-25 04:04:59 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -84,8 +84,8 @@ static const char rcsid[] =
/* Forwards */
static int nit_setflags(int, int, int, char *);
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_snit(pcap_t *p, struct pcap_stat *ps)
{
/*
@ -318,6 +318,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
goto bad;
}
p->stats_op = pcap_stats_snit;
p->close_op = pcap_close_snit;
return (p);

View File

@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.40 2003-07-25 03:25:47 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.41 2003-07-25 04:04:59 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -102,8 +102,8 @@ again:
return (0);
}
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
{
register struct rawstats *rs;
struct rawstats rawstats;
@ -294,6 +294,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
goto bad;
}
p->stats_op = pcap_stats_snoop;
p->close_op = pcap_close_snoop;
return (p);

View File

@ -32,7 +32,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.9 2003-07-25 03:25:47 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.10 2003-07-25 04:04:59 guy Exp $ (LBL)";
#endif
#include <pcap-int.h>
@ -75,8 +75,8 @@ wsockinit()
}
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
static int
pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
{
if(PacketGetStats(p->adapter, (struct bpf_stat*)ps) != TRUE){
@ -254,6 +254,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
PacketSetReadTimeout(p->adapter, to_ms);
p->stats_op = pcap_stats_win32;
p->close_op = pcap_close_win32;
return (p);

17
pcap.c
View File

@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.57 2003-07-25 03:25:48 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.58 2003-07-25 04:05:00 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -610,6 +610,20 @@ pcap_strerror(int errnum)
#endif
}
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
return p->stats_op(p, ps);
}
static int
pcap_stats_dead(pcap_t *p, struct pcap_stat *ps)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"Statistics aren't available from a pcap_open_dead pcap_t");
return (-1);
}
static void
pcap_close_dead(pcap_t *p)
{
@ -627,6 +641,7 @@ pcap_open_dead(int linktype, int snaplen)
memset (p, 0, sizeof(*p));
p->snapshot = snaplen;
p->linktype = linktype;
p->stats_op = pcap_stats_dead;
p->close_op = pcap_close_dead;
return p;
}

View File

@ -30,7 +30,7 @@
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.82 2003-07-25 03:25:48 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.83 2003-07-25 04:05:00 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -410,6 +410,14 @@ swap_hdr(struct pcap_file_header *hp)
hp->linktype = SWAPLONG(hp->linktype);
}
static int
sf_stats(pcap_t *p, struct pcap_stat *ps)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"Statistics aren't available from savefiles");
return (-1);
}
static void
sf_close(pcap_t *p)
{
@ -524,6 +532,7 @@ pcap_open_offline(const char *fname, char *errbuf)
pcap_fddipad = 0;
#endif
p->stats_op = sf_stats;
p->close_op = sf_close;
return (p);