-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathIPv4Defrag.js
More file actions
42 lines (34 loc) · 1.22 KB
/
IPv4Defrag.js
File metadata and controls
42 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var protocols = require("../../decode/ip_protocols");
var IPv4Reassembler = require("./IPv4Reassembler");
/* Handle with differents fragments of differents original parts to reassembly
* Use this class to reassembly*/
function IPv4Defrag() {
this.fragmentsById = {};
}
function isFragment(iPPacket) {
return (iPPacket.fragmentOffset > 0 || iPPacket.flags.moreFragments);
}
//If complete, returns de reassempled payload!
IPv4Defrag.prototype.receivePart = function(iPPacket) {
if(!isFragment(iPPacket)) {
return null;
}
if(this.fragmentsById[iPPacket.identification] === undefined) {
this.fragmentsById[iPPacket.identification] = new IPv4Reassembler();
}
this.fragmentsById[iPPacket.identification].newPart(iPPacket);
var buffer = this.fragmentsById[iPPacket.identification].buildBuffer();
if(buffer === null) {
return null;
}
var ProtocolDecoder = protocols[iPPacket.protocol];
if(ProtocolDecoder === undefined) {
return null;
} else {
var payload = new ProtocolDecoder(this.emitter).decode(buffer, 0, buffer.length);
return payload;
}
}
module.exports = IPv4Defrag;
module.exports.isFragment = isFragment;