Expand description
WebAssembly bindings for NTP packet parsing and timestamp conversion.
This crate provides a thin JavaScript-friendly API over ntp_usg-proto for
use in browser-based packet inspection tools. Build with wasm-pack:
wasm-pack build crates/ntp_usg-wasm --target web§Examples (JavaScript)
import { NtpPacket, buildClientRequest, ntpTimestampToUnixSeconds } from 'ntp_usg-wasm';
// Build an NTP client request
const request = buildClientRequest();
// Parse a captured packet
const packet = new NtpPacket(capturedBytes);
console.log(`Version: ${packet.version}, Mode: ${packet.mode}`);
// Convert NTP timestamp to Unix seconds
const ts = packet.transmitTimestamp;
const unixSecs = ntpTimestampToUnixSeconds(ts[0], ts[1], Date.now() / 1000);Structs§
- NtpPacket
- Parsed NTP packet with JavaScript-friendly accessors.
Functions§
- build_
client_ request - Build a minimal NTPv4 client request packet (48 bytes).
- compute_
offset_ delay - Compute clock offset and round-trip delay from four NTP timestamps.
- ntp_
packet_ size - Returns the packed size of an NTP packet header in bytes (48).
- ntp_
timestamp_ to_ unix_ seconds - Convert an NTP timestamp to Unix seconds (with fractional part).
- parse_
extension_ fields_ js - Parse extension fields from bytes following the 48-byte NTP header.
- unix_
seconds_ to_ ntp_ timestamp - Convert Unix seconds to an NTP timestamp.
- validate_
response - Validate an NTP server response per RFC 5905 packet sanity checks.