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 LocalAddr/bind IP for outgoing requests #112

Open
AndreiG6 opened this issue Jun 5, 2018 · 1 comment
Open

Specifying LocalAddr/bind IP for outgoing requests #112

AndreiG6 opened this issue Jun 5, 2018 · 1 comment

Comments

@AndreiG6
Copy link

AndreiG6 commented Jun 5, 2018

Hello,

I have tried using get_address, LocalAddr, and inet_aton to no avail in my attempts to set the outbound IP/local bind address. Looking over https://github.com/tokuhirom/Furl/blob/master/lib/Furl/HTTP.pm it seems as though IO::Socket can be used similar to https://github.com/tokuhirom/Furl/blob/master/lib/Furl/HTTP.pm#L1355 however I'm fairly sure I'm doing it wrong. For example, I tried doing the following:

my $furl = Furl->new(
inet_aton => sub { new IO::Socket::INET( LocalAddr => $ips[rand @ips]); },
ssl_opts => { SSL_verify_mode => '0' },
timeout => '30',
inactivity_timeout => '30',
max_redirects => '0',
headers => [ 'Accept-Encoding' => 'gzip', 'Connection' => 'close' ]
);
Which resulted in error:

Thread 20 terminated abnormally: Bad arg length for Socket::pack_sockaddr_in, length is 37, should be 4 at /usr/local/share/perl5/Furl/HTTP.pm line 676.

Does anyone have a working example for setting the outbound IP address, or perhaps a patch?

@kazuho
Copy link
Collaborator

kazuho commented Jun 5, 2018

You'd need to modify Furl to set the source address.

Calls to socket and connect happen at https://github.com/tokuhirom/Furl/blob/master/lib/Furl/HTTP.pm#L649-L652, but as you can see, Furl never calls bind in between, which IIUC is necessary to set the source address.

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

2 participants