From: unknown Date: Fri, 2 Sep 2011 22:25:39 +0000 (+0200) Subject: [fix] - fix win32_inet_pton X-Git-Tag: upstream/1.9.6^2~312 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=f5a488524d22369a13582caf4fd0346a10418138 [fix] - fix win32_inet_pton --- diff --git a/win32/win32_compat.c b/win32/win32_compat.c index b8d8680..65450eb 100644 --- a/win32/win32_compat.c +++ b/win32/win32_compat.c @@ -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; } /*