From 8d513103f66617e96234d19813ab655ed9d5d13d Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 16 Sep 2017 17:06:41 +0100 Subject: [PATCH] server/admin.h: Consolidate address construction during resolution. Previously, setting up the socket address was kind of scattered throughout the resolver code: the address family was set up front; the port number stashed a bit later; and then the address plugged in once the resolution job finished. Instead, keep the port number separate once we've worked out what it is, and build the entire socket address in one go at each site (once in the background-resolver callback, and once for parsing a numerical address). --- server/admin.c | 6 +++++- server/tripe.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/admin.c b/server/admin.c index 8cb44a3c..c5fed8b0 100644 --- a/server/admin.c +++ b/server/admin.c @@ -1028,7 +1028,9 @@ static void a_resolved(struct hostent *h, void *v) r->func(r, ARES_FAIL); } else { T( trace(T_ADMIN, "admin: resop %s ok", BGTAG(r)); ) + r->sa.sin.sin_family = AF_INET; memcpy(&r->sa.sin.sin_addr, h->h_addr, sizeof(struct in_addr)); + r->sa.sin.sin_port = htons(r->port); r->func(r, ARES_OK); } sel_rmtimer(&r->t); @@ -1130,7 +1132,7 @@ static void a_resolve(admin *a, admin_resop *r, const char *tag, a_fail(a, "invalid-port", "%lu", pt, A_END); goto fail; } - r->sa.sin.sin_port = htons(pt); + r->port = pt; /* --- Report backgrounding --- * * @@ -1147,6 +1149,8 @@ static void a_resolve(admin *a, admin_resop *r, const char *tag, if (inet_aton(av[i], &r->sa.sin.sin_addr)) { T( trace(T_ADMIN, "admin: resop %s done the easy way", BGTAG(r)); ) + r->sa.sin.sin_family = AF_INET; + r->sa.sin.sin_port = htons(r->port); func(r, ARES_OK); xfree(r->addr); a_bgrelease(&r->bg); diff --git a/server/tripe.h b/server/tripe.h index 0eae8dc5..baae9078 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -692,6 +692,7 @@ typedef struct admin_resop { bres_client r; /* Background resolver task */ sel_timer t; /* Timer for resolver */ addr sa; /* Socket address */ + unsigned port; /* Port number chosen */ size_t sasz; /* Socket address size */ void (*func)(struct admin_resop *, int); /* Handler */ } admin_resop; -- 2.11.0