diff options
Diffstat (limited to 'libcsoap')
-rw-r--r-- | libcsoap/soap-nudp.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libcsoap/soap-nudp.c b/libcsoap/soap-nudp.c index 8a2706c..ddcf74c 100644 --- a/libcsoap/soap-nudp.c +++ b/libcsoap/soap-nudp.c @@ -73,7 +73,50 @@ #include <libxml/uri.h> #ifdef WIN32 +#include <winsock2.h> #include <ws2tcpip.h> +int inet_pton(int af, const char *src, void *dst) +{ + /* struct sockaddr can't accomodate struct sockaddr_in6. */ + union { + struct sockaddr_in6 sin6; + struct sockaddr_in sin; + } sa; + size_t srcsize; + + switch(af) + { + case AF_INET: + sa.sin.sin_family = AF_INET; + srcsize = sizeof (sa.sin); + break; + case AF_INET6: + sa.sin6.sin6_family = AF_INET6; + srcsize = sizeof (sa.sin6); + break; + default: + errno = 76; + return -1; + } + + if (WSAStringToAddress(src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0) + { + errno = WSAGetLastError(); + return -1; + } + + switch(af) + { + case AF_INET: + memcpy(dst, &sa.sin.sin_addr, sizeof(sa.sin.sin_addr)); + break; + case AF_INET6: + memcpy(dst, &sa.sin6.sin6_addr, sizeof(sa.sin6.sin6_addr)); + break; + } + + return 1; +} #endif #include <nanohttp/nanohttp-error.h> |