aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pcap-int.h17
-rw-r--r--pcap-win32.c97
-rw-r--r--pcap.c51
-rw-r--r--savefile.c33
4 files changed, 139 insertions, 59 deletions
diff --git a/pcap-int.h b/pcap-int.h
index fe46316..daa0b0a 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -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.85 2007-09-29 19:33:29 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.86 2007-10-17 18:52:41 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
@@ -212,6 +212,21 @@ struct pcap {
int (*getnonblock_op)(pcap_t *, char *);
int (*setnonblock_op)(pcap_t *, int, char *);
int (*stats_op)(pcap_t *, struct pcap_stat *);
+#ifdef WIN32
+ /*
+ * Win32-only; given the way the buffer size is set with BPF,
+ * to make this cross-platform we'll have to set the buffer
+ * size at open time.
+ */
+ int (*setbuff_op)(pcap_t *, int);
+
+ /*
+ * These are, at least currently, specific to the Win32 NPF
+ * driver.
+ */
+ int (*setmode_op)(pcap_t *, int);
+ int (*setmintocopy_op)(pcap_t *, int);
+#endif
void (*close_op)(pcap_t *);
/*
diff --git a/pcap-win32.c b/pcap-win32.c
index 09d37f1..e9bf491 100644
--- a/pcap-win32.c
+++ b/pcap-win32.c
@@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.34 2007-09-25 20:34:36 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.35 2007-10-17 18:52:41 guy Exp $ (LBL)";
#endif
#include <pcap-int.h>
@@ -100,6 +100,43 @@ pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
return 0;
}
+/* Set the dimension of the kernel-level capture buffer */
+static int
+pcap_setbuff_win32(pcap_t *p, int dim)
+{
+ if(PacketSetBuff(p->adapter,dim)==FALSE)
+ {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
+ return -1;
+ }
+ return 0;
+}
+
+/* Set the driver working mode */
+static int
+pcap_setmode_win32(pcap_t *p, int mode)
+{
+ if(PacketSetMode(p->adapter,mode)==FALSE)
+ {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: working mode not recognized");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*set the minimum amount of data that will release a read call*/
+static int
+pcap_setmintocopy_win32(pcap_t *p, int size)
+{
+ if(PacketSetMinToCopy(p->adapter, size)==FALSE)
+ {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: unable to set the requested mintocopy size");
+ return -1;
+ }
+ return 0;
+}
+
static int
pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
@@ -641,6 +678,9 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
p->getnonblock_op = pcap_getnonblock_win32;
p->setnonblock_op = pcap_setnonblock_win32;
p->stats_op = pcap_stats_win32;
+ p->setbuff_op = pcap_setbuff_win32;
+ p->setmode_op = pcap_setmode_win32;
+ p->setmintocopy_op = pcap_setmintocopy_win32;
p->close_op = pcap_close_win32;
return (p);
@@ -747,61 +787,6 @@ pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
return (0);
}
-/* Set the driver working mode */
-int
-pcap_setmode(pcap_t *p, int mode){
-
- if (p->adapter==NULL)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "impossible to set mode while reading from a file");
- return -1;
- }
-
- if(PacketSetMode(p->adapter,mode)==FALSE)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: working mode not recognized");
- return -1;
- }
-
- return 0;
-}
-
-/* Set the dimension of the kernel-level capture buffer */
-int
-pcap_setbuff(pcap_t *p, int dim)
-{
- if (p->adapter==NULL)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file");
- return -1;
- }
-
- if(PacketSetBuff(p->adapter,dim)==FALSE)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
- return -1;
- }
- return 0;
-}
-
-/*set the minimum amount of data that will release a read call*/
-int
-pcap_setmintocopy(pcap_t *p, int size)
-{
- if (p->adapter==NULL)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Impossible to set the mintocopy parameter on an offline capture");
- return -1;
- }
-
- if(PacketSetMinToCopy(p->adapter, size)==FALSE)
- {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: unable to set the requested mintocopy size");
- return -1;
- }
- return 0;
-}
-
/*platform-dependent routine to add devices other than NDIS interfaces*/
int
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
diff --git a/pcap.c b/pcap.c
index c91a654..edc4cb1 100644
--- a/pcap.c
+++ b/pcap.c
@@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.112 2007-10-05 01:40:14 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.113 2007-10-17 18:52:41 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -757,6 +757,50 @@ pcap_stats_dead(pcap_t *p, struct pcap_stat *ps _U_)
return (-1);
}
+#ifdef WIN32
+int
+pcap_setbuff(pcap_t *p, int dim)
+{
+ return p->setbuff_op(p, dim);
+}
+
+static int
+pcap_setbuff_dead(pcap_t *p, int dim)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "The kernel buffer size cannot be set on a pcap_open_dead pcap_t");
+ return (-1);
+}
+
+int
+pcap_setmode(pcap_t *p, int mode)
+{
+ return p->setmode_op(p, mode);
+}
+
+static int
+pcap_setmode_dead(pcap_t *p, int mode)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "impossible to set mode on a pcap_open_dead pcap_t");
+ return (-1);
+}
+
+int
+pcap_setmintocopy(pcap_t *p, int size)
+{
+ return p->setintocopy_op(p, size);
+}
+
+static int
+pcap_setmintocopy_dead(pcap_t *p, int size)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "The mintocopy parameter cannot be set on a pcap_open_dead pcap_t");
+ return (-1);
+}
+#endif
+
void
pcap_close_common(pcap_t *p)
{
@@ -786,6 +830,11 @@ pcap_open_dead(int linktype, int snaplen)
p->snapshot = snaplen;
p->linktype = linktype;
p->stats_op = pcap_stats_dead;
+#ifdef WIN32
+ p->setbuff_op = pcap_setbuff_dead;
+ p->setmode_op = pcap_setmode_dead;
+ p->setmintocopy_op = pcap_setmintocopy_dead;
+#endif
p->close_op = pcap_close_dead;
return p;
}
diff --git a/savefile.c b/savefile.c
index 7375d01..fb0806f 100644
--- a/savefile.c
+++ b/savefile.c
@@ -30,7 +30,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.168 2007-10-05 01:40:15 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.169 2007-10-17 18:52:41 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -953,6 +953,32 @@ sf_stats(pcap_t *p, struct pcap_stat *ps)
return (-1);
}
+#ifdef WIN32
+static int
+sf_setbuff(pcap_t *p, int dim)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "The kernel buffer size cannot be set while reading from a file");
+ return (-1);
+}
+
+static int
+sf_setmode(pcap_t *p, int mode)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "impossible to set mode while reading from a file");
+ return (-1);
+}
+
+static int
+sf_setmintocopy(pcap_t *p, int size)
+{
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "The mintocopy parameter cannot be set while reading from a file");
+ return (-1);
+}
+#endif
+
static int
sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
{
@@ -1202,6 +1228,11 @@ pcap_fopen_offline(FILE *fp, char *errbuf)
p->getnonblock_op = sf_getnonblock;
p->setnonblock_op = sf_setnonblock;
p->stats_op = sf_stats;
+#ifdef WIN32
+ p->setbuff_op = sf_setbuff;
+ p->setmode_op = sf_setmode;
+ p->setmintocopy_op = sf_setmintocopy;
+#endif
p->close_op = sf_close;
return (p);