From: Guy Harris Date: Fri, 8 Sep 2017 00:19:13 +0000 (-0700) Subject: Move some Windows-isms into pcap.c. X-Git-Tag: libpcap-1.9-bp~753 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/f8a5b5f5e4602fd5222d4ceef20833c9ff42e94b?ds=sidebyside Move some Windows-isms into pcap.c. This would be useful if there's ever support for non-NPF capture mechanisms on Windows. --- diff --git a/pcap-win32.c b/pcap-win32.c index f2b442ea..520d61f5 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -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 8de39a6b..c6c1b609 100644 --- a/pcap.c +++ b/pcap.c @@ -122,6 +122,55 @@ struct rtentry; /* declarations in */ #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) {