summaryrefslogtreecommitdiffstats
path: root/src/fastd.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/fastd.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/fastd.c')
-rw-r--r--src/fastd.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 18f9d96..e48bb8a 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -851,19 +851,25 @@ static void handle_socket(fastd_context_t *ctx, fastd_socket_t *sock) {
static void handle_resolv_returns(fastd_context_t *ctx) {
fastd_resolve_return_t resolve_return;
- if (read(ctx->resolverfd, &resolve_return, sizeof(resolve_return)) < 0) {
+ while (read(ctx->resolverfd, &resolve_return, sizeof(resolve_return)) < 0) {
if (errno != EINTR)
- pr_warn(ctx, "read: %s", strerror(errno));
+ exit_errno(ctx, "handle_resolv_return: read");
+ }
- return;
+ char hostname[resolve_return.hostname_len+1];
+ while (read(ctx->resolverfd, hostname, resolve_return.hostname_len) < 0) {
+ if (errno != EINTR)
+ exit_errno(ctx, "handle_resolv_return: read");
}
+ hostname[resolve_return.hostname_len] = 0;
+
fastd_peer_t *peer;
for (peer = ctx->peers; peer; peer = peer->next) {
if (!peer->config)
continue;
- if (!strequal(peer->config->hostname, resolve_return.hostname))
+ if (!strequal(peer->config->hostname, hostname))
continue;
if (!fastd_peer_config_matches_dynamic(peer->config, &resolve_return.constraints))
@@ -875,13 +881,11 @@ static void handle_resolv_returns(fastd_context_t *ctx) {
send_handshake(ctx, peer);
}
else {
- pr_warn(ctx, "hostname `%s' resolved to address %I which is used by a fixed peer", resolve_return.hostname, &resolve_return.addr);
+ pr_warn(ctx, "hostname `%s' resolved to address %I which is used by a fixed peer", hostname, &resolve_return.addr);
fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500));
}
break;
}
-
- free(resolve_return.hostname);
}
static inline void handle_socket_error(fastd_context_t *ctx, fastd_socket_t *sock) {