-
Notifications
You must be signed in to change notification settings - Fork 33
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
Sending packets via specific network interfaces #15
Comments
Hey @mszmurlo ! Use the % ping -I lo 127.0.0.1
{ok, S} = gen_icmp:open([{interface, "lo"}]),
gen_icmp:ping(S, ["127.0.0.1", "8.8.8.8"], []).
[{error,timeout,"8.8.8.8",{8,8,8,8}},
{ok,"127.0.0.1",
{127,0,0,1},
{127,0,0,1},
{50250,0,64,0},
<<" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO">>}] These options are documented here: Setting the source IP address using the % ping -I 127.0.0.1
{ok, S} = gen_icmp:open([{ip, "127.0.0.1"}]),
gen_icmp:ping(S, ["127.0.0.1", "8.8.8.8"], []). It seems procket will not attempt to bind() an ICMP socket. Should be simple to fix, I'll take a look at it. Thank you for opening the issue! And if you have any questions, please let me know! |
Thanks for the quick reply! |
No problem! The readme should have documented those options. BTW, if you don't want to manage the socket yourself, gen_icmp:ping(["127.0.0.1", "8.8.8.8"], [{interface, "lo"}]). |
All works fine on my RPi with 2 modems and a wifi connection. |
Allow setting the source address of ICMP sockets by calling bind(2) in the setuid helper. See: msantos/gen_icmp#15 For SOCK_RAW sockets, getaddrinfo(3) on Linux expects: * the service name (aka port) to be NULL * the node name to be non-NULL According to the Linux and FreeBSD man page, if the node name is NULL, default values of INADDR_ANY for IPv4 and IN6ADDR_ANY_INIT for IPv6 will be used. On Linux at least, passing NULL will result in an error. Set defaults of either "0.0.0.0" or "::" to avoid the error. Portability of these defaults still needs testing. Alternatively, setting of these options could be moved to erlang code, either in procket.erl or by the caller.
Hi,
This is not an issue but a feature inquiry (unless it already exists and I've missed it).
I need to send packets (mainly for ping and traceroute) through different interfaces and I couldn't find the way do do it. On the command line with the linux
ping
, you can set the option-I <interface>
or-I <address>
and the packets are sent through the interface with the proper source address regardless of the routing table.Thanks for the great work anyway : this lib is very useful.
Cheers
Maurycy
The text was updated successfully, but these errors were encountered: