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

packet-socket

v1.0.1

Published

Node.js package implementing socket for receiving OSI layer 2 packets

Downloads

15

Readme

packet-socket

Node.js package implementing socket for receiving OSI layer 2 packets

API

Assume that packet-socket module is required in following examples.

var packet = require('packet-socket')

Opening socket

var socket = packet.openSocket({device: 'lo'})

openSocket call accepts options object as argument. Option device should contain interface name on which open raw packet socket.

Closing socket

socket.close()

Few words about address

Some functions require address as an argument. Formats accepted:

  • String 'aa:bb:cc:11:22:33'
  • Array [0xaa, 0xbb, 0xcc, 0x11, 0x22, 0x33]
  • Buffer new Buffer([0xaa, 0xbb, 0xcc, 0x11, 0x22, 0x33])

Joining and leaving Multicast Membership

socket.joinMC(packet.PROMISCIOUS)
socket.joinMC(packet.ALL_MULTICAST)
socket.joinMC('11:00:de:ad:be:ef')
socket.leaveMC(packet.PROMISCIOUS)
socket.leaveMC(packet.ALL_MULTICAST)
socket.leaveMC('11:00:de:ad:be:ef')

joinMC or leaveMC method accepts as argument either multicast address or integer constant:

  • PROMISCIOUS - sets interface to PROMISCIOUS mode, catching all packets
  • ALL_MULTICAST - catch all multicast messages

Sending

packet.send(new Buffer('message to send'), '58:00:00:00:00:01', function(err, bytes) {

})

Callback function argument will provide information if send failed, then err will contain information, if it is null, then bytes will contain number of bytes transferred.

Events

Socket returned by openSocket can emit events:

  • message - this event is emited when packet is received, it contain buffer with message received, source and destination addresses (in string format)
packet.on('message', function(message, source, destination) {
});
  • error - this event is emited in case of any error, it contain error object
packet.on('error', function(error) {});

Packet socket root reqirement

Opening packet (man 7 packet) socket requires root permission or cap_net_raw capability

Testing

Module contains unit test, which can be invoked by command

npm test

This however requires build suite ready, with CppUTest libraries installed.