[erlang-questions] Send IP Message with Custom IP Header
asdf asdf
codewiget95@REDACTED
Wed May 9 17:03:20 CEST 2018
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>>,
I can send the ICMP properly and see it through Wireshark using the following:
{ok, FD} = procket:socket(inet, raw, icmp),
{ok, Socket} = gen_udp:open(0, [binary, {fd, FD}, inet]),
gen_udp:send(Socket, {192,168,7,83}, 0, Packet),
Now, if I Include the icmp header: NewPacket = <<IpHeader/binary, Packet/binary>> and send this, Wireshark shows a malformed ICMP packet. Gen_udp or procket, or someone down the line is still placing a standard icmp header on top of my custom one and treating it as payload.
I have tried setting raw C setsocketopts : inet:sockopts(Socket, [{raw, 0(IPPROTO_IP), 3 (IP_HDRINCL) , <<1:32/native>>(integer 1 for on)}]) to attempt to stop the socket from adding the header, but when I do this the packet doesn’t seem to leave the machine, and I can’t see it on Wireshark. The numbers for IPPROTO comes from the header file: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/in.h and IP_HDRINCL: http://students.mimuw.edu.pl/SO/Linux/Kod/include/linux/socket.h.html .
Is there any way to put a custom IP header on any ip packet in erlang?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180509/be75fbc0/attachment.htm>
More information about the erlang-questions
mailing list