MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / readNtpTimestamp

Function readNtpTimestamp

ntp/ntp.ts:59–66  ·  view source on GitHub ↗
(buf: Buffer, offset: number)

Source from the content-addressed store, hash-verified

57 const ms = (sec - NTP_EPOCH_OFFSET) * 1000 + Math.floor((frac / 2 ** 32) * 1000);
58 return ms;
59}
60
61async function queryOnce(host: string, timeoutMs = 2500): Promise<NtpResult> {
62 return new Promise((resolve, reject) => {
63 const socket = dgram.createSocket("udp4");
64 let timeoutTimer: NodeJS.Timeout | null = null;
65
66 const packet = Buffer.alloc(48);
67 // LI = 0 (no warning), VN = 4, Mode = 3 (client) -> 0b00 100 011 = 0x23
68 packet[0] = 0x23;
69 // Transmit timestamp: set to client time (optional but good practice)

Callers 1

queryOnceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected