Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/session_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ nc_sock_bind_inet(int sock, const char *address, uint16_t port, int is_ipv4)
struct sockaddr_storage saddr;
struct sockaddr_in *saddr4;
struct sockaddr_in6 *saddr6;
int opt = 1;

memset(&saddr, 0, sizeof(struct sockaddr_storage));

Expand All @@ -307,6 +308,11 @@ nc_sock_bind_inet(int sock, const char *address, uint16_t port, int is_ipv4)
return -1;
}

if (setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &opt, sizeof(opt))) {
ERR(NULL, "Could not bind (%s).", strerror(errno));
return -1;
}

if (bind(sock, (struct sockaddr *)saddr4, sizeof(struct sockaddr_in)) == -1) {
ERR(NULL, "Could not bind %s:%" PRIu16 " (%s).", address, port, strerror(errno));
return -1;
Expand All @@ -328,6 +334,11 @@ nc_sock_bind_inet(int sock, const char *address, uint16_t port, int is_ipv4)
return -1;
}

if (setsockopt(sock, IPPROTO_IPV6, IPV6_FREEBIND, &opt, sizeof(opt))) {
ERR(NULL, "Could not bind (%s).", strerror(errno));
return -1;
}

if (bind(sock, (struct sockaddr *)saddr6, sizeof(struct sockaddr_in6)) == -1) {
ERR(NULL, "Could not bind [%s]:%" PRIu16 " (%s).", address, port, strerror(errno));
return -1;
Expand Down