npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ntp-packet-parser

v0.4.1

Published

A parser for NTP UDP packets

Downloads

9,476

Readme

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:

| Property | Type | Description | | :--- | :--- | :--- | | leapIndicator | Integer | Warning of an impending leap second to be inserted or deleted in the last minute of the current month | | version | Integer | NTP version number, currently 4 | | mode | Integer | Request/response mode | | stratum | Integer | Stratum of the server | | poll | Integer | Integer representing the maximum interval in log2 seconds between successive messages (Note: you need to apply Math.pow(2, <value>) to get the real value) | | precision | Integer | Integer representing the precision of the system clock in log2 seconds (Note: you need to apply Math.pow(2, <value>) to get the real value) | | rootDelay | Date | Total round-trip delay to the reference clock | | rootDispersion | Date | Total dispersion to the reference clock | | referenceId | String | String to identify the particular server or reference clock | | referenceTimestamp | Date | Time when the system clock was last set or corrected | | originTimestamp | Date | Time at the client when the request departed for the server | | receiveTimestamp | Date | Time at the server when the request arrived from the client | | transmitTimestamp | Date | Time 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