#include <opencv2/opencv.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/icmp.hpp>
#include <iostream>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cstring>
using namespace cv;
using namespace boost::asio;
using namespace std;
string formatIPv6Address(const string& base, int x, int y, int r, int g, int b) {
stringstream ss;
ss << hex << base << ":"
<< setw(4) << setfill('0') << x << ":"
<< setw(4) << setfill('0') << y << ":"
<< setw(2) << setfill('0') << r
<< setw(2) << setfill('0') << g << ":"
<< setw(2) << setfill('0') << b << "ff";
return ss.str();
}
struct icmpv6_header {
uint8_t type;
uint8_t code;
uint16_t checksum;
uint16_t identifier;
uint16_t sequence_number;
};
void send_icmp_echo_request(io_context& io_context, const string& target_address) {
static ip::icmp::socket socket(io_context, ip::icmp::v6());
try {
if (!socket.is_open()) {
socket.open(ip::icmp::v6());
}
socket.set_option(ip::unicast::hops(128));
ip::icmp::resolver resolver(io_context);
ip::icmp::endpoint destination = *resolver.resolve(ip::icmp::v6(), target_address, "").begin();
icmpv6_header echo_req{};
echo_req.type = 128; // Echo Request
echo_req.code = 0;
echo_req.checksum = 0;
echo_req.identifier = htons(12345);
echo_req.sequence_number = htons(1);
char send_buf[sizeof(echo_req)];
std::memcpy(send_buf, &echo_req, sizeof(echo_req));
socket.send_to(buffer(send_buf, sizeof(send_buf)), destination);
}
catch (const std::exception& e) {
cerr << "Error sending ICMPv6 echo request: " << e.what() << endl;
socket.close();
throw;
}
}