udp-header

UDP header serialization

npm install udp-header
4 downloads in the last week
14 downloads in the last month

udp-header

UDP header serialization.

Build Status

Example

var UdpHeader = require('udp-header');

// parse UDP headers in
var udph = new UdpHeader(inputBuf, inputOffset);
udph.srcPort === 52;
udph.dstPort === 5432;
udph.dataLength === 500;
udph.totalLength === 508;
udph.length === 8;

// write UDP headers out
var out = udph.toBuffer();

// By default, the UDP checksum is not calculated.  It is passed through from
// if you parse an existing buffer or set to the opts.checksum constructor
// option.
//
// To calculate the checksum you must call setChecksum() with the ip header
// object and udp payload buffer.
// the src IP, dst IP, and data buffer.
var iph = new IpHeader({dst:'1.1.1.1', src:'2.2.2.2'});
udph.setChecksum(iph, buf, offset);

// To write a buffer in place, provide the buffer and option offset
// after the packet object.
udph.toBuffer(buf, offset);
npm loves you