summaryrefslogtreecommitdiffstats
path: root/src/resolve.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-01-24 13:21:48 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-01-24 13:21:48 +0100
commitd1b4837082a800978142a31d6b6d40e2e4814069 (patch)
treeba172e0b1aaab72108adb217042711500aa4d71c /src/resolve.c
parentbb15efd0202c134e4623a610ffbb73372d43408a (diff)
downloadfastd-d1b4837082a800978142a31d6b6d40e2e4814069.tar
fastd-d1b4837082a800978142a31d6b6d40e2e4814069.zip
resolver: write whole hostname instead of a pointer to the resolver pipe
Shouldn't make a difference, but feels cleaner now, and silences a clang-analyzer warning.
Diffstat (limited to 'src/resolve.c')
-rw-r--r--src/resolve.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/resolve.c b/src/resolve.c
index b1ef696..02a986d 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -69,25 +69,32 @@ static void* resolve_peer(void *varg) {
error = true;
}
- fastd_resolve_return_t ret;
- memset(&ret, 0, sizeof(ret));
+ size_t hostname_len = strlen(arg->hostname);
+ char buf[sizeof(fastd_resolve_return_t) + hostname_len];
- ret.hostname = arg->hostname;
- ret.constraints = arg->constraints;
+ fastd_resolve_return_t *ret = (void*)buf;
+ char *hostname = buf + sizeof(fastd_resolve_return_t);
+
+ memset(ret, 0, sizeof(fastd_resolve_return_t));
+
+ ret->constraints = arg->constraints;
+ ret->hostname_len = hostname_len;
+ memcpy(hostname, arg->hostname, hostname_len);
if (!error) {
pr_verbose(arg->ctx, "resolved host `%s' successfully", arg->hostname);
- memcpy(&ret.addr, res->ai_addr, res->ai_addrlen);
- fastd_peer_address_simplify(&ret.addr);
+ memcpy(&ret->addr, res->ai_addr, res->ai_addrlen);
+ fastd_peer_address_simplify(&ret->addr);
}
else {
- ret.addr.sa.sa_family = AF_UNSPEC;
+ ret->addr.sa.sa_family = AF_UNSPEC;
}
- if (write(arg->ctx->resolvewfd, &ret, sizeof(ret)) < 0)
+ if (write(arg->ctx->resolvewfd, buf, sizeof(buf)) < 0)
pr_error_errno(arg->ctx, "can't write resolve return");
freeaddrinfo(res);
+ free(arg->hostname);
free(arg);
return NULL;
@@ -102,14 +109,19 @@ void fastd_resolve_peer(fastd_context_t *ctx, fastd_peer_t *peer) {
if (timespec_diff(&ctx->now, &peer->last_resolve) < ctx->conf->min_resolve_interval*1000) {
pr_debug(ctx, "not resolving %P as it has been resolved a short time ago", peer);
- fastd_resolve_return_t ret;
- memset(&ret, 0, sizeof(ret));
+ size_t hostname_len = strlen(peer->config->hostname);
+ char buf[sizeof(fastd_resolve_return_t) + hostname_len];
+
+ fastd_resolve_return_t *ret = (void*)buf;
+ char *hostname = buf + sizeof(fastd_resolve_return_t);
+
+ memset(ret, 0, sizeof(fastd_resolve_return_t));
- ret.hostname = strdup(peer->config->hostname);
- ret.constraints = peer->config->address;
- ret.addr = peer->address;
+ ret->constraints = peer->config->address;
+ ret->hostname_len = hostname_len;
+ memcpy(hostname, peer->config->hostname, hostname_len);
- if (write(ctx->resolvewfd, &ret, sizeof(ret)) < 0)
+ if (write(ctx->resolvewfd, buf, sizeof(buf)) < 0)
pr_error_errno(ctx, "can't write resolve return");
return;