ping: fancier sub-ms printing (I think %Ng is supposed to do this, but mine might be broken?)
This commit is contained in:
parent
7d5bfe4a63
commit
33848f8a8e
14
apps/ping.c
14
apps/ping.c
@ -141,10 +141,18 @@ int main(int argc, char * argv[]) {
|
||||
size_t len = ntohs(ipv4->length) - sizeof(struct IPV4_Header);
|
||||
/* Get the address */
|
||||
char * from = inet_ntoa(*(struct in_addr*)&ipv4->source);
|
||||
printf("%zd bytes from %s: icmp_seq=%d ttl=%d time=%zd ms\n",
|
||||
int time_taken = (rcvd_at - sent_at);
|
||||
printf("%zd bytes from %s: icmp_seq=%d ttl=%d time=%d",
|
||||
len, from, ntohs(icmp->sequence_number), ipv4->ttl,
|
||||
(rcvd_at - sent_at) / 1000);
|
||||
|
||||
time_taken / 1000);
|
||||
if (time_taken < 1000) {
|
||||
printf(".%03d", time_taken % 1000);
|
||||
} else if (time_taken < 10000) {
|
||||
printf(".%02d", (time_taken / 10) % 100);
|
||||
} else if (time_taken < 100000) {
|
||||
printf(".%01d", (time_taken / 100) % 10);
|
||||
}
|
||||
printf(" ms\n");
|
||||
responses_received++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user