Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying the source address of an outgoing connection using IO::Socket::* #6399

Open
p6rt opened this issue Jul 19, 2017 · 4 comments
Open
Assignees

Comments

@p6rt
Copy link

p6rt commented Jul 19, 2017

Migrated from rt.perl.org#131766 (status was 'new')

Searchable as RT131766$

@p6rt
Copy link
Author

p6rt commented Jul 19, 2017

From @AlexDaniel

It should be possible to specify the source address of outgoing (client) connections. This is especially useful if the machine has more than one IP address.

Examples in other software​:
* wget supports --bind-address parameter​: https://www.gnu.org/software/wget/manual/wget.html#Download-Options
* Python accepts optional “source_address” parameter​: https://docs.python.org/2/library/socket.html#socket.create_connection
* “bind before connect”, a blog post that seems to be relevant​: https://idea.popcount.org/2014-04-03-bind-before-connect/
* curl seems to allow it too, but surprisingly it can also accept the interface name​: https://curl.haxx.se/docs/manpage.html#--interface

It is possible to find more examples of languages that support it, but I'm sold already.

My best guess is that it is doable by simply calling uv_tcp_bind for outgoing connections.

Relevant links​:
* https://github.com/MoarVM/MoarVM/blob/2a79727deb78105c8c9f660a1136a3db1179b09b/src/io/asyncsocket.c#L532-L533
* https://github.com/MoarVM/MoarVM/blob/2a79727deb78105c8c9f660a1136a3db1179b09b/src/io/asyncsocket.c#L681-L683

@AlexDaniel
Copy link
Member

There were a series of pull requests to resolve this, but unfortunately it's a little bit stuck.

@Kaiepi, any thoughts?

@Kaiepi
Copy link

Kaiepi commented Feb 10, 2020

Bind before connect is something I'm working towards making possible with MoarVM/MoarVM#1231 / Raku/nqp#597 / rakudo/rakudo#3451. With those it'd be possible to call a bind method (which I don't think I actually have written yet) before calling connect to do this, but it'd be useful to be able to deal with this from the connect method alone as well.

I'm OK with adding source host and port parameters to IO::Socket::INET.connect, but the way the PR handles this by adding more behaviour to nqp::connect conflicts somewhat with how I was approaching this.

@AlexDaniel
Copy link
Member

OK, I see. Mind if I assign you here?

Kaiepi added a commit to Kaiepi/rakudo that referenced this issue Feb 11, 2020
This adds localhost and localport named parameters to
IO::Socket::INET.connect, which allows you to specify an address to bind
to before connecting.

Fixes Raku/old-issue-tracker#6399
Kaiepi added a commit to Kaiepi/rakudo that referenced this issue Feb 15, 2020
This adds localhost and localport named parameters to
IO::Socket::INET.connect, which allows you to specify an address to bind
to before connecting.

Fixes Raku/old-issue-tracker#6399
Kaiepi added a commit to Kaiepi/rakudo that referenced this issue Apr 1, 2020
This adds localhost and localport named parameters to
IO::Socket::INET.connect, which allows you to specify an address to bind
to before connecting.

Fixes Raku/old-issue-tracker#6399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants