IPv6 network packet: JavaScript parsing library

KS implementation details

License: CC0-1.0
Minimal Kaitai Struct required: 0.8

This page hosts a formal specification of IPv6 network packet using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

See the usage examples in the JavaScript notes.

Parse structure from an ArrayBuffer:

var arrayBuffer = ...;
var data = new Ipv6Packet(new KaitaiStream(arrayBuffer));

After that, one can get various attributes from the structure by accessing fields or properties like:

data.version // => get version

JavaScript source code to parse IPv6 network packet

Ipv6Packet.js

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['kaitai-struct/KaitaiStream', './ProtocolBody'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'), require('./ProtocolBody'));
  } else {
    root.Ipv6Packet = factory(root.KaitaiStream, root.ProtocolBody);
  }
}(this, function (KaitaiStream, ProtocolBody) {
var Ipv6Packet = (function() {
  function Ipv6Packet(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  Ipv6Packet.prototype._read = function() {
    this.version = this._io.readBitsInt(4);
    this.trafficClass = this._io.readBitsInt(8);
    this.flowLabel = this._io.readBitsInt(20);
    this._io.alignToByte();
    this.payloadLength = this._io.readU2be();
    this.nextHeaderType = this._io.readU1();
    this.hopLimit = this._io.readU1();
    this.srcIpv6Addr = this._io.readBytes(16);
    this.dstIpv6Addr = this._io.readBytes(16);
    this.nextHeader = new ProtocolBody(this._io, this, null, this.nextHeaderType);
    this.rest = this._io.readBytesFull();
  }

  return Ipv6Packet;
})();
return Ipv6Packet;
}));