From 8016b2c54625b761f5713c1b3f964dd37ad7e490 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 1 Sep 2020 15:44:27 -0400 Subject: [PATCH] ntpquery: Record destination timestamp as well --- Userland/ntpquery.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Userland/ntpquery.cpp b/Userland/ntpquery.cpp index f086b9bd1d..089d1daf8e 100644 --- a/Userland/ntpquery.cpp +++ b/Userland/ntpquery.cpp @@ -168,6 +168,7 @@ int main(int argc, char** argv) socklen_t peer_address_size = sizeof(peer_address); rc = recvfrom(fd, &packet, sizeof(packet), 0, (struct sockaddr*)&peer_address, &peer_address_size); + gettimeofday(&t, nullptr); if (rc < 0) { perror("recvfrom"); return 1; @@ -177,6 +178,11 @@ int main(int argc, char** argv) return 1; } + NtpTimestamp origin_timestamp = be64toh(packet.origin_timestamp); + NtpTimestamp receive_timestamp = be64toh(packet.receive_timestamp); + NtpTimestamp transmit_timestamp = be64toh(packet.transmit_timestamp); + NtpTimestamp destination_timestamp = ntp_timestamp_from_timeval(t); + printf("NTP response from %s:\n", inet_ntoa(peer_address.sin_addr)); printf("Leap Information: %d\n", packet.li_vn_mode >> 6); printf("Version Number: %d\n", (packet.li_vn_mode >> 3) & 7); @@ -187,8 +193,9 @@ int main(int argc, char** argv) printf("Root delay: %#x\n", ntohl(packet.root_delay)); printf("Root dispersion: %#x\n", ntohl(packet.root_dispersion)); printf("Reference ID: %#x\n", ntohl(packet.reference_id)); - printf("Reference timestamp: %#016llx (%s)\n", be64toh(packet.reference_timestamp), format_ntp_timestamp(be64toh(packet.reference_timestamp)).characters()); - printf("Origin timestamp: %#016llx (%s)\n", be64toh(packet.origin_timestamp), format_ntp_timestamp(be64toh(packet.origin_timestamp)).characters()); - printf("Receive timestamp: %#016llx (%s)\n", be64toh(packet.receive_timestamp), format_ntp_timestamp(be64toh(packet.receive_timestamp)).characters()); - printf("Transmit timestamp: %#016llx (%s)\n", be64toh(packet.transmit_timestamp), format_ntp_timestamp(be64toh(packet.transmit_timestamp)).characters()); + printf("Reference timestamp: %#016llx (%s)\n", be64toh(packet.reference_timestamp), format_ntp_timestamp(be64toh(packet.reference_timestamp)).characters()); + printf("Origin timestamp: %#016llx (%s)\n", origin_timestamp, format_ntp_timestamp(origin_timestamp).characters()); + printf("Receive timestamp: %#016llx (%s)\n", receive_timestamp, format_ntp_timestamp(receive_timestamp).characters()); + printf("Transmit timestamp: %#016llx (%s)\n", transmit_timestamp, format_ntp_timestamp(transmit_timestamp).characters()); + printf("Destination timestamp: %#016llx (%s)\n", destination_timestamp, format_ntp_timestamp(destination_timestamp).characters()); }