X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=win32%2Fwin32_compat.c;h=65450eb7dbc5c08af58bd2afb4d7e8d68a13900f;hb=f5a488524d22369a13582caf4fd0346a10418138;hp=b8d86807169fc433a6d416030821673d7ad36c6c;hpb=75e8e264d68f241b2e4d5b4a846e90cda1266630;p=deb_libnfs.git 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; } /*