summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-02-07 14:41:44 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-02-07 14:41:44 +0000
commitaa2865c7a41e2f005fe08af9ff5d93d6a4055b4c (patch)
tree26f1bf1573144fd4e37af86d28e0e922bef4502e
parentb228fb5b146a53fa72fa4600ca85f9f9bb7ae105 (diff)
downloadnetsurf-aa2865c7a41e2f005fe08af9ff5d93d6a4055b4c.tar.gz
netsurf-aa2865c7a41e2f005fe08af9ff5d93d6a4055b4c.tar.bz2
add compatability for inet_pton and inet_aton
svn path=/trunk/netsurf/; revision=11627
-rw-r--r--utils/config.h16
-rw-r--r--utils/url.c3
-rw-r--r--utils/utils.c52
3 files changed, 69 insertions, 2 deletions
diff --git a/utils/config.h b/utils/config.h
index 950429b57..b05785390 100644
--- a/utils/config.h
+++ b/utils/config.h
@@ -47,6 +47,22 @@ char *strcasestr(const char *haystack, const char *needle);
char *strchrnul(const char *s, int c);
#endif
+#define HAVE_INETATON
+#if (defined(_WIN32))
+#undef HAVE_INETATON
+#include <winsock.h>
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+int inet_aton(const char *cp, struct in_addr *inp);
+#else
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
+#define HAVE_INETPTON
+#if (defined(_WIN32))
+#undef HAVE_INETPTON
+int inet_pton(int af, const char *src, void *dst);
+#endif
#define HAVE_UTSNAME
#if (defined(_WIN32))
diff --git a/utils/url.c b/utils/url.c
index e00f43824..ba7cc01bb 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -30,8 +30,7 @@
#include <string.h>
#include <regex.h>
#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+
#include "curl/curl.h"
#include "utils/config.h"
#include "utils/log.h"
diff --git a/utils/utils.c b/utils/utils.c
index 9561521cb..66c020f1d 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -31,6 +31,7 @@
#include <sys/time.h>
#include <regex.h>
#include <time.h>
+
#include "utils/config.h"
#define NDEBUG
#include "utils/log.h"
@@ -532,4 +533,55 @@ char *realpath(const char *path, char *resolved_path)
return ret;
}
+#ifndef HAVE_INETATON
+
+
+int inet_aton(const char *cp, struct in_addr *inp)
+{
+ unsigned int b1, b2, b3, b4;
+ unsigned char c;
+
+ if (strspn(cp, "0123456789.") < strlen(cp))
+ return 0;
+
+ if (sscanf(cp, "%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c) != 4)
+ return 0;
+
+ if ((b1 > 255) || (b2 > 255) || (b3 > 255) || (b4 > 255))
+ return 0;
+
+ inp->s_addr = b4 << 24 | b3 << 16 | b2 << 8 | b1;
+
+ return 1;
+}
+
+#endif
+
+#ifndef HAVE_INETPTON
+
+int inet_pton(int af, const char *src, void *dst)
+{
+ int ret;
+
+ if (af == AF_INET) {
+ ret = inet_aton(src, dst);
+ }
+#if !defined(NO_IPV6)
+ else if (af == AF_INET6) {
+ /* TODO: implement v6 address support */
+ ret = -1;
+ errno = EAFNOSUPPORT;
+ }
+#endif
+ else {
+ ret = -1;
+ errno = EAFNOSUPPORT;
+ }
+
+ return ret;
+}
+
+#endif
+
+
#endif