Skip to main content

Crate ntp_usg_wasm

Crate ntp_usg_wasm 

Source
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.