Browse Source

Fix enet_address_set_host potentially failing on Windows w/ MinGW

Vladyslav Hrytsenko 6 years ago
parent
commit
1d8a284220
1 changed files with 10 additions and 4 deletions
  1. 10 4
      include/enet.h

+ 10 - 4
include/enet.h

@@ -5198,16 +5198,22 @@ extern "C" {
     }
 
     int enet_address_set_host(ENetAddress *address, const char *name) {
-        struct hostent * hostEntry = NULL;
-
+        struct hostent *hostEntry = NULL;
         hostEntry = gethostbyname(name);
 
         if (hostEntry == NULL || hostEntry->h_addrtype != AF_INET) {
-            if (!inet_pton(AF_INET6, name, &address->host))
-                { return -1; }
+            if (!inet_pton(AF_INET6, name, &address->host)) {
+                return -1;
+            }
+
             return 0;
         }
 
+        ((enet_uint32 *)&address->host.s6_addr)[0] = 0;
+        ((enet_uint32 *)&address->host.s6_addr)[1] = 0;
+        ((enet_uint32 *)&address->host.s6_addr)[2] = htonl(0xffff);
+        ((enet_uint32 *)&address->host.s6_addr)[3] = *(enet_uint32 *)hostEntry->h_addr_list[0];
+
         return 0;
     }