diff --git a/libs/esl/src/esl.c b/libs/esl/src/esl.c index 44c5557b60..c8f2b7ead2 100644 --- a/libs/esl/src/esl.c +++ b/libs/esl/src/esl.c @@ -36,14 +36,6 @@ #define closesocket(x) close(x) #endif -#ifndef HAVE_GETHOSTBYNAME_R -extern int gethostbyname_r (const char *__name, - struct hostent *__result_buf, - char *__buf, size_t __buflen, - struct hostent **__result, - int *__h_errnump); -#endif - /* Written by Marc Espie, public domain */ @@ -456,7 +448,7 @@ esl_status_t esl_connect(esl_handle_t *handle, const char *host, esl_port_t port struct hostent *result; char sendbuf[256]; - int rval; + int rval = 0; const char *hval; if (!handle->mutex) { @@ -476,19 +468,18 @@ esl_status_t esl_connect(esl_handle_t *handle, const char *host, esl_port_t port memset(&handle->hostent, 0, sizeof(handle->hostent)); -#ifdef HAVE_GETHOSTBYNAME_R_FIVE - rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &handle->errnum); - result = handle->hostent; -#else - rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &result, &handle->errnum); -#endif + if ((result = gethostbyname(host))) { + handle->hostent = *result; + } else { + rval = -1; + } if (rval) { strerror_r(handle->errnum, handle->err, sizeof(handle->err)); goto fail; } - memcpy(&handle->sockaddr.sin_addr, result->h_addr, result->h_length); + memcpy(&handle->sockaddr.sin_addr, result->h_addr_list[0], result->h_length); rval = connect(handle->sock, (struct sockaddr *) &handle->sockaddr, sizeof(handle->sockaddr)); diff --git a/libs/esl/src/include/esl.h b/libs/esl/src/include/esl.h index 8d144cfefc..cf5fc08449 100644 --- a/libs/esl/src/include/esl.h +++ b/libs/esl/src/include/esl.h @@ -35,6 +35,10 @@ #define _ESL_H_ +#include +int vasprintf(char **ret, const char *format, va_list ap); + + #define esl_copy_string(_x, _y, _z) strncpy(_x, _y, _z - 1) #define esl_set_string(_x, _y) esl_copy_string(_x, _y, sizeof(_x))