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

netbios-name

v0.2.0

Published

Utility code for working with NetBIOS names.

Downloads

17

Readme

node-netbios-name

A utility module for working with NetBIOS names as defined in RFC1001, RFC1002, and RFC883.

Example

var nbname = require('netbios-name');

var fqdn = 'foobar.example.com';
var suffix = 0x20;

nbname.decompose(fqdn, function(error, netbiosName, scopeId) {
  netbiosName === 'foobar         ';  // true
  scopeId === 'example.com';          // true
};

var buf = new Buffer(128);
nbname.pack(buf, 0, {}, fqdn, suffix, function(error, pLen) {
  pLen === (1 + 32 + 1 + 7 + 1 + 3 + 1);   // true

  nbname.unpack(buf, offset, function(error, uLen, uName, uSuffix) {
    uLen === pLen;        // true
    uName === fqdn;       // true
    uSuffix === suffix;   // true
  });
});

decompose(name, callback)

Decompose a given fully qualified domain name (FQDN) into a NetBIOS name and its accompanying scope ID. All NetBIOS names are a fixed width of 16-bytes consisting of 15 name bytes and a single trailing suffix byte. This routine will pad the first element of the FQDN out to 15-bytes using space characters. An FQDN whose first part is greater than 15-bytes produces an error. The scope ID does not include the initial dot.

  • name {String} Fully qualified domain name. The first label must be 15-bytes or less in length.
  • callback {Function} Callback function
    • error {Error object} Set if the FQDN is not a legal NetBIOS name.
    • netbiosName {String} First label from the FQDN padded out to 15-bytes with spaces.
    • scopeId {String} The remaining domain name from the FQDN without the leading dot.

Example:

decompose('foobar.example.com', function(error, nbname, scope) {
  nbname; // 'foobar         '
  scope;  // 'example.com'
});

pack(buf, offset, nameMap, name, suffix, callback)

Serialize a fully qualified domain name (FQDN) and its accompanying NetBIOS suffix byte into the given buffer. The serialization is implemented using NetBIOS encoding from RFC1001 and domain name compression from RFC883.

Name compression supports the ability to use offset pointers for duplicated labels within a buffer. In order to use this feature the same nameMap hash must be passed into all pack() calls operating on the same buffer. If you do not want to use label pointers, pass null for the nameMap.

  • buf {Buffer} The buffer to write the name to.
  • offset {Number} An index into the buffer indicating where to begin writing the name.
  • nameMap {Object | null} An optional map that will be used to record where each name element is stored in the offset. Subsequent calls to pack() with the same map will result in a pointer to the previously stored offset. If null is passed for the name map, then pointers will not be used.
  • name {String} The fully qualified domain name to serialize. The first'' label in the name must be 15 characters or less in length.
  • suffix {Number} The NetBIOS name suffix byte indicating the node type.
  • callback {Function}
    • error {Error object} Set if the name is illegal or the buffer is too small.
    • len {Number} The number of bytes parsed from the buffer.

Example:

var buf = new Buffer(512);
var nameMap = {};
var offset = 0;
pack(buf, offset, nameMap, 'foobar.hmm.com', 0x20, function(error, nLen) {
  if (error) { // handle error... }

  offset += nLen;

  pack(buf, offset, nameMap, 'snafu.hmm.com', 0x20, function(error, nLen) {
    if (error) { // handle error... }

    offset += nLen;

    // the 'hmm.com' portion of the name will be packed using pointers
    // using only 2 bytes instead of the normal 9 bytes.
  });
});

unpack(buf, offset, callback)

Deserialize the given buffer storing an encoded and compressed NetBIOS name. The name serialization format is defined by the NetBIOS encoding in RFC1001 and the domain name compression in RFC883:

  • buf {Buffer} The buffer to read the name from.
  • offset {Number} The index into the buffer at which to start reading.
  • callback {Function}
    • error {Error object} Set if the name cannot be read from the given buffer location.
    • len {Number} The number of bytes read from the buffer.
    • name {String} The fully qualified domain name read from the buffer.
    • suffix {Number} The NetBIOS name suffix byte indicating the node type.

Example:

var offset = 0;
unpack(buf, offset, function(error, nLen, name, suffix) {
  if (error) { // handle error... }

  offset += nLen;             // number of bytes parsed from the buffer
  name === 'foobar.hmm.com';  // FQDN parsed from the buffer
  suffix === 0x20;            // Suffix byte from name defining node type
});