Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost asio raw sockets

I'm trying to write a simple packet crafter with asio. And I need to send raw data by different protocols.

I'm trying to change ping example from asio documentation. In this example icpm-packet is sent via socket_.send_to method. This method encapsulates icmp-packet to ip-packet.

But I need to send ip header, then icmp header and then body of packet without any encapsulation! I'm trying to do it with socket.send method. But it throws an exception.

here's the code. In my class I have:

boost::asio::basic_raw_socket<raw> socket_;

When 'raw' is class of raw data protocol. This class is like 'icmp' class from asio with protocol_ equal IPPROTO_RAW.

Then I send data:

     IPV4header ip_header;
 //fill ip_header

 ICMPHeader echo_request;
 //fill icmp-header

 std::string body("---");

 // Encode the request packet.
 boost::asio::streambuf request_buffer;
 std::ostream os(&request_buffer);
 os << ip_header << echo_request << body;

 socket_.send(request_buffer.data(), request_buffer.size());
like image 761
Raman Avatar asked Sep 21 '26 15:09

Raman


1 Answers

Use setsockopt to set value IPPROTO_IP IP_HDRINCL to 0. It should help

like image 151
Roman Rek Avatar answered Sep 24 '26 03:09

Roman Rek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!