OSDN Git Service

libhb: fix gethostbyname failure on mingw
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 20 Sep 2009 16:30:07 +0000 (16:30 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 20 Sep 2009 16:30:07 +0000 (16:30 +0000)
winsock requires initialization before you can call any networking functions

git-svn-id: svn://localhost/HandBrake/trunk@2830 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/ports.c

index 6368bcb..1200386 100644 (file)
@@ -644,6 +644,23 @@ hb_net_t * hb_net_open( char * address, int port )
     struct sockaddr_in   sock;
     struct hostent     * host;
 
+#ifdef SYS_MINGW
+    WSADATA wsaData;
+    int iResult, winsock_init = 0;
+
+    // Initialize Winsock
+    if (!winsock_init)
+    {
+        iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
+        if (iResult != 0)
+        {
+            hb_log("WSAStartup failed: %d", iResult);
+            return NULL;
+        }
+        winsock_init = 1;
+    }
+#endif
+
     /* TODO: find out why this doesn't work on Win32 */
     if( !( host = gethostbyname( address ) ) )
     {