Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

udp-packet

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

udp-packet

encode/decode raw udp packets

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31
increased by72.22%
Maintainers
1
Weekly downloads
 
Created
Source

udp-packet

encode example

var udp = require('udp-packet')

console.log(udp.encode({
  sourceIp: '10.0.0.1',
  sourcePort: 58936,
  destinationIp: '10.0.0.2',
  destinationPort: 80,
  data: Buffer('whatever')
}))

output:

<Buffer e6 38 00 50 00 10 61 7d 77 68 61 74 65 76 65 72>

decode example

var udp = require('udp-packet')
var buf = Buffer([
  0xea, 0x61, 0xe2, 0xde, 0x00, 0x50, 0xd5, 0x20, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x04, 0x41, 0x81, 0xc6, 0xe0, 0x46, 0xba, 0xfd, 0xc6, 0x87, 0x22, 0x10, 0xd7,
  0xeb, 0xda, 0xd7, 0x4f, 0x62, 0x45, 0xac, 0x6b, 0xce, 0x7e, 0x6a, 0x8d, 0x4d,
  0xbc, 0xd2, 0x57, 0x32, 0x76, 0xcf, 0xa0, 0xde, 0x22, 0x38, 0xf7, 0xe0, 0xd8,
  0xee, 0x6e, 0xe0, 0xa1, 0xe8, 0xb3, 0x3e, 0x29, 0x6e, 0x08, 0x9a, 0x4a, 0xad,
  0x6e, 0x51, 0xed, 0x0b, 0xf6, 0x13, 0xff, 0xd8, 0x24, 0xbf, 0xba, 0xa4, 0x0b,
  0x05, 0xad
])
console.log(udp.decode(buf))

output:

{ sourcePort: 60001,
  destinationPort: 58078,
  length: 80,
  checksum: 54560,
  data: <Buffer 80 00 00 00 00 04 41 81 c6 e0 46 ba fd c6 87 22 10 d7 eb da d7 4f 62 45 ac 6b ce 7e 6a 8d 4d bc d2 57 32 76 cf a0 de 22 38 f7 e0 d8 ee 6e e0 a1 e8 b3 ... > }

api

var udp = require('udp-packet')

var buf = udp.encode(packet)

Encode a packet:

  • packet.sourcePort
  • packet.destinationPort
  • packet.data - buffer payload

Optionally, for checksums:

  • packet.sourceIp - ipv4 address string or 4-byte buffer
  • packet.destinationIp - ipv4 address string or 4-byte buffer
  • packet.protocol - protocol number (default: 0x11 for UDP)

var packet = udp.decode(buf)

Decode a given a UDP data packet buf:

  • packet.sourcePort
  • packet.destinationPort
  • packet.length - length of total udp packet, including 8 byte header
  • packet.checksum
  • packet.data

var sum = udp.checksum(packet, buffer)

Return the checksum for a decoded packet.

install

npm install udp-packet

license

MIT

Keywords

FAQs

Package last updated on 16 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc