The last patch didn't stop my program from SEGVing. The attached patch seems to solve the problem.
It seems that gethostbyname() was the culprit. gethostbyname_r() is not a standard function, so this will need to have a ./configure test for it. This means of course that on platforms which lack gethostbyname_r() the library will never be thread-safe. -- russ...@coker.com.au http://etbe.coker.com.au/ My Main Blog http://doc.coker.com.au/ My Documents Blog
diff -ru libcsoap-1.1.0.bak/nanohttp/nanohttp-socket.c libcsoap-1.1.0/nanohttp/nanohttp-socket.c --- libcsoap-1.1.0.bak/nanohttp/nanohttp-socket.c 2009-04-07 15:19:25.000000000 +1000 +++ libcsoap-1.1.0/nanohttp/nanohttp-socket.c 2009-04-07 19:51:15.000000000 +1000 @@ -176,19 +176,30 @@ { struct sockaddr_in address; struct hostent *host; - char *ip; +#define GETHOSTBYNAME_R +#ifdef 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 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 +319,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 +335,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;