--- tl.orig/configure.ac
+++ tl/configure.ac
@@ -61,7 +61,7 @@
 AC_FUNC_VPRINTF
 AC_FUNC_STRFTIME
 AC_FUNC_SELECT_ARGTYPES
-AC_CHECK_FUNCS([gethostbyname inet_ntoa memmove memset mkdir select socket strchr strdup strncasecmp strpbrk strspn strstr strtol])
+AC_CHECK_FUNCS([gethostbyname gethostbyname_r inet_ntoa memmove memset mkdir select socket strchr strdup strncasecmp strpbrk strspn strstr strtol])
 
 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
 dnl
--- tl.orig/nanohttp/nanohttp-socket.c
+++ tl/nanohttp/nanohttp-socket.c
@@ -176,19 +176,29 @@
 {
   struct sockaddr_in address;
   struct hostent *host;
-  char *ip;
+#ifdef HAVE_GETHOSTBYNAME_R
+  struct hostent hostbuf;
+  char gethostbyname_buf[1024];
+  int h_errnop;
+#endif
+  struct in_addr **h_addr_list;
 
   if ((dsock->sock = socket(AF_INET, SOCK_STREAM, 0)) <= 0)
     return herror_new("hsocket_open", HSOCKET_ERROR_CREATE,
                       "Socket error (%s)", strerror(errno));
 
   /* Get host data */
-  if (!(host = gethostbyname(hostname)))
+#ifdef HAVE_GETHOSTBYNAME_R
+  gethostbyname_r(hostname, &hostbuf, gethostbyname_buf, sizeof(gethostbyname_buf), &host, &h_errnop);
+#else
+  host = gethostbyname(hostname);
+#endif
+  if(!host)
     return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME,
                       "Socket error (%s)", strerror(errno));
 
-  ip = inet_ntoa(*(struct in_addr *) *host->h_addr_list);
-  address.sin_addr.s_addr = inet_addr(ip);
+  h_addr_list = (struct in_addr **)host->h_addr_list;
+  address.sin_addr.s_addr = h_addr_list[0]->s_addr;
 
   /* set server addresss */
   address.sin_family = host->h_addrtype;
@@ -308,6 +318,7 @@
 hsocket_accept(hsocket_t * sock, hsocket_t * dest)
 {
   herror_t status;
+  char ntop_buf[16];
 
   if (sock->sock < 0)
     return herror_new("hsocket_accept", HSOCKET_ERROR_NOT_INITIALIZED,
@@ -323,7 +334,7 @@
   }
 
   log_verbose3("accepting connection from '%s' socket=%d",
-               SAVE_STR(((char *) inet_ntoa(dest->addr.sin_addr))),
+               SAVE_STR(((char *) inet_ntop(AF_INET, &dest->addr.sin_addr, ntop_buf, sizeof(dest->addr.sin_addr)))),
                dest->sock);
 
   return H_OK;
