add InetPton stub

This commit is contained in:
snow flurry 2024-03-01 20:07:17 -08:00
parent 3531419db4
commit 1150ab329b

40
src/win32shim.c Normal file
View file

@ -0,0 +1,40 @@
/* Custom InetPton implementation */
#include <Winsock2.h>
#include <ws2tcpip.h>
int __stdcall
InetPton(int Family,
const char *pszAddrString,
void *pAddrBuf)
{
IN_ADDR *addr = pAddrBuf;
unsigned long ulTmp;
if (Family != AF_INET) {
// Oops! We don't support that addr family
WSASetLastError(WSAEAFNOSUPPORT);
return -1;
}
if (!pAddrBuf || !pszAddrString ||
pszAddrString[0] == '\0') {
WSASetLastError(WSAEFAULT);
return -1;
}
// Technically we could just put the return val directly
// into addr->S_un.S_addr, but I don't like writing bad
// data unless absolutely necessary. So store it in a temp
// variable, first.
ulTmp = inet_addr(pszAddrString);
if (ulTmp == INADDR_NONE) {
// Not an IP address
WSASetLastError(WSAEFAULT);
return -1;
}
// S_un.S_addr is an unsigned long. Easy!
addr->S_un.S_addr = ulTmp;
return 0;
}