aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2017-12-20 00:40:58 +0100
committerToni Uhlig <matzeton@googlemail.com>2017-12-20 00:40:58 +0100
commitdbfa491594e0c84079bebc991107e1b51a228433 (patch)
tree45c42b4abb81067f139b2acdffed18c8612577f8 /src/utils.c
parent8c051422c1673e57ce70cc9dccb6e136d901cc09 (diff)
ptunnel-ng:
* fixed mingw64 cross compile issues * using getaddrinfo instead of obsolete gethostbyname * removed IS_WINDOWS AM_CONDITIONAL
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 996baf7..3305456 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,7 +1,13 @@
#include <stdarg.h>
+#include <string.h>
#ifndef WIN32
#include <syslog.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#else
+#include <ws2tcpip.h>
#endif
#include <sys/time.h>
@@ -52,6 +58,25 @@ double time_as_double(void) {
return result;
}
+int host_to_addr(const char *hostname, uint32_t *result)
+{
+ int ret;
+ struct addrinfo *addrs = NULL;
+ struct addrinfo hints;
+ struct sockaddr_in *addr;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+
+ if ((ret = getaddrinfo(hostname, NULL, &hints, &addrs)) != 0)
+ return ret;
+ addr = (struct sockaddr_in *) addrs->ai_addr;
+ *result = *(uint32_t *) &addr->sin_addr;
+ freeaddrinfo(addrs);
+
+ return 0;
+}
+
#if 0
static const char hextab[] = "0123456789ABCDEF";