summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2012-06-26 10:12:55 +0000
committerjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2012-06-26 10:12:55 +0000
commit4f50a65041ba63d29c183190801c5899b377e27c (patch)
tree0b8965713ca796686638b114f8598627865a00b6 /test
parent45bc232d386ea9431bb6a104fdf0057eeac9570a (diff)
downloadneon-4f50a65041ba63d29c183190801c5899b377e27c.tar.gz
* 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
Diffstat (limited to 'test')
-rw-r--r--test/common/child.c22
-rw-r--r--test/common/child.h4
2 files changed, 25 insertions, 1 deletions
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;
}
@@ -320,10 +323,26 @@ 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);