1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +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:
brapru 2022-02-14 06:09:28 -05:00 committed by Andreas Kling
parent 6cdb41ccab
commit ef3605604e

View file

@ -152,17 +152,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
struct timeval tv_send;
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));
if (rc < 0) {
perror("sendto");
return 1;
}
if (count && total_pings == count)
closing_statistics();
else
total_pings++;
for (;;) {
auto pong_packet_result = ByteBuffer::create_uninitialized(
sizeof(struct ip) + max_optional_header_size_in_bytes + sizeof(struct icmphdr) + payload_size);