aboutsummaryrefslogtreecommitdiff
path: root/pcap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-05-30 20:08:14 -0700
committerGuy Harris <gharris@sonic.net>2020-05-30 20:08:14 -0700
commitc8645aa7f3d31863d51dad32ca5c8c63dddb9e5b (patch)
tree0b9f03325e91741debe9fde9ff1e76dfc8433f85 /pcap.c
parent19e1676ca47ddb11385b771f477e181e3a442e3b (diff)
Add pcap_handle(), and deprecate pcap_fileno(), on Windows.
I don't know whether a Windows HANDLE can be expected to survive conversion to an int - and there's no need for it to have to be converted. If a caller needs to do something with a HANDLE associated with a pcap_t, it should call the new pcap_handle() routine and get a HANDLE; code for UN*X that uses the result of pcap_fileno() is unlikely to work on Windows anyway. Squelch the "pointer truncation from 'HANDLE' to 'DWORD'" warning, as, if that truncation causes an issue, callers should use pcap_handle(), and if it *doesn't* cause an issue, it's, well, not an issue.
Diffstat (limited to 'pcap.c')
-rw-r--r--pcap.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/pcap.c b/pcap.c
index 38aaf379..7b89c051 100644
--- a/pcap.c
+++ b/pcap.c
@@ -3464,18 +3464,36 @@ pcap_file(pcap_t *p)
return (p->rfile);
}
+#ifdef _WIN32
+HANDLE
+pcap_handle(pcap_t *p)
+{
+ return (p->handle);
+}
+
int
pcap_fileno(pcap_t *p)
{
-#ifndef _WIN32
- return (p->fd);
-#else
- if (p->handle != INVALID_HANDLE_VALUE)
+ if (p->handle != INVALID_HANDLE_VALUE) {
+ /*
+ * This is a bogus and now-deprecated API; we
+ * squelch the narrowing warning for the cast
+ * from HANDLE to DWORD - Windows programmers
+ * should use pcap_handle().
+ */
+DIAG_OFF_NARROWING
return ((int)(DWORD)p->handle);
- else
+DIAG_ON_WARINING
+ } else
return (PCAP_ERROR);
-#endif
}
+#else /* _WIN32 */
+int
+pcap_fileno(pcap_t *p)
+{
+ return (p->fd);
+}
+#endif /* _WIN32 */
#if !defined(_WIN32) && !defined(MSDOS)
int