]> The Tcpdump Group git mirrors - libpcap/commitdiff
Move some Windows-isms into pcap.c.
authorGuy Harris <[email protected]>
Fri, 8 Sep 2017 00:19:13 +0000 (17:19 -0700)
committerGuy Harris <[email protected]>
Fri, 8 Sep 2017 00:19:13 +0000 (17:19 -0700)
This would be useful if there's ever support for non-NPF capture
mechanisms on Windows.

pcap-win32.c
pcap.c

index f2b442ea944b18cf38871e1acdcc4215c1a0edf9..520d61f5470d5fd5ab6800d605590cbb0bfb722e 100644 (file)
@@ -84,15 +84,6 @@ struct pcap_win {
 #endif
 };
 
-BOOL WINAPI DllMain(
-  HANDLE hinstDLL,
-  DWORD dwReason,
-  LPVOID lpvReserved
-)
-{
-       return (TRUE);
-}
-
 /*
  * Define stub versions of the monitor-mode support routines if this
  * isn't Npcap. HAVE_NPCAP_PACKET_API is defined by Npcap but not
@@ -131,34 +122,6 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
 }
 #endif
 
-/* Start winsock */
-int
-wsockinit(void)
-{
-       WORD wVersionRequested;
-       WSADATA wsaData;
-       static int err = -1;
-       static int done = 0;
-
-       if (done)
-               return (err);
-
-       wVersionRequested = MAKEWORD( 1, 1);
-       err = WSAStartup( wVersionRequested, &wsaData );
-       atexit ((void(*)(void))WSACleanup);
-       done = 1;
-
-       if ( err != 0 )
-               err = -1;
-       return (err);
-}
-
-int
-pcap_wsockinit(void)
-{
-       return (wsockinit());
-}
-
 static int
 pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
 {
@@ -916,7 +879,7 @@ pcap_activate_win32(pcap_t *p)
        }
 
        /* Init WinSock */
-       wsockinit();
+       pcap_wsockinit();
 
        pw->adapter = PacketOpenAdapter(p->opt.device);
 
diff --git a/pcap.c b/pcap.c
index 8de39a6b8a692c4088ab51d7ad47c113fa8f6f50..c6c1b609934d20b2a5087389db2198be9fcc036f 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -122,6 +122,55 @@ struct rtentry;            /* declarations in <net/if.h> */
 #include "pcap-rdmasniff.h"
 #endif
 
+#ifdef _WIN32
+/*
+ * DllMain(), required when built as a Windows DLL.
+ */
+BOOL WINAPI DllMain(
+  HANDLE hinstDLL,
+  DWORD dwReason,
+  LPVOID lpvReserved
+)
+{
+       return (TRUE);
+}
+
+/*
+ * Start WinSock.
+ * Exported in case some applications using WinPcap called it,
+ * even though it wasn't exported.
+ */
+int
+wsockinit(void)
+{
+       WORD wVersionRequested;
+       WSADATA wsaData;
+       static int err = -1;
+       static int done = 0;
+
+       if (done)
+               return (err);
+
+       wVersionRequested = MAKEWORD( 1, 1);
+       err = WSAStartup( wVersionRequested, &wsaData );
+       atexit ((void(*)(void))WSACleanup);
+       done = 1;
+
+       if ( err != 0 )
+               err = -1;
+       return (err);
+}
+
+/*
+ * This is the exported function; new programs should call this.
+ */
+int
+pcap_wsockinit(void)
+{
+       return (wsockinit());
+}
+#endif /* _WIN32 */
+
 static int
 pcap_not_initialized(pcap_t *pcap)
 {