Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ntp-packet-parser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntp-packet-parser

A parser for NTP UDP packets

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NPM downloads Build Status NPM version

NTP packet parser

Library to parse NTP response packets according to RFC 5905 into a easy-to-use structure. It does not apply any validations or calculations regarding the time but solely parses the data.

See buffcode/ntp-time-sync for an implementation.

Installation

yarn add ntp-packet-parser

Usage

ES6 style

import { NtpPacketParser } from "ntp-packet-parser";

/** const udpPacket = new Buffer(...); **/
const result = NtpPacketParser.parse(udpPacket);

Legacy style

var NtpPacketParser = require("ntp-packet-parser").NtpPacketParser;

/** const udpPacket = new Buffer(...); **/
var result = NtpPacketParser.parse(udpPacket);

Structure

The response from NtpPacketParser.parse will return the following object structure:

PropertyTypeDescription
leapIndicatorIntegerWarning of an impending leap second to be inserted or deleted in the last minute of the current month
versionIntegerNTP version number, currently 4
modeIntegerRequest/response mode
stratumIntegerStratum of the server
pollIntegerInteger representing the maximum interval in log2 seconds between successive messages (Note: you need to apply Math.pow(2, <value>) to get the real value)
precisionIntegerInteger representing the precision of the system clock in log2 seconds (Note: you need to apply Math.pow(2, <value>) to get the real value)
rootDelayDateTotal round-trip delay to the reference clock
rootDispersionDateTotal dispersion to the reference clock
referenceIdStringString to identify the particular server or reference clock
referenceTimestampDateTime when the system clock was last set or corrected
originTimestampDateTime at the client when the request departed for the server
receiveTimestampDateTime at the server when the request arrived from the client
transmitTimestampDateTime at the server when the response left for the client

To get the relative time for any Date property, calculate the difference between "Jan 01 1900 GMT" and the given date.

let rootDelayInMilliseconds = result.rootDelay.getTime() - new Date("Jan 01 1900 GMT").getTime(); 

For further explanations on the possible values of these properties please refer to RFC 5909, Page 19ff.

Testing

Some tests regarding structure, response and error handling exist. To run them locally:

yarn test

Contributing

Please file a PR against master.

License

GNU General Public License Version 3

Keywords

FAQs

Package last updated on 25 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc