[fix] - fix win32_inet_pton
authorunknown <memphis@machzwo.de>
Fri, 2 Sep 2011 22:25:39 +0000 (00:25 +0200)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 3 Sep 2011 05:28:43 +0000 (15:28 +1000)
win32/win32_compat.c

index b8d86807169fc433a6d416030821673d7ad36c6c..65450eb7dbc5c08af58bd2afb4d7e8d68a13900f 100644 (file)
@@ -48,10 +48,25 @@ static int dummy ATTRIBUTE((unused));
 int win32_inet_pton(int af, const char * src, void * dst)
 {
    int temp = sizeof(struct sockaddr_in);
-   char *srcNonConst = (char *)malloc(strlen(src)+1);
-   strncpy(srcNonConst,src,strlen(src));
-   WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp);
-   return temp;
+   int ret = -1;
+   int len = strlen(src) + 1;
+   wchar_t *srcNonConst = (wchar_t *)malloc(len);
+   memset(srcNonConst, 0, len);
+   MultiByteToWideChar(CP_ACP, NULL, src, -1, srcNonConst, len);
+
+   if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp) == 0 )
+   {
+          ret = 1;
+   }
+   else
+   {
+               if(     WSAGetLastError() == WSAEINVAL )
+               {
+                       ret = -1;
+               }
+   }
+   //free(srcNonConst);
+   return ret;
 }
 
 /*