Merge pull request #3397 from awakecoding/master
add missing inet_pton implementation on Windows
This commit is contained in:
commit
0c8af43153
@ -64,7 +64,8 @@
|
||||
|
||||
#if (_WIN32_WINNT < 0x0600)
|
||||
|
||||
PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize);
|
||||
WINPR_API PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize);
|
||||
WINPR_API INT inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf);
|
||||
|
||||
#endif /* (_WIN32_WINNT < 0x0600) */
|
||||
|
||||
|
@ -262,6 +262,29 @@ PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INT inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf)
|
||||
{
|
||||
SOCKADDR_STORAGE addr;
|
||||
int addr_len = sizeof(addr);
|
||||
|
||||
if ((Family != AF_INET) && (Family != AF_INET6))
|
||||
return -1;
|
||||
|
||||
if (WSAStringToAddressA((char*) pszAddrString, Family, NULL, (struct sockaddr*) &addr, &addr_len) != 0)
|
||||
return 0;
|
||||
|
||||
if (Family == AF_INET)
|
||||
{
|
||||
memcpy(pAddrBuf, &((struct sockaddr_in*) &addr)->sin_addr, sizeof(struct in_addr));
|
||||
}
|
||||
else if (Family == AF_INET6)
|
||||
{
|
||||
memcpy(pAddrBuf, &((struct sockaddr_in6*) &addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* (_WIN32_WINNT < 0x0600) */
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
Loading…
Reference in New Issue
Block a user