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

pcap-dgram

v0.4.0

Published

Mock UDP socket based on pcap file data.

Downloads

20

Readme

pcap-dgram

Mock UDP socket based on pcap file data.

Build Status

Example

'use strict';

var PcapDgram = require('../dgram');
var path = require('path');

module.exports.example = function(test) {
  test.expect(8);

  var hello = new Buffer('Hello world!');
  var remoteAddr = '192.168.207.128';
  var remotePort = 137;

  // Create a dgram socket using a netbios name service pcap file
  var file = path.join(__dirname, 'data', 'netbios-ns-b-register-winxp.pcap');
  var pdgram = new PcapDgram(file, '192.168.207.2');

  // When we receive the netbios name service packet, validate it
  pdgram.on('message', function(msg, rinfo) {
    // assert values from inspecting pcap with tshark
    test.equal(68, msg.length);
    test.equal(msg.length, rinfo.size);
    test.equal(remoteAddr, rinfo.address);
    test.equal(remotePort, rinfo.port);

    // Simulate sending a response back
    pdgram.send(hello, 0, hello.length, rinfo.port, rinfo.address, function(error) {
      test.equal(null, error);
    });
  });

  // Validate the response was sent
  pdgram.on('output', function(msg, port, address) {
    test.equal(hello.toString(), msg.toString());
    test.equal(remotePort, port);
    test.equal(remoteAddr, address);
  });

  pdgram.on('close', function() {
    test.done();
  });
};

Limitations / TODO

  • Currently only supports IPv4.
  • Currently ignores all fragmented IP packets.

Class PcapDgram

The PcapDgram class implements the same API as the dgram.Socket class. Data is delivered to the 'message' event by reading data from a pcap file. Outgoing data is redirected to the 'output' event so that it can be validated for correctness.

var pdgram = new PcapDgram(pcapSource, address, opts)

  • pcapSource {String | Stream} If a String, pcapSource is interpreted as the name of a pcap file to read from. Otherwise pcapSource is treated as a stream providing pcap data.
  • address {String} An IPv4 address used in the pcap file. The dgram socket will act as that IP address. Packets sent to this address will be emitted via the 'message' event.
  • opts {Object | null} Optional parameters
    • port {Number | null} The UDP port associated with the address passed as the second argument. Packets sent to this port at the given address wil be emitted via the 'message' event. If not provided then the port will be automatically set to the port used on the first UDP packet sent to the address.
    • netmask {String} An IPv4 netmask to use when pretending to be the configured address. This mainly determines if packets sent to subnet specific broadcast addresses. For example, setting a netmask of '255.255.255.0' will cause the socket to deliver packets addressed like this '192.168.1.255'. Defaults to '255.255.255.255' meaning only unicast and full broadcast will packets will be delivered.

Event 'output'

The 'output' event will fire whenever the send() fuction is called. Instead of writing the data out to the specified remote host, the data is provided to this event instead. This allows test code to validate that the correct output is being produced by the code under test.

  • msg {Buffer} The UDP payload to send to the remote host
  • port {Number} The UDP port of the remote host
  • address {Address} The IPv4 address of the remote host