diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-02-23 20:08:51 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-02-23 20:08:51 +0100 |
commit | 48a3812435c15c77c1ae752322cff63c8e0b092d (patch) | |
tree | 3996b37d6230f65b63643827d5bd05efa9d55c75 /src | |
parent | 9a0cba318b42ea3c375f6232d7d0b8e74e60ae2b (diff) | |
download | fastd-48a3812435c15c77c1ae752322cff63c8e0b092d.tar fastd-48a3812435c15c77c1ae752322cff63c8e0b092d.zip |
Fail initialization when a default socket can't be bound
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/fastd.c b/src/fastd.c index cf72dfc..8b6ea94 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -268,7 +268,7 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b return -1; } -static void bind_sockets(fastd_context_t *ctx) { +static bool bind_sockets(fastd_context_t *ctx) { unsigned i; for (i = 0; i < ctx->n_socks; i++) { @@ -284,6 +284,11 @@ static void bind_sockets(fastd_context_t *ctx) { pr_info(ctx, "successfully bound to %B", &ctx->socks[i].addr->addr); } } + + if ((ctx->sock_default_v4 && ctx->sock_default_v4->fd < 0) || (ctx->sock_default_v6 && ctx->sock_default_v6->fd < 0)) + return false; + + return true; } fastd_socket_t* fastd_socket_open(fastd_context_t *ctx, fastd_peer_t *peer, int af) { @@ -1151,7 +1156,9 @@ int main(int argc, char *argv[]) { crypto_init(&ctx); init_sockets(&ctx); - bind_sockets(&ctx); + + if (!bind_sockets(&ctx)) + exit_error(&ctx, "unable to bind default socket"); init_tuntap(&ctx); |