aboutsummaryrefslogtreecommitdiff
path: root/pcap-npf.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap-npf.c')
-rw-r--r--pcap-npf.c296
1 files changed, 162 insertions, 134 deletions
diff --git a/pcap-npf.c b/pcap-npf.c
index 99b5981e5a57..76346f574b60 100644
--- a/pcap-npf.c
+++ b/pcap-npf.c
@@ -31,9 +31,7 @@
*
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include <errno.h>
#include <limits.h> /* for INT_MAX */
@@ -143,14 +141,56 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
#endif
/*
- * Sigh. PacketRequest() will have made a DeviceIoControl()
- * call to the NPF driver to perform the OID request, with a
- * BIOCQUERYOID ioctl. The kernel code should get back one
- * of NDIS_STATUS_INVALID_OID, NDIS_STATUS_NOT_SUPPORTED,
- * or NDIS_STATUS_NOT_RECOGNIZED if the OID request isn't
- * supported by the OS or the driver, but that doesn't seem
- * to make it to the caller of PacketRequest() in a
- * reliable fashion.
+ * If a driver returns an NTSTATUS value:
+ *
+ * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
+ *
+ * with the "Customer" bit set, it will not be mapped to a Windows error
+ * value in userland, so it will be returned by GetLastError().
+ *
+ * Note that "driver" here includes the Npcap NPF driver, as various
+ * versions would take NT status values and set the "Customer" bit
+ * before returning the status code. The commit message for the
+ * change that started doing that is
+ *
+ * Returned a customer-defined NTSTATUS in OID requests to avoid
+ * NTSTATUS-to-Win32 Error code translation.
+ *
+ * but I don't know why the goal was to avoid that translation. For
+ * a while, I suspected that the NT status STATUS_NOT_SUPPORTED was
+ * getting mapped to ERROR_GEN_FAILURE, but, in the cases where
+ * attempts to set promiscuous mode on regular Ethernet devices were
+ * failing with ERROR_GEN_FAILURE, it turns out that the drivers for
+ * those devices were NetAdapterCx drivers, and Microsoft's NetAdapterCx
+ * mechanism wasn't providing the correct "bytes processed" value on
+ * attempts to set OIDs, and the Npcap NPF driver was checking for
+ * that and returning STATUS_UNSUCCESSFUL, which gets mapped to
+ * ERROR_GEN_FAILURE, so perhaps there's no need to avoid that
+ * translation.
+ *
+ * Attempting to set the hardware filter on a Microsoft Surface Pro's
+ * Mobile Broadband Adapter returns an error that appears to be
+ * NDIS_STATUS_NOT_SUPPORTED ORed with the "Customer" bit, so it's
+ * probably indicating that it doesn't support that. It was probably
+ * the NPF driver setting that bit.
+ */
+#define NT_STATUS_CUSTOMER_DEFINED 0x20000000
+
+/*
+ * PacketRequest() makes a DeviceIoControl() call to the NPF driver to
+ * perform the OID request, with a BIOCQUERYOID ioctl. The kernel code
+ * should get back one of NDIS_STATUS_INVALID_OID, NDIS_STATUS_NOT_SUPPORTED,
+ * or NDIS_STATUS_NOT_RECOGNIZED if the OID request isn't supported by
+ * the OS or the driver.
+ *
+ * Currently, that code may be returned by the Npcap NPF driver with the
+ * NT_STATUS_CUSTOMER_DEFINED bit. That prevents the return status from
+ * being mapped to a Windows error code; if the NPF driver were to stop
+ * ORing in the NT_STATUS_CUSTOMER_DEFINED bit, it's not obvious how those
+ * the NDIS_STATUS_ values that don't correspond to NTSTATUS values would
+ * be translated to Windows error values (NDIS_STATUS_NOT_SUPPORTED is
+ * the same as STATUS_NOT_SUPPORTED, which is an NTSTATUS value that is
+ * mapped to ERROR_NOT_SUPPORTED).
*/
#define NDIS_STATUS_INVALID_OID 0xc0010017
#define NDIS_STATUS_NOT_SUPPORTED 0xc00000bb /* STATUS_NOT_SUPPORTED */
@@ -182,7 +222,7 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
oid_data_arg->Oid = oid;
oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */
if (!PacketRequest(adapter, FALSE, oid_data_arg)) {
- pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Error calling PacketRequest");
free(oid_data_arg);
return (-1);
@@ -221,7 +261,7 @@ pcap_stats_npf(pcap_t *p, struct pcap_stat *ps)
* to us.
*/
if (!PacketGetStats(pw->adapter, &bstats)) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketGetStats error");
return (-1);
}
@@ -278,7 +318,7 @@ pcap_stats_ex_npf(pcap_t *p, int *pcap_stat_size)
* same layout, but let's not cheat.)
*/
if (!PacketGetStatsEx(pw->adapter, &bstats)) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketGetStatsEx error");
return (NULL);
}
@@ -380,7 +420,7 @@ pcap_oid_set_request_npf(pcap_t *p, bpf_u_int32 oid, const void *data,
oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */
memcpy(oid_data_arg->Data, data, *lenp);
if (!PacketRequest(pw->adapter, TRUE, oid_data_arg)) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Error calling PacketRequest");
free(oid_data_arg);
return (PCAP_ERROR);
@@ -410,7 +450,7 @@ pcap_sendqueue_transmit_npf(pcap_t *p, pcap_send_queue *queue, int sync)
(BOOLEAN)sync);
if(res != queue->len){
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Error queueing packets");
}
@@ -618,7 +658,7 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
"The interface disappeared (error code %s)",
errcode_msg);
} else {
- pcap_fmt_errmsg_for_win32_err(p->errbuf,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf,
PCAP_ERRBUF_SIZE, errcode,
"PacketReceivePacket error");
}
@@ -676,13 +716,13 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* in kernel, no need to do it now - we already know
* the packet passed the filter.
*
- * XXX - pcap_filter() should always return TRUE if
+ * XXX - pcapint_filter() should always return TRUE if
* handed a null pointer for the program, but it might
* just try to "run" the filter, so we check here.
*/
if (pw->filtering_in_kernel ||
p->fcode.bf_insns == NULL ||
- pcap_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
+ pcapint_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
#ifdef ENABLE_REMOTE
switch (p->rmt_samp.method) {
@@ -904,7 +944,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* No underlying filtering system. We need to filter on our own */
if (p->fcode.bf_insns)
{
- if (pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
+ if (pcapint_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
{
/* Move to next packet */
header = (dag_record_t*)((char*)header + erf_record_len);
@@ -945,7 +985,7 @@ pcap_inject_npf(pcap_t *p, const void *buf, int size)
PacketInitPacket(&pkt, (PVOID)buf, size);
if(PacketSendPacket(pw->adapter,&pkt,TRUE) == FALSE) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "send error: PacketSendPacket failed");
return (-1);
}
@@ -971,51 +1011,19 @@ pcap_cleanup_npf(pcap_t *p)
{
PacketSetMonitorMode(p->opt.device, 0);
}
- pcap_cleanup_live_common(p);
+ pcapint_cleanup_live_common(p);
}
static void
pcap_breakloop_npf(pcap_t *p)
{
- pcap_breakloop_common(p);
+ pcapint_breakloop_common(p);
struct pcap_win *pw = p->priv;
/* XXX - what if this fails? */
SetEvent(PacketGetReadEvent(pw->adapter));
}
-/*
- * These are NTSTATUS values:
- *
- * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
- *
- * with the "Customer" bit set. If a driver returns them, they are not
- * mapped to Windows error values in userland; they're returned by
- * GetLastError().
- *
- * Note that "driver" here includes the Npcap NPF driver, as various
- * versions would take NT status values and set the "Customer" bit
- * before returning the status code. The commit message for the
- * change that started doing that is
- *
- * Returned a customer-defined NTSTATUS in OID requests to avoid
- * NTSTATUS-to-Win32 Error code translation.
- *
- * but I don't know why the goal was to avoid that translation.
- *
- * Attempting to set the hardware filter on a Microsoft Surface Pro's
- * Mobile Broadband Adapter returns an error that appears to be
- * NDIS_STATUS_NOT_SUPPORTED ORed with the "Customer" bit, so it's
- * probably indicating that it doesn't support that.
- *
- * It is likely that there are other devices which throw spurious errors,
- * at which point this will need refactoring to efficiently check against
- * a list, but for now we can just check this one value. Perhaps the
- * right way to do this is compare against various NDIS errors with
- * the "customer" bit ORed in.
- */
-#define NT_STATUS_CUSTOMER_DEFINED 0x20000000
-
static int
pcap_activate_npf(pcap_t *p)
{
@@ -1095,7 +1103,7 @@ pcap_activate_npf(pcap_t *p)
/*
* Unknown - report details.
*/
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
errcode, "Error opening adapter");
if (pw->rfmon_selfstart)
{
@@ -1108,7 +1116,7 @@ pcap_activate_npf(pcap_t *p)
/*get network type*/
if(PacketGetNetType (pw->adapter,&type) == FALSE)
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Cannot determine the network type");
goto bad;
}
@@ -1132,14 +1140,15 @@ pcap_activate_npf(pcap_t *p)
* Ethernet framing).
*/
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
- /*
- * If that fails, just leave the list empty.
- */
- if (p->dlt_list != NULL) {
- p->dlt_list[0] = DLT_EN10MB;
- p->dlt_list[1] = DLT_DOCSIS;
- p->dlt_count = 2;
+ if (p->dlt_list == NULL)
+ {
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "malloc");
+ goto bad;
}
+ p->dlt_list[0] = DLT_EN10MB;
+ p->dlt_list[1] = DLT_DOCSIS;
+ p->dlt_count = 2;
break;
case NdisMedium802_5:
@@ -1243,7 +1252,7 @@ pcap_activate_npf(pcap_t *p)
*/
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_SINGLE_SYNCHRONIZATION))
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_SINGLE_SYNCHRONIZATION");
goto bad;
}
@@ -1255,7 +1264,7 @@ pcap_activate_npf(pcap_t *p)
*/
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_QUERYSYSTEMTIME))
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_QUERYSYSTEMTIME");
goto bad;
}
@@ -1267,7 +1276,7 @@ pcap_activate_npf(pcap_t *p)
*/
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_QUERYSYSTEMTIME_PRECISE))
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_QUERYSYSTEMTIME_PRECISE");
goto bad;
}
@@ -1297,13 +1306,18 @@ pcap_activate_npf(pcap_t *p)
/* Set promiscuous mode */
if (p->opt.promisc)
{
-
+ /*
+ * For future reference, in case we ever want to query
+ * whether an adapter supports promiscuous mode, that
+ * would be done on Windows by querying the value
+ * of the OID_GEN_SUPPORTED_PACKET_FILTERS OID.
+ */
if (PacketSetHwFilter(pw->adapter,NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE)
{
DWORD errcode = GetLastError();
/*
- * Suppress spurious error generated by non-compiant
+ * Suppress spurious error generated by non-compliant
* MS Surface mobile adapters that appear to
* return NDIS_STATUS_NOT_SUPPORTED for attempts
* to set the hardware filter.
@@ -1341,10 +1355,18 @@ pcap_activate_npf(pcap_t *p)
* value, so that old incorrect programs that
* assume a non-zero return from pcap_activate()
* is an error don't break.)
+ *
+ * We check here for ERROR_NOT_SUPPORTED, which
+ * is what NDIS_STATUS_NOT_SUPPORTED (which is
+ * the same value as the NTSTATUS value
+ * STATUS_NOT_SUPPORTED) gets mapped to, as
+ * well as NDIS_STATUS_NOT_SUPPORTED with the
+ * "Customer" bit set.
*/
- if (errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
+ if (errcode != ERROR_NOT_SUPPORTED &&
+ errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf,
PCAP_ERRBUF_SIZE, errcode,
"failed to set hardware filter to promiscuous mode");
goto bad;
@@ -1370,12 +1392,12 @@ pcap_activate_npf(pcap_t *p)
DWORD errcode = GetLastError();
/*
- * Suppress spurious error generated by non-compiant
+ * Suppress spurious error generated by non-compliant
* MS Surface mobile adapters.
*/
if (errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf,
PCAP_ERRBUF_SIZE, errcode,
"failed to set hardware filter to non-promiscuous mode");
goto bad;
@@ -1407,7 +1429,7 @@ pcap_activate_npf(pcap_t *p)
p->buffer = malloc(p->bufsize);
if (p->buffer == NULL)
{
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "malloc");
goto bad;
}
@@ -1417,7 +1439,7 @@ pcap_activate_npf(pcap_t *p)
/* tell the driver to copy the buffer as soon as data arrives */
if(PacketSetMinToCopy(pw->adapter,0)==FALSE)
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf,
PCAP_ERRBUF_SIZE, GetLastError(),
"Error calling PacketSetMinToCopy");
goto bad;
@@ -1428,7 +1450,7 @@ pcap_activate_npf(pcap_t *p)
/* tell the driver to copy the buffer only if it contains at least 16K */
if(PacketSetMinToCopy(pw->adapter,16000)==FALSE)
{
- pcap_fmt_errmsg_for_win32_err(p->errbuf,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf,
PCAP_ERRBUF_SIZE, GetLastError(),
"Error calling PacketSetMinToCopy");
goto bad;
@@ -1505,7 +1527,7 @@ pcap_activate_npf(pcap_t *p)
total_prog.bf_len = 1;
total_prog.bf_insns = &total_insn;
if (!PacketSetBpf(pw->adapter, &total_prog)) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketSetBpf");
status = PCAP_ERROR;
goto bad;
@@ -1569,7 +1591,7 @@ pcap_activate_npf(pcap_t *p)
* that the caller can do anything useful with it.
*
* (Not that we make any general guarantee of that
- * sort on UN*X, either, any more, given that not
+ * sort on UN*X, either, anymore, given that not
* all capture devices are regular OS network
* interfaces.)
*/
@@ -1600,6 +1622,11 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
char *device_copy = NULL;
ADAPTER *adapter = NULL;
ULONG num_ts_modes;
+ /* Npcap 1.00 driver is buggy and will write 16 bytes regardless of
+ * buffer size. Using a sufficient stack buffer avoids overflow and
+ * avoids a heap allocation in most (currently all) cases.
+ */
+ ULONG ts_modes[4];
BOOL ret;
DWORD error = ERROR_SUCCESS;
ULONG *modes = NULL;
@@ -1616,7 +1643,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
*/
device_copy = strdup(device);
if (device_copy == NULL) {
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
+ pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
status = -1;
break;
}
@@ -1660,7 +1687,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
p->tstamp_type_list = NULL;
status = 0;
} else {
- pcap_fmt_errmsg_for_win32_err(ebuf,
+ pcapint_fmt_errmsg_for_win32_err(ebuf,
PCAP_ERRBUF_SIZE, error,
"Error opening adapter");
status = -1;
@@ -1690,8 +1717,8 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
* happen), and that ULONG should be set to the
* number of modes.
*/
- num_ts_modes = 1;
- ret = PacketGetTimestampModes(adapter, &num_ts_modes);
+ ts_modes[0] = sizeof(ts_modes) / sizeof(ULONG);
+ ret = PacketGetTimestampModes(adapter, ts_modes);
if (!ret) {
/*
* OK, it failed. Did it fail with
@@ -1725,24 +1752,55 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
/*
* No, some other error. Fail.
*/
- pcap_fmt_errmsg_for_win32_err(ebuf,
+ pcapint_fmt_errmsg_for_win32_err(ebuf,
PCAP_ERRBUF_SIZE, error,
"Error calling PacketGetTimestampModes");
status = -1;
break;
}
+
+ /*
+ * Yes, so we now know how many types to fetch.
+ *
+ * The buffer needs to have one ULONG for the
+ * count and num_ts_modes ULONGs for the
+ * num_ts_modes time stamp types.
+ */
+ num_ts_modes = ts_modes[0];
+ modes = (ULONG *)malloc((1 + num_ts_modes) * sizeof(ULONG));
+ if (modes == NULL) {
+ /* Out of memory. */
+ pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
+ status = -1;
+ break;
+ }
+ modes[0] = 1 + num_ts_modes;
+ if (!PacketGetTimestampModes(adapter, modes)) {
+ pcapint_fmt_errmsg_for_win32_err(ebuf,
+ PCAP_ERRBUF_SIZE, GetLastError(),
+ "Error calling PacketGetTimestampModes");
+ status = -1;
+ break;
+ }
+ if (modes[0] != num_ts_modes) {
+ snprintf(ebuf, PCAP_ERRBUF_SIZE,
+ "First PacketGetTimestampModes() call gives %lu modes, second call gives %lu modes",
+ num_ts_modes, modes[0]);
+ status = -1;
+ break;
+ }
+ }
+ else {
+ modes = ts_modes;
+ num_ts_modes = ts_modes[0];
}
- /* else (ret == TRUE)
- * Unexpected success. Let's act like we got ERROR_MORE_DATA.
- * If it doesn't work, we'll hit some other error condition farther on.
- */
/* If the driver reports no modes supported *and*
* ERROR_MORE_DATA, something is seriously wrong.
* We *could* ignore the error and continue without supporting
* settable timestamp modes, but that would hide a bug.
*/
- if (num_ts_modes == 0) {
+ if (modes[0] == 0) {
snprintf(ebuf, PCAP_ERRBUF_SIZE,
"PacketGetTimestampModes() reports 0 modes supported.");
status = -1;
@@ -1750,43 +1808,13 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
}
/*
- * Yes, so we now know how many types to fetch.
- *
- * The buffer needs to have one ULONG for the
- * count and num_ts_modes ULONGs for the
- * num_ts_modes time stamp types.
- */
- modes = (ULONG *)malloc((1 + num_ts_modes) * sizeof(ULONG));
- if (modes == NULL) {
- /* Out of memory. */
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
- status = -1;
- break;
- }
- modes[0] = 1 + num_ts_modes;
- if (!PacketGetTimestampModes(adapter, modes)) {
- pcap_fmt_errmsg_for_win32_err(ebuf,
- PCAP_ERRBUF_SIZE, GetLastError(),
- "Error calling PacketGetTimestampModes");
- status = -1;
- break;
- }
- if (modes[0] != num_ts_modes) {
- snprintf(ebuf, PCAP_ERRBUF_SIZE,
- "First PacketGetTimestampModes() call gives %lu modes, second call gives %lu modes",
- num_ts_modes, modes[0]);
- status = -1;
- break;
- }
-
- /*
* Allocate a buffer big enough for
* PCAP_TSTAMP_HOST (default) plus
* the explicitly specified modes.
*/
p->tstamp_type_list = malloc((1 + num_ts_modes) * sizeof(u_int));
if (p->tstamp_type_list == NULL) {
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
+ pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
status = -1;
break;
}
@@ -1843,7 +1871,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
if (device_copy != NULL) {
free(device_copy);
}
- if (modes != NULL) {
+ if (modes != NULL && modes != ts_modes) {
free(modes);
}
if (adapter != NULL) {
@@ -1864,7 +1892,7 @@ get_ts_types(const char *device _U_, pcap_t *p _U_, char *ebuf _U_)
#endif /* HAVE_PACKET_GET_TIMESTAMP_MODES */
pcap_t *
-pcap_create_interface(const char *device _U_, char *ebuf)
+pcapint_create_interface(const char *device _U_, char *ebuf)
{
pcap_t *p;
@@ -1915,11 +1943,11 @@ pcap_setfilter_npf(pcap_t *p, struct bpf_program *fp)
*/
/*
- * install_bpf_program() validates the program.
+ * pcapint_install_bpf_program() validates the program.
*
* XXX - what if we already have a filter in the kernel?
*/
- if (install_bpf_program(p, fp) < 0)
+ if (pcapint_install_bpf_program(p, fp) < 0)
return (-1);
pw->filtering_in_kernel = 0; /* filtering in userland */
return (0);
@@ -1948,12 +1976,12 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
if(!fp)
{
- pcap_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
+ pcapint_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
return (-1);
}
/* Install a user level filter */
- if (install_bpf_program(p, fp) < 0)
+ if (pcapint_install_bpf_program(p, fp) < 0)
return (-1);
return (0);
@@ -1996,7 +2024,7 @@ pcap_setnonblock_npf(pcap_t *p, int nonblock)
newtimeout = p->opt.timeout;
}
if (!PacketSetReadTimeout(pw->adapter, newtimeout)) {
- pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketSetReadTimeout");
return (-1);
}
@@ -2018,7 +2046,7 @@ pcap_add_if_npf(pcap_if_list_t *devlistp, char *name, bpf_u_int32 flags,
/*
* Add an entry for this interface, with no addresses.
*/
- curdev = add_dev(devlistp, name, flags, description, errbuf);
+ curdev = pcapint_add_dev(devlistp, name, flags, description, errbuf);
if (curdev == NULL) {
/*
* Failure.
@@ -2050,7 +2078,7 @@ pcap_add_if_npf(pcap_if_list_t *devlistp, char *name, bpf_u_int32 flags,
* "curdev" is an entry for this interface; add an entry for
* this address to its list of addresses.
*/
- res = add_addr_to_dev(curdev,
+ res = pcapint_add_addr_to_dev(curdev,
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
sizeof (struct sockaddr_storage),
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
@@ -2327,7 +2355,7 @@ DIAG_ON_ENUM_SWITCH
}
int
-pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
+pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
{
int ret = 0;
const char *desc;
@@ -2359,7 +2387,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
if (last_error != ERROR_INSUFFICIENT_BUFFER)
{
- pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
last_error, "PacketGetAdapterNames");
return (-1);
}
@@ -2375,7 +2403,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
}
if (!PacketGetAdapterNames(AdaptersName, &NameLength)) {
- pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketGetAdapterNames");
free(AdaptersName);
return (-1);
@@ -2490,7 +2518,7 @@ pcap_lookupdev(char *errbuf)
* In addition, it's not thread-safe, so we've marked it as
* deprecated.
*/
- if (pcap_new_api) {
+ if (pcapint_new_api) {
snprintf(errbuf, PCAP_ERRBUF_SIZE,
"pcap_lookupdev() is deprecated and is not supported in programs calling pcap_init()");
return (NULL);
@@ -2536,7 +2564,7 @@ DIAG_ON_DEPRECATION
if ( !PacketGetAdapterNames((PTSTR)TAdaptersName,&NameLength) )
{
- pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "PacketGetAdapterNames");
free(TAdaptersName);
return NULL;
@@ -2710,7 +2738,7 @@ pcap_lib_version(void)
*/
char *full_pcap_version_string;
- if (pcap_asprintf(&full_pcap_version_string,
+ if (pcapint_asprintf(&full_pcap_version_string,
WINPCAP_PRODUCT_NAME " version " WINPCAP_VER_STRING " (packet.dll version %s), based on " PCAP_VERSION_STRING,
packet_version_string) != -1) {
/* Success */
@@ -2737,7 +2765,7 @@ pcap_lib_version(void)
*/
char *full_pcap_version_string;
- if (pcap_asprintf(&full_pcap_version_string,
+ if (pcapint_asprintf(&full_pcap_version_string,
PCAP_VERSION_STRING " (packet.dll version %s)",
PacketGetVersion()) != -1) {
/* Success */