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());