by vkoskiv on 9/6/23, 8:59 PM with 18 comments
Is this just me? I was doing some late night hacking on a System 6 NTP client I'm working on, and I couldn't figure this out, until I looked at the tcpdump log and observed the date coming in wrong from Apple's timeserver. I can reproduce this with `ntpdate` and the SerenityOS `ntpquery` as well, so it can't be my code.
I always get this same reference timestamp back: 3889764561.575988850 (2023-04-06T10:09:21Z)
by askbjoernhansen on 9/6/23, 10:00 PM
by nilespotter on 9/6/23, 9:26 PM
# ntpdate -q time.apple.com
server 17.253.82.253, stratum 1, offset +0.044020, delay 0.06635
server 17.253.82.125, stratum 1, offset +0.045065, delay 0.06586
server 17.253.16.125, stratum 1, offset +0.044869, delay 0.05829
6 Sep 15:25:18 ntpdate[65639]: adjust time server 17.253.16.125 offset +0.044869 secby drewolbrich on 9/6/23, 9:35 PM
by threeseed on 9/6/23, 9:32 PM
import socket
import struct
import time
NTP_SERVER = "time.apple.com"
NTP_PORT = 123
TIME1970 = 2208988800
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data = b'\x1b' + 47 \* b'\0'
client.sendto(data, (NTP_SERVER, NTP_PORT))
data, addr = client.recvfrom(1024)
if data:
t = struct.unpack('!12I', data)[10]
t -= TIME1970
print("Current time:", time.ctime(t))by vkoskiv on 9/7/23, 6:36 AM
by ChristianGeek on 9/6/23, 9:41 PM
by DeRock on 9/6/23, 9:34 PM
$ sntp -n 1 time.apple.com | grep t1
t1: E8A36E57.9BB5D031 (3903024727.608242999)
# Subtract delta from unix time epoch to NTP epoch
# NTP epoch is January 1, 1900, Unix epoch is January 1, 1970
$ date -r $(expr 3903024727 - 2208988800)
Wed Sep 6 14:32:07 PDT 2023
Works for me.by newman314 on 9/6/23, 9:50 PM
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- time.cloudflare.com 3 6 37 5 -2135us[-2132us] +/- 18ms
^- time.cloudflare.com 3 6 37 3 -1514us[-1511us] +/- 18ms
^- virginia.time.system76.c> 2 6 37 4 -2250us[-2247us] +/- 54ms
^- ohio.time.system76.com 2 6 37 2 -4525us[-4522us] +/- 42ms
^- oregon.time.system76.com 2 6 37 3 +742us[ +745us] +/- 30ms
^? 52.148.114.188 3 6 37 3 -544us[ -541us] +/- 124ms
^? defra1-ntp-004.aaplimg.c> 1 6 37 3 -1297us[-1294us] +/- 79ms
^? time4.facebook.com 1 6 37 4 -73us[ -71us] +/- 36ms
^? ec2-54-81-127-33.compute> 4 6 37 2 -369us[ -366us] +/- 35ms
^? time-a-wwv.nist.gov 1 6 17 42 +5816us[+5858us] +/- 24ms