udp-packet
encode example
var udp =console
output:
<Buffer e6 38 00 50 00 10 61 7d 77 68 61 74 65 76 65 72>
decode example
var udp =var buf =console
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 =
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 bufferpacket.destinationIp
- ipv4 address string or 4-byte bufferpacket.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 headerpacket.checksum
packet.data
var sum = udp.checksum(packet, buffer)
Return the checksum for a decoded packet
.
install
npm install udp-packet
license
MIT