summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-02-18 01:41:17 +0100
committerGravatar Martin Szulecki2013-02-18 01:41:17 +0100
commitd59524aa95f17f53ccf21bf1da38a8c1c2d64577 (patch)
tree431feeb17e861338d413435d95b69122c00f6c13
parent24f2f1a1286baebcfc55c6133e2962d3b7d8194a (diff)
downloadcsoap-d59524aa95f17f53ccf21bf1da38a8c1c2d64577.tar.gz
csoap-d59524aa95f17f53ccf21bf1da38a8c1c2d64577.tar.bz2
Define missing inet_pton() for WIN32 builds
-rw-r--r--libcsoap/soap-nudp.c43
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>