wincompat: recent mingw has inet_ntop/inet_pton
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b637db4692
commit
66714e2c47
|
@ -25,5 +25,3 @@
|
||||||
char *strsep(char **str, const char *sep);
|
char *strsep(char **str, const char *sep);
|
||||||
ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp);
|
ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp);
|
||||||
ssize_t getline(char **buf, size_t *bufsiz, FILE *fp);
|
ssize_t getline(char **buf, size_t *bufsiz, FILE *fp);
|
||||||
int inet_pton(int af, const char *src, void *dst);
|
|
||||||
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
char *strsep(char **str, const char *sep)
|
char *strsep(char **str, const char *sep)
|
||||||
|
@ -69,37 +67,3 @@ ssize_t getline(char **buf, size_t *bufsiz, FILE *fp)
|
||||||
{
|
{
|
||||||
return getdelim(buf, bufsiz, '\n', fp);
|
return getdelim(buf, bufsiz, '\n', fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int inet_pton(int af, const char *src, void *dst)
|
|
||||||
{
|
|
||||||
struct sockaddr_storage ss = { 0 };
|
|
||||||
int size = sizeof(ss);
|
|
||||||
char s[INET6_ADDRSTRLEN + 1];
|
|
||||||
|
|
||||||
strncpy(s, src, INET6_ADDRSTRLEN + 1);
|
|
||||||
s[INET6_ADDRSTRLEN] = '\0';
|
|
||||||
|
|
||||||
if (WSAStringToAddress(s, af, NULL, (struct sockaddr *)&ss, &size))
|
|
||||||
return 0;
|
|
||||||
if (af == AF_INET)
|
|
||||||
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
|
|
||||||
else if (af == AF_INET6)
|
|
||||||
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
|
||||||
{
|
|
||||||
struct sockaddr_storage ss = { .ss_family = af };
|
|
||||||
unsigned long s = size;
|
|
||||||
|
|
||||||
if (af == AF_INET)
|
|
||||||
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
|
|
||||||
else if (af == AF_INET6)
|
|
||||||
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
return WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) ? NULL : dst;
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue