Skip to content

Commit

Permalink
inet_pton: Fix for older compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
Iswenzz committed Mar 17, 2023
1 parent 069933d commit e8273b5
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/sys_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,32 @@
#define IPV6_V6ONLY 27 // Treat wildcard bind as AF_INET6-only.
#endif

// int inet_pton(int af, const char *src, void *dst)
// {
// struct sockaddr_storage sin;
// int addrSize = sizeof(sin);
// char address[256];
// strncpy(address, src, sizeof(address));

// int rc = WSAStringToAddressA( address, af, NULL, (SOCKADDR*)&sin, &addrSize );
// if(rc != 0)
// {
// return -1;
// }
// if(af == AF_INET)
// {
// *((struct in_addr *)dst) = ((struct sockaddr_in*)&sin)->sin_addr;
// return 1;
// }
// if(af == AF_INET6)
// {
// *((struct in_addr6 *)dst) = ((struct sockaddr_in6*)&sin)->sin6_addr;
// return 1;
// }
// return 0;
// }
#ifndef InetPtonA
int inet_pton(int af, const char *src, void *dst)
{
struct sockaddr_storage sin;
int addrSize = sizeof(sin);
char address[256];
strncpy(address, src, sizeof(address));

int rc = WSAStringToAddressA( address, af, NULL, (SOCKADDR*)&sin, &addrSize );
if(rc != 0)
{
return -1;
}
if(af == AF_INET)
{
*((struct in_addr *)dst) = ((struct sockaddr_in*)&sin)->sin_addr;
return 1;
}
if(af == AF_INET6)
{
*((struct in_addr6 *)dst) = ((struct sockaddr_in6*)&sin)->sin6_addr;
return 1;
}
return 0;
}
#endif

#else

Expand Down

0 comments on commit e8273b5

Please sign in to comment.