ip-header
IP header parsing.
Example
var IpHeader = ; // parse an IP header from buffervar iph = buf;iphsrc === '1.1.1.1'; // source IP addressiphdst === '2.2.2.2'; // destination IP addressiphflagsdf === true; // don't fragment flagiphflagsmf === false; // more fragments flagiphid === 12345; // IP identifier for frag reassemblyiphoffset === 0; // fragment offsetiphttl === 64; // time-to-liveiphprotocol === 'tcp'; // payload protocoliphprotocolCode === 6; // code for the payload protocoliphlength === 20; // length of IP header in bytesiphtotalLength === 520; // total length of IP packet in bytesiphdataLength === 500; // size of data payload (total - header)var data = buf; // create a new IP header from scratchvar iph2 = src: '1.1.1.1' dst: '3.3.3.3' protocol: 'udp' flags: df: true dataLength: 58;var out = iph2; // write header out to new buffer // operate on buffers in placevar iph3 = buf offset;var iph4 = IpHeader;iph3;
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.