diff options
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 25 |
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"; |