-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathipDefrag.js
More file actions
38 lines (31 loc) · 1.07 KB
/
ipDefrag.js
File metadata and controls
38 lines (31 loc) · 1.07 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
'use strict';
var fs = require('fs');
var pcap = require('../pcap');
var IPv4Defrag = require("./ipDefrag/IPv4Defrag");
var filename = process.argv[2];
var pcap_session = pcap.createOfflineSession(filename, '');
function findIPv4Packet(pcapPacket) {
if(pcapPacket.link_type === 'LINKTYPE_RAW') {
return pcapPacket.payload;
}
if(pcapPacket.link_type === 'LINKTYPE_ETHERNET') {
var packetEthernet = pcapPacket.payload;
if(packetEthernet.ethertype === 2048) {
return packetEthernet.payload;
}
}
//TODO LINKTYPE_NULL
return null;
}
var packetCount = 0;
var iPv4Defrag = new IPv4Defrag();
pcap_session.on('packet', function filterDecodePacket(rawPacket) {
var packet = pcap.decode.packet(rawPacket);
var iPPacket = findIPv4Packet(packet);
packetCount++;
var result = iPv4Defrag.receivePart(iPPacket);
if(result !== null) {
console.log("New fragmented IPv4 packet reassembled! Last part is in the packet number", packetCount);
console.log(result.toString(), result);
}
});