-
Notifications
You must be signed in to change notification settings - Fork 80
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
Custom IP Header #43
Comments
Hey @piedpieper ! Your code worked without any changes for me on linux: -module(icmpt).
-include("procket.hrl").
-export([t/0, t/1]).
%%%
%%% erlc -I include icmpt.erl
%%%
t() ->
t({192,168,7,83}).
t({IP1, IP2, IP3, IP4}) ->
% IpHeader_ = #ipv4{p = 1,
% saddr = {127,0,0,1},
% daddr = {192,168,7,83},
% len = byte_size(Icmp) + 20
% },
% IpHeader = pkt:ipv4(IpHeader_#ipv4{sum = pkt:makesum(IpHeader_)})
Packet = <<8,0,140,250,29,138,0,0,255,253,243,182,73,166,226,218,32,33,34,35,36,37,
38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,
62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79>>,
{ok, FD} = procket:open(0, [{protocol, icmp}, {type, raw}, {family, inet}]),
ok = procket:sendto(FD, Packet, 0,
<<
?PF_INET:16/native, % sin_family
0:16, % sin_port
IP1:8, IP2:8, IP3:8, IP4:8, % sin_addr
0:64 % sin_zero
>>
). Running it: 1> icmp:t().
ok The corresponding tcpdump:
Ping'ing the router: 2> icmp:t({192,168,214,1}). And the tcpdump shows an ICMP echo reply:
What OS are you testing with?
I've been meaning to update those old blog posts forever now. Sorry about that! Feel free to ask if you have any problems! |
Hi,
I am using pkt to create a custom ipv4 header:
IpHeader_ = #ipv4{p = 1, saddr = {127,0,0,1}, daddr = {192,168,7,83}, len = byte_size(Icmp) + 20},
IpHeader = pkt:ipv4(IpHeader_#ipv4{sum = pkt:makesum(IpHeader_)})
Using a static icmp echo packet: Packet = <<8,0,140,250,29,138,0,0,255,253,243,182,73,166,226,218,32,33,34,35,36,37,
38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,
62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79>>,
However, I am having issues sending the raw packet without the underlying protocol adding the header. I am following this blog here:http://blog.listincomprehension.com/2010/06/fun-with-raw-sockets-in-erlang-sending.html
which uses {ok, FD} = procket:listen(0, [{protocol, icmp}, {type, raw}, {family, inet}]) and then ok = procket:sendto(S, Packet, 0,
<<
?PF_INET:16/native, % sin_family
0:16, % sin_port
IP1:8, IP2:8, IP3:8, IP4:8, % sin_addr
0:64 % sin_zero
>>
),
But attempting to use procket:listen with those arguments gives an error, it seems like this repository has changed a bit since 2010!
So instead I've been using procket:open with those same options, {ok, FD} = procket:open(0, [{protocol, icmp}, {type, raw}, {family, packet}]),
but when i try to write or sendto i get an error enxio which corresponds to the device not existing...
I'm curious what you all think is the best route from here. I've hit a wall.
Thanks for your help!
The text was updated successfully, but these errors were encountered: