-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
40 lines (30 loc) · 740 Bytes
/
test.js
File metadata and controls
40 lines (30 loc) · 740 Bytes
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
const { exit } = require('process');
const Tun = require('./index');
var tun = new Tun('lowpan0', 'cccc::1', 64);
try {
tun.open();
}
catch (err) {
console.log("erro deu ", err);
process.exit(1);
}
tun.on('data', (e) => {
// console.log('rx:', e);
if (e[6] == 0x3a && e[40] == 128 && e[41] == 0) {
// console.log('icmp echo');
// muda para reply
e[40] = 129;
// recalcula checksum
e[42] = e[42] - 1;
if (e[42] == 0xff) {
e[43] = e[43] - 1;
}
// inverte o src com dst
for (var i = 0; i < 16; i++) {
var tmp = e[8+i];
e[8+i] = e[8+i+16];
e[8+i+16] = tmp;
}
tun.send(e);
}
})