[cdc_rsync] Fix issue with IPV6 localhosts (#93)

Fixes an issue with port forwarding when localhost on the remote
system maps to the IPV6 localhost. In that case the server would time
out on accept() since it creates an IPV4 socket, so the connection
is never established.

Also allows passing in port 0, so that it will auto-detect an
available port. This will be used in a future CL to remove the
necessity of running netstat/ss.
This commit is contained in:
Lutz Justen
2023-02-14 11:09:03 +01:00
committed by GitHub
parent fcc4cbc3f3
commit 5fd86e4625
4 changed files with 109 additions and 19 deletions
+11 -1
View File
@@ -18,8 +18,11 @@
#define CDC_RSYNC_SERVER_SERVER_SOCKET_H_
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "cdc_rsync/base/socket.h"
struct addrinfo;
namespace cdc_ft {
class ServerSocket : public Socket {
@@ -28,7 +31,9 @@ class ServerSocket : public Socket {
~ServerSocket();
// Starts listening for connections on |port|.
absl::Status StartListening(int port);
// Passing 0 as port will bind to any available port.
// Returns the port that was bound to.
absl::StatusOr<int> StartListening(int port);
// Stops listening for connections. No-op if already stopped/never started.
void StopListening();
@@ -50,6 +55,11 @@ class ServerSocket : public Socket {
size_t* bytes_received) override;
private:
// Called by StartListening() for a specific IPV4 or IPV6 |addr_info|.
// Passing 0 as port will bind to any available port.
// Returns the port that was bound to.
absl::StatusOr<int> StartListeningInternal(int port, addrinfo* addr);
std::unique_ptr<struct ServerSocketInfo> socket_info_;
};