Send IP Message with Custom IP Header

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Send IP Message with Custom IP Header

asdf asdf

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,

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: and IP_HDRINCL: . 

Is there any way to put a custom IP header on any ip packet in erlang?


erlang-questions mailing list
[hidden email]