Send several pings

This commit is contained in:
Baptiste Wicht 2016-09-05 20:44:17 +02:00
parent f50b495e2d
commit 18b6e17893

View File

@ -47,6 +47,7 @@ int main(int argc, char* argv[]) {
desc.type = tlib::icmp::type::ECHO_REQUEST; desc.type = tlib::icmp::type::ECHO_REQUEST;
desc.code = 0; desc.code = 0;
for(size_t i = 0; i < 4; ++i){
auto packet = tlib::prepare_packet(*socket, &desc); auto packet = tlib::prepare_packet(*socket, &desc);
if (!packet) { if (!packet) {
@ -57,7 +58,7 @@ int main(int argc, char* argv[]) {
auto* command_header = reinterpret_cast<tlib::icmp::echo_request_header*>(packet->payload + packet->index); auto* command_header = reinterpret_cast<tlib::icmp::echo_request_header*>(packet->payload + packet->index);
command_header->identifier = 0x666; command_header->identifier = 0x666;
command_header->sequence = 0x1; command_header->sequence = 0x1 + i;
status = tlib::finalize_packet(*socket, *packet); status = tlib::finalize_packet(*socket, *packet);
if (!status) { if (!status) {
@ -76,11 +77,16 @@ int main(int argc, char* argv[]) {
auto command_type = static_cast<tlib::icmp::type>(icmp_header->type); auto command_type = static_cast<tlib::icmp::type>(icmp_header->type);
if(command_type == tlib::icmp::type::ECHO_REPLY){ if(command_type == tlib::icmp::type::ECHO_REPLY){
tlib::printf("reply received from %s\n", ip.c_str()); tlib::printf("Reply received from %s\n", ip.c_str());
} else {
tlib::printf("Unhandled command type received\n");
} }
tlib::release_packet(*p); tlib::release_packet(*p);
tlib::sleep_ms(1000);
}
status = tlib::listen(*socket, false); status = tlib::listen(*socket, false);
if (!status) { if (!status) {
tlib::printf("ping: listen error: %s\n", std::error_message(status.error())); tlib::printf("ping: listen error: %s\n", std::error_message(status.error()));