Index: reactos/dll/win32/ws2_32/misc/ns.c
===================================================================
--- reactos/dll/win32/ws2_32/misc/ns.c	(revision 71496)
+++ reactos/dll/win32/ws2_32/misc/ns.c	(working copy)
@@ -869,16 +869,24 @@
 
     check_hostent(&p->Hostent);   /*XXX alloc_hostent*/
 
-    /* Hostname NULL - behave like gethostname */
+    /* Hostname NULL - return invalid param */
     if(name == NULL)
     {
+        WSASetLastError( WSA_INVALID_PARAMETER );
+        return NULL;
+    }
+
+    /* Hostname empty - behave like gethostname */
+    if (strlen(name) == 0)
+    {
         ret = gethostname(p->Hostent->h_name, MAX_HOSTNAME_LEN);
         if(ret)
         {
-            WSASetLastError( WSAHOST_NOT_FOUND ); //WSANO_DATA  ??
+            // error should already be set by gethostname
+            //WSASetLastError( WSAHOST_NOT_FOUND ); //WSANO_DATA  ??
             return NULL;
         }
-        return p->Hostent;
+        name = p->Hostent->h_name;
     }
 
     /* Is it an IPv6 address? */
@@ -933,7 +941,7 @@
                                 /* extra dns servers */ &dp,
                                 0);
 
-        if(dns_status == 0)
+        if(dns_status == 0 && dp != NULL)
         {
             //ASSERT(dp->wType == DNS_TYPE_A);
             //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA));
