[ws2_32]
[reactos.git] / reactos / dll / win32 / ws2_32 / misc / dllmain.c
index ea5d45f..b0d657e 100644 (file)
@@ -55,7 +55,8 @@ EXPORT
 WSAStartup(IN  WORD wVersionRequested,
            OUT LPWSADATA lpWSAData)
 {
-    BYTE Low, High;
+    WORD VersionReturned = 0;
+    DWORD ErrorCode = ERROR_SUCCESS;
 
     WS_DbgPrint(MAX_TRACE, ("WSAStartup of ws2_32.dll\n"));
 
@@ -65,48 +66,56 @@ WSAStartup(IN  WORD wVersionRequested,
     if (lpWSAData == NULL)
         return WSAEFAULT;
 
-    Low = LOBYTE(wVersionRequested);
-    High  = HIBYTE(wVersionRequested);
-
-    if (Low < 1)
+    /* Check which version is being requested */
+    switch (LOBYTE(wVersionRequested))
     {
-        WS_DbgPrint(MAX_TRACE, ("Bad winsock version requested, %d,%d", Low, High));
-        return WSAVERNOTSUPPORTED;
-    }
+        case 0:
 
-    if (Low == 1)
-    {
-        if (High == 0)
-        {
-            lpWSAData->wVersion = wVersionRequested;
-        }
-        else
-        {
-            lpWSAData->wVersion = MAKEWORD(1, 1);
-        }
-    }
-    else if (Low == 2)
-    {
-        if (High <= 2)
-        {
-            lpWSAData->wVersion = MAKEWORD(2, High);
-        }
-        else
-        {
-            lpWSAData->wVersion = MAKEWORD(2, 2);
-        }
-    }
-    else
-    {
-        lpWSAData->wVersion = MAKEWORD(2, 2);
+            /* We don't support this unknown version */
+            ErrorCode = WSAVERNOTSUPPORTED;
+            break;
+
+        case 1:
+            /* We support only 1.0 and 1.1 */
+            if (HIBYTE(wVersionRequested) == 0)
+            {
+                /* Caller wants 1.0, return it */
+                VersionReturned = wVersionRequested;
+            }
+            else
+            {
+                /* The only other version we support is 1.1 */
+                VersionReturned = MAKEWORD(1, 1);
+            }
+            break;
+
+        case 2:
+            /* We support only 2.0, 2.1 and 2.2 */
+            if (HIBYTE(wVersionRequested) <= 2)
+            {
+                /* Caller wants 2.0-2.2, return it */
+                VersionReturned = MAKEWORD(2, HIBYTE(wVersionRequested));
+            }
+            else
+            {
+                /* The highest version we support is 2.2 */
+                VersionReturned = MAKEWORD(2, 2);
+            }
+            break;
+
+        default:
+
+            /* Return 2.2 */
+            VersionReturned = MAKEWORD(2, 2);;
+            break;
     }
 
-    lpWSAData->wVersion     = wVersionRequested;
+    /* Return the Version Requested, unless error */
+    lpWSAData->wVersion = VersionReturned;
+
     lpWSAData->wHighVersion = MAKEWORD(2,2);
     lstrcpyA(lpWSAData->szDescription, "WinSock 2.0");
     lstrcpyA(lpWSAData->szSystemStatus, "Running");
-    lpWSAData->iMaxSockets  = 0;
-    lpWSAData->iMaxUdpDg    = 0;
     lpWSAData->lpVendorInfo = NULL;
 
     if (LOBYTE(wVersionRequested) == 1)
@@ -124,7 +133,7 @@ WSAStartup(IN  WORD wVersionRequested,
 
     WSASETINITIALIZED;
 
-    return NO_ERROR;
+    return ErrorCode;
 }