IP header parsing.

Example
var IpHeader = require('ip-header');
var iph = new IpHeader(buf);
iph.src === '1.1.1.1';
iph.dst === '2.2.2.2';
iph.flags.df === true;
iph.flags.mf === false;
iph.id === 12345;
iph.offset === 0;
iph.ttl === 64;
iph.protocol === 'tcp';
iph.protocolCode === 6;
iph.length === 20;
iph.totalLength === 520;
iph.dataLength === 500;
var data = buf.slice(iph.length, iph.totalLength);
var iph2 = new IpHeader({
src: '1.1.1.1',
dst: '3.3.3.3',
protocol: 'udp',
flags: { df: true },
dataLength: 58
});
var out = iph2.toBuffer();
var iph3 = new IpHeader(buf, offset);
var iph4 = IpHeader.fromBuffer(buf, offset);
iph3.toBuffer(buf, offset);
Limitations
- Only supports IPv4. Buffer parsing throws if an IPv6 header is seen.
- Only supports common protocols as readable strings. Throws if other
protocols are seen. If you need another protocol, send a pull request
to add it.
'icmp'
- 1'igmp'
- 2'tcp'
- 6'udp'
- 17'encap'
- 41'ospf'
- 89'sctp'
- 132
- Does not support options. Throws if the IP header length is not exactly
20 bytes.