Bind TCP client socket (multi-interface)

Please post support and help requests here.
nogo
Posts: 4
Joined: 17 May 2016, 13:51

Bind TCP client socket (multi-interface)

Postby nogo » 17 May 2016, 14:46

Hi,
I've a conceptual question wrt the documentation (and perhaps implementation) of Poco StreamSockets and SocketImpl.
First of all my specific use case: A TCP client (proprietary app-layer protocol) running on a multi-interface host (several IPv4, several IPv6 addresses/interfaces) must contact a server. The client MUST use the right local interface (and optionally the right port). The application knows the right IPv4 address from cmd-line arguments.

Problem: The typical use of Poco StreamSocket is to create an instance of a StreamSocket and connect it to the server socket. No method to bind to a local interface. Going more into details reveals the StreamSocket::impl() method and the bind() method of the returned SocketImpl. But binding before connect results in a core dump (tried both, IPv4 address with port number zero=unspecified and IPv4 address with dedicated port) and bind after connect does not make much of a sense. System is Linux (Kubuntu 16.04) with default Poco dev libraries (1.58).

Reading through the documentation at http://pocoproject.org/docs/Poco.Net.So ... html#24524 reveals even in the latest release that "TCP clients should not bind a socket to a specific address." Why?

I guess there's a good reason, so before starting to debug the Poco libraries myself I'd like to find out what's behind this statement in SocketImpl. Can perhaps someone with insight comment on the background of this restriction? I consider the use case of "a client must use a specific local interface out of n available" to be a valid one. And TCP clients have ever since been able to bind to a specific interface. For Poco raw sockets and UDP sockets the client-side bind op works as expected.

Any straight-forward solution or experience on how to implement this for TCP? As next step I'd target TLS but that's another story...

thanks in advance,
nogo

alex
Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Bind TCP client socket (multi-interface)

Postby alex » 18 May 2016, 01:59

Why would you want to bind a client socket to a specific interface? Routing determines to which interface the traffic will go.

nogo
Posts: 4
Joined: 17 May 2016, 13:51

Re: Bind TCP client socket (multi-interface)

Postby nogo » 18 May 2016, 08:57

> Why would you want to bind a client socket to a specific interface? Routing determines to which interface the traffic will go.

Routing enforces policies in the sense of "the OS or admin knows better than the user what's good for the user". Measurement and OAM tools (and many applications, too) have legitimate reasons to go beyond the routing decisions that someone else has taken. These apps may not have rights to modify the routing (and even if they did, it would not help).
One particular example (there are many more): A device has active WiFi and 3G interfaces, the default route is set to WiFi. Measurements and OAM must measure the performance of the 3G link towards one specific reflecting node and monitor its availability (keep-alives). Without explicit client socket binding there's no way how this can be achieved. Moreover, even explicit routing does not help you if there's one single destination node (IP) shared for WiFi and 3G monitoring. Alternatively, the client may also need to use a specific port because of local policies.
So, please believe me: there are legitimate use cases for client socket binding whenever two or more interfaces are present. The BSD socket interface supports client socket binding for good reasons and I wonder why Poco doesn't.

alex
Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Bind TCP client socket (multi-interface)

Postby alex » 18 May 2016, 14:28

Poco does not have it because nobody ever needed it or asked for it. If you need it, send a pull request and we will consider it.

nogo
Posts: 4
Joined: 17 May 2016, 13:51

Re: Bind TCP client socket (multi-interface)

Postby nogo » 20 May 2016, 10:36

Excellent, I'll do this asap. Thanks!

GiriG
Posts: 1
Joined: 09 Jun 2015, 05:27

Re: Bind TCP client socket (multi-interface)

Postby GiriG » 28 Oct 2016, 05:46

i am also looking for similar feature how to check/contribute for this feature is there separate branch active.

guenter
Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Bind TCP client socket (multi-interface)

Postby guenter » 28 Oct 2016, 21:05

I created an issue to track this on GitHub: https://github.com/pocoproject/poco/issues/1475


Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests