ip-packet
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/ip-packet package

1.1.0 • Public • Published

ip-packet

Encode/decode raw ip packets

npm install ip-packet

build status

Usage

var ip = require('ip-packet')
 
var buf = ip.encode({
  version: 4,
  protocol: 0,
  sourceIp: '127.0.0.1',
  destinationIp: '127.0.0.1',
  data: new Buffer('some data')
})
 
console.log(ip.decode(buf)) // prints out the decoded packet

API

buffer = ip.encode(packet, [buffer], [offset])

Encode a packet. A packet should look like this

{
  version: 4,
  dscp: 0,
  ecn: 0,
  identification: 0,
  flags: 0,
  fragmentOffset: 0,
  ttl: 0,
  protocol: 0,
  sourceIp: '127.0.0.1',
  destinationIp: '127.0.0.1',
  data: <Buffer>
}

`packet = ip.decode(buffer, [offset])

Decode a packet. Throws an exception if the packet contains a bad checksum.

length = ip.encodingLength(packet)

Returns the byte length of the packet encoded

configure = ip.configure(options)

Returns ip-packet configured with options.

Options:

  • allowNullChecksum. When decoding, ignore checksums set to 0x0000

License

MIT

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i ip-packet

    Weekly Downloads

    72

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    6.7 kB

    Total Files

    6

    Last publish

    Collaborators

    • freeall
    • mafintosh