From 4f50a65041ba63d29c183190801c5899b377e27c Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 26 Jun 2012 10:12:55 +0000 Subject: * test/common/child.c (new_spawn_server2): Factored out, return address used. Fix to ensure local host address is resolved. git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@1889 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845 --- test/common/child.c | 22 +++++++++++++++++++++- test/common/child.h | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/common/child.c b/test/common/child.c index 8ff7253..e7ca92a 100644 --- a/test/common/child.c +++ b/test/common/child.c @@ -54,7 +54,9 @@ static pid_t child = 0; int clength; -static struct in_addr lh_addr = {0}, hn_addr = {0}; +static struct in_addr lh_addr, hn_addr; + +static int have_lh_addr; const char *want_header = NULL; got_header_fn got_header = NULL; @@ -73,6 +75,7 @@ int lookup_localhost(void) /* this will break if a system is set up so that `localhost' does * not resolve to 127.0.0.1, but... */ lh_addr.s_addr = inet_addr("127.0.0.1"); + have_lh_addr = 1; return OK; } @@ -319,11 +322,27 @@ int spawn_server_repeat(int port, server_fn fn, void *userdata, int n) int new_spawn_server(int count, server_fn fn, void *userdata, unsigned int *port) +{ + ne_inet_addr *addr; + int ret; + + ret = new_spawn_server2(count, fn, userdata, &addr, port); + + ne_iaddr_free(addr); + + return ret; +} + +int new_spawn_server2(int count, server_fn fn, void *userdata, + ne_inet_addr **addr, unsigned int *port) { struct sockaddr_in sa; socklen_t salen = sizeof sa; int ls; + if (!have_lh_addr) + lookup_localhost(); + ls = do_listen(lh_addr, 0); ONN("could not bind/listen fd for server", ls < 0); @@ -332,6 +351,7 @@ int new_spawn_server(int count, server_fn fn, void *userdata, strerror(errno))); *port = ntohs(sa.sin_port); + *addr = ne_iaddr_make(ne_iaddr_ipv4, (unsigned char *)&lh_addr.s_addr); NE_DEBUG(NE_DBG_SOCKET, "child using port %u\n", *port); diff --git a/test/common/child.h b/test/common/child.h index ababb87..432fb6c 100644 --- a/test/common/child.h +++ b/test/common/child.h @@ -69,6 +69,10 @@ int spawn_server_repeat(int port, server_fn fn, void *userdata, int n); int new_spawn_server(int count, server_fn fn, void *userdata, unsigned int *port); +/* As per new_spawn_server, but also returns the bound address as *addr. */ +int new_spawn_server2(int count, server_fn fn, void *userdata, + ne_inet_addr **addr, unsigned int *port); + /* Blocks until child process exits, and gives return code of 'fn'. */ int await_server(void); -- cgit v1.2.1