diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-04 23:54:24 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-04 23:54:24 +0200 |
commit | 95c81c5d77398517c5d84c4eb2704732a3fb9a41 (patch) | |
tree | 4e305f917c6ccfa50d037b3190ad53c5542892e8 /src/socket.c | |
parent | 4bb2d6fb99723dfad2dbf405007eeba275652afc (diff) | |
download | fastd-95c81c5d77398517c5d84c4eb2704732a3fb9a41.tar fastd-95c81c5d77398517c5d84c4eb2704732a3fb9a41.zip |
Support dynamic binds with extra options (interface binds, specific addresses...)
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/socket.c b/src/socket.c index 7d78b7f..e72ec94 100644 --- a/src/socket.c +++ b/src/socket.c @@ -199,6 +199,9 @@ bool fastd_socket_handle_binds(void) { if (ctx.socks[i].fd >= 0) continue; + if (!ctx.socks[i].addr) + continue; + ctx.socks[i].fd = bind_socket(ctx.socks[i].addr, ctx.socks[i].fd < -1); if (ctx.socks[i].fd >= 0) { @@ -226,11 +229,20 @@ bool fastd_socket_handle_binds(void) { return true; } -/** Opens a single unbound socket for the given address family */ +/** Opens a single socket bound to a random port for the given address family */ fastd_socket_t * fastd_socket_open(fastd_peer_t *peer, int af) { const fastd_bind_address_t any_address = { .addr.sa.sa_family = af }; - int fd = bind_socket(&any_address, true); + const fastd_bind_address_t *bind_address; + + if (af == AF_INET && conf.bind_addr_default_v4) + bind_address = conf.bind_addr_default_v4; + else if (af == AF_INET6 && conf.bind_addr_default_v6) + bind_address = conf.bind_addr_default_v6; + else + bind_address = &any_address; + + int fd = bind_socket(bind_address, true); if (fd < 0) return NULL; |