mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Complete ping program
This commit is contained in:
parent
abd56314b8
commit
521f5b7912
@ -20,7 +20,13 @@ int main(int argc, char* argv[]){
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string ip(argv[0]);
|
||||
std::string ip(argv[1]);
|
||||
auto ip_parts = std::split(ip, '.');
|
||||
|
||||
if (ip_parts.size() != 4) {
|
||||
tlib::print_line("Invalid address IP");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto socket = tlib::socket_open(tlib::socket_domain::AF_INET, tlib::socket_type::RAW, tlib::socket_protocol::ICMP);
|
||||
|
||||
@ -29,7 +35,33 @@ int main(int argc, char* argv[]){
|
||||
return 1;
|
||||
}
|
||||
|
||||
tlib::icmp::packet_descriptor desc;
|
||||
desc.payload_size = 0;
|
||||
desc.target_ip = tlib::ip::make_address(std::atoui(ip_parts[0]), std::atoui(ip_parts[1]), std::atoui(ip_parts[2]), std::atoui(ip_parts[3]));
|
||||
desc.type = tlib::icmp::type::ECHO_REQUEST;
|
||||
desc.code = 0;
|
||||
|
||||
auto packet = tlib::prepare_packet(*socket, &desc);
|
||||
|
||||
if (!packet) {
|
||||
tlib::printf("ping: prepare_packet error: %s\n", std::error_message(packet.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto* command_header = reinterpret_cast<tlib::icmp::echo_request_header*>(packet->payload + packet->index);
|
||||
|
||||
command_header->identifier = 0x666;
|
||||
command_header->sequence = 0x1;
|
||||
|
||||
auto status = tlib::finalize_packet(*socket, *packet);
|
||||
if (!status) {
|
||||
tlib::printf("ping: finalize_packet error: %s\n", std::error_message(status.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
tlib::socket_close(*socket);
|
||||
|
||||
//TODO Wait for replies
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user