[IPHLPAPI] Don't (de)initialize ws2 on dll process (attach/detach), do it on IcmpCrea...
authorAmine Khaldi <amine.khaldi@reactos.org>
Tue, 20 Sep 2016 09:42:51 +0000 (09:42 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Tue, 20 Sep 2016 09:42:51 +0000 (09:42 +0000)
svn path=/trunk/; revision=72747

reactos/dll/win32/iphlpapi/icmp.c
reactos/dll/win32/iphlpapi/iphlpapi_main.c

index a67a867..63da35d 100644 (file)
@@ -114,8 +114,18 @@ static int in_cksum(u_short *addr, int len)
 HANDLE WINAPI Icmp6CreateFile(VOID)
 {
     icmp_t* icp;
+    int sid;
+#ifdef __REACTOS__
+    WSADATA wsaData;
 
-    int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
+    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
+    {
+        ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
+        return INVALID_HANDLE_VALUE;
+    }
+#endif
+
+    sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
 #ifndef __REACTOS__
     if (sid < 0)
     {
@@ -133,6 +143,7 @@ HANDLE WINAPI Icmp6CreateFile(VOID)
     if (icp==NULL) {
 #ifdef __REACTOS__
         closesocket(sid);
+        WSACleanup();
 #else
         close(sid);
 #endif
@@ -180,8 +191,17 @@ HANDLE WINAPI IcmpCreateFile(VOID)
     static int once;
 #endif
     icmp_t* icp;
+    int sid;
+#ifdef __REACTOS__
+    WSADATA wsaData;
 
-    int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
+    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
+    {
+        ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
+        return INVALID_HANDLE_VALUE;
+    }
+#endif
+    sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
 #ifdef __REACTOS__
     if (sid < 0) {
         ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n");
@@ -204,6 +224,7 @@ HANDLE WINAPI IcmpCreateFile(VOID)
     if (icp==NULL) {
 #ifdef __REACTOS__
         closesocket(sid);
+        WSACleanup();
 #else
         if (sid >= 0) close(sid);
 #endif
@@ -235,6 +256,9 @@ BOOL WINAPI IcmpCloseHandle(HANDLE  IcmpHandle)
     if (icp->sid >= 0) close(icp->sid);
 #endif
     HeapFree(GetProcessHeap (), 0, icp);
+#ifdef __REACTOS__
+    WSACleanup();
+#endif
     return TRUE;
 }
 
index c8dec12..30d0b42 100644 (file)
@@ -35,17 +35,13 @@ typedef struct _NAME_SERVER_LIST_CONTEXT {
 
 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 {
-  WSADATA wsaData;
-
   switch (fdwReason) {
     case DLL_PROCESS_ATTACH:
       DisableThreadLibraryCalls( hinstDLL );
       interfaceMapInit();
-      WSAStartup(MAKEWORD(2, 2), &wsaData);
       break;
 
     case DLL_PROCESS_DETACH:
-      WSACleanup();
       interfaceMapFree();
       break;
   }