mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
peer: fix --port option.
We need SO_REUSEADDR, and we need to memset sockaddr to zero; valgrind complains for both IPv4 and IPv6, but the invalid sin6_flowinfo causes the IPv6 bind to fail altogether. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1102,16 +1102,32 @@ static int make_listen_fd(struct lightningd_state *dstate,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!addr || bind(fd, addr, len) == 0) {
|
if (addr) {
|
||||||
if (listen(fd, 5) == 0)
|
int on = 1;
|
||||||
return fd;
|
|
||||||
|
/* Re-use, please.. */
|
||||||
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
|
||||||
|
log_unusual(dstate->base_log,
|
||||||
|
"Failed setting socket reuse: %s",
|
||||||
|
strerror(errno));
|
||||||
|
|
||||||
|
if (bind(fd, addr, len) != 0) {
|
||||||
|
log_unusual(dstate->base_log,
|
||||||
|
"Failed to bind on %u socket: %s",
|
||||||
|
domain, strerror(errno));
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listen(fd, 5) != 0) {
|
||||||
log_unusual(dstate->base_log,
|
log_unusual(dstate->base_log,
|
||||||
"Failed to listen on %u socket: %s",
|
"Failed to listen on %u socket: %s",
|
||||||
domain, strerror(errno));
|
domain, strerror(errno));
|
||||||
} else
|
goto fail;
|
||||||
log_debug(dstate->base_log, "Failed to bind on %u socket: %s",
|
}
|
||||||
domain, strerror(errno));
|
return fd;
|
||||||
|
|
||||||
|
fail:
|
||||||
close_noerr(fd);
|
close_noerr(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1124,10 +1140,12 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
|
|||||||
int fd1, fd2;
|
int fd1, fd2;
|
||||||
u16 listen_port;
|
u16 listen_port;
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
addr.sin_port = htons(portnum);
|
addr.sin_port = htons(portnum);
|
||||||
|
|
||||||
|
memset(&addr6, 0, sizeof(addr6));
|
||||||
addr6.sin6_family = AF_INET6;
|
addr6.sin6_family = AF_INET6;
|
||||||
addr6.sin6_addr = in6addr_any;
|
addr6.sin6_addr = in6addr_any;
|
||||||
addr6.sin6_port = htons(portnum);
|
addr6.sin6_port = htons(portnum);
|
||||||
|
|||||||
Reference in New Issue
Block a user