mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
ping: Fix off by one error in count argument
Previously, the count and total_pings comparison was evaluated after a ping was sent for that iteration. This would cause one extra ping to be sent greater than the specific count passed.
This commit is contained in:
parent
6cdb41ccab
commit
ef3605604e
1 changed files with 5 additions and 5 deletions
|
@ -152,17 +152,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
struct timeval tv_send;
|
struct timeval tv_send;
|
||||||
gettimeofday(&tv_send, nullptr);
|
gettimeofday(&tv_send, nullptr);
|
||||||
|
|
||||||
|
if (count && total_pings == count)
|
||||||
|
closing_statistics();
|
||||||
|
else
|
||||||
|
total_pings++;
|
||||||
|
|
||||||
rc = sendto(fd, ping_packet.data(), ping_packet.size(), 0, (const struct sockaddr*)&peer_address, sizeof(sockaddr_in));
|
rc = sendto(fd, ping_packet.data(), ping_packet.size(), 0, (const struct sockaddr*)&peer_address, sizeof(sockaddr_in));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count && total_pings == count)
|
|
||||||
closing_statistics();
|
|
||||||
else
|
|
||||||
total_pings++;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto pong_packet_result = ByteBuffer::create_uninitialized(
|
auto pong_packet_result = ByteBuffer::create_uninitialized(
|
||||||
sizeof(struct ip) + max_optional_header_size_in_bytes + sizeof(struct icmphdr) + payload_size);
|
sizeof(struct ip) + max_optional_header_size_in_bytes + sizeof(struct icmphdr) + payload_size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue