netkitty 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/inspectionProfiles/Project_Default.xml +1 -1
- package/dist/NetKitty.d.ts +12 -0
- package/dist/NetKitty.d.ts.map +1 -1
- package/dist/NetKitty.js +74 -1
- package/dist/lib/codec/Codec.d.ts.map +1 -1
- package/dist/lib/codec/Codec.js +8 -0
- package/dist/lib/codec/abstracts/BaseHeader.d.ts +2 -1
- package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +1 -1
- package/dist/lib/codec/abstracts/BaseHeader.js +19 -10
- package/dist/lib/codec/headers/Goose.d.ts.map +1 -1
- package/dist/lib/codec/headers/Goose.js +26 -8
- package/dist/lib/codec/headers/ICMP.d.ts +15 -0
- package/dist/lib/codec/headers/ICMP.d.ts.map +1 -0
- package/dist/lib/codec/headers/ICMP.js +147 -0
- package/dist/lib/codec/headers/ICMPv6.d.ts +15 -0
- package/dist/lib/codec/headers/ICMPv6.d.ts.map +1 -0
- package/dist/lib/codec/headers/ICMPv6.js +128 -0
- package/dist/lib/codec/headers/IPv6.d.ts +10 -0
- package/dist/lib/codec/headers/IPv6.d.ts.map +1 -0
- package/dist/lib/codec/headers/IPv6.js +177 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +71 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +1 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.js +497 -0
- package/dist/lib/codec/headers/TCP.d.ts.map +1 -1
- package/dist/lib/codec/headers/TCP.js +1 -0
- package/dist/tests/units/Codec.spec.js +19 -21
- package/package.json +1 -1
- package/src/NetKitty.ts +61 -0
- package/src/lib/codec/Codec.ts +8 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +17 -9
- package/src/lib/codec/headers/Goose.ts +21 -9
- package/src/lib/codec/headers/ICMP.ts +151 -0
- package/src/lib/codec/headers/ICMPv6.ts +128 -0
- package/src/lib/codec/headers/IPv6.ts +176 -0
- package/src/lib/codec/headers/IPv6HopByHopOptions.ts +532 -0
- package/src/lib/codec/headers/TCP.ts +1 -0
- package/src/tests/units/Codec.spec.ts +21 -21
- package/src/tests/units/ReadPCAP.spec.ts +1 -2
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IPv6HopByHopOptions = void 0;
|
|
7
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
8
|
+
const BufferToNumber_1 = require("../lib/BufferToNumber");
|
|
9
|
+
const NumberToBuffer_1 = require("../lib/NumberToBuffer");
|
|
10
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
11
|
+
const node_tlv_1 = __importDefault(require("node-tlv"));
|
|
12
|
+
const HexToNumber_1 = require("../lib/HexToNumber");
|
|
13
|
+
//Type=1 PadN
|
|
14
|
+
//Type=4 Tunnel Encapsulation Limit
|
|
15
|
+
//Type=5 Router Alert
|
|
16
|
+
//Type=7 CALIPSO
|
|
17
|
+
//Type=8 SMF_DPD
|
|
18
|
+
//Type=11 MPL Option
|
|
19
|
+
//Type=12 ILNP Nonce
|
|
20
|
+
//Type=13 Line-Identification Option
|
|
21
|
+
//Type=30 IPv6 DFF Header
|
|
22
|
+
//Type=138 Endpoint Identification
|
|
23
|
+
var Type;
|
|
24
|
+
(function (Type) {
|
|
25
|
+
Type["PadN"] = "PadN";
|
|
26
|
+
Type["Tunnel_Encapsulation_Limit"] = "Tunnel-Encapsulation-Limit";
|
|
27
|
+
Type["Router_Alert"] = "Router-Alert";
|
|
28
|
+
Type["CALIPSO"] = "CALIPSO";
|
|
29
|
+
Type["SMF_DPD"] = "SMF_DPD";
|
|
30
|
+
Type["MPL_Option"] = "MPL-Option";
|
|
31
|
+
Type["ILNP_Nonce"] = "ILNP-Nonce";
|
|
32
|
+
Type["Line_Identification_Option"] = "Line-Identification-Option";
|
|
33
|
+
Type["IPv6_DFF_Header"] = "IPv6-DFF-Header";
|
|
34
|
+
Type["Endpoint_Identification"] = "Endpoint-Identification";
|
|
35
|
+
})(Type || (Type = {}));
|
|
36
|
+
class IPv6HopByHopOptions extends BaseHeader_1.BaseHeader {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(...arguments);
|
|
39
|
+
this.items = [];
|
|
40
|
+
this.SCHEMA = {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
nxt: {
|
|
44
|
+
type: 'integer',
|
|
45
|
+
label: 'Next Header',
|
|
46
|
+
minimum: 0,
|
|
47
|
+
maximum: 255,
|
|
48
|
+
decode: () => {
|
|
49
|
+
this.instance.nxt.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
|
|
50
|
+
},
|
|
51
|
+
encode: () => {
|
|
52
|
+
const nxt = this.instance.nxt.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
53
|
+
this.instance.nxt.setValue(nxt);
|
|
54
|
+
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(nxt));
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
len: {
|
|
58
|
+
type: 'integer',
|
|
59
|
+
label: 'Length',
|
|
60
|
+
minimum: 0,
|
|
61
|
+
maximum: 255,
|
|
62
|
+
decode: () => {
|
|
63
|
+
this.instance.len.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(1, 1)));
|
|
64
|
+
},
|
|
65
|
+
encode: () => {
|
|
66
|
+
const len = this.instance.len.getValue(0);
|
|
67
|
+
this.instance.len.setValue(len);
|
|
68
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(len));
|
|
69
|
+
if (!len) {
|
|
70
|
+
this.addPostSelfEncodeHandler(() => {
|
|
71
|
+
let rawLength = 0;
|
|
72
|
+
this.itemTLVs
|
|
73
|
+
.map(tlv => Buffer.from(tlv.getTLV(), 'hex').length)
|
|
74
|
+
.forEach(itemLength => rawLength += itemLength);
|
|
75
|
+
const calcLength = Math.floor(rawLength / 8);
|
|
76
|
+
this.instance.len.setValue(calcLength);
|
|
77
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(calcLength));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
items: {
|
|
83
|
+
type: 'array',
|
|
84
|
+
label: 'Option Items',
|
|
85
|
+
items: {
|
|
86
|
+
anyOf: [
|
|
87
|
+
//Type=1 PadN
|
|
88
|
+
{
|
|
89
|
+
type: 'object',
|
|
90
|
+
label: 'PadN',
|
|
91
|
+
properties: {
|
|
92
|
+
type: {
|
|
93
|
+
type: 'string',
|
|
94
|
+
label: 'Type',
|
|
95
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
96
|
+
enum: [Type.PadN]
|
|
97
|
+
},
|
|
98
|
+
n: {
|
|
99
|
+
type: 'integer',
|
|
100
|
+
label: 'N'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
//Type=4 Tunnel Encapsulation Limit
|
|
105
|
+
{
|
|
106
|
+
type: 'object',
|
|
107
|
+
label: 'Tunnel Encapsulation Limit',
|
|
108
|
+
properties: {
|
|
109
|
+
type: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
label: 'Type',
|
|
112
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
113
|
+
enum: [Type.Tunnel_Encapsulation_Limit]
|
|
114
|
+
},
|
|
115
|
+
limit: {
|
|
116
|
+
type: 'integer',
|
|
117
|
+
label: 'Limit',
|
|
118
|
+
minimum: 1,
|
|
119
|
+
maximum: 255
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
//Type=5 Router Alert
|
|
124
|
+
{
|
|
125
|
+
type: 'object',
|
|
126
|
+
label: 'Router Alert',
|
|
127
|
+
properties: {
|
|
128
|
+
type: {
|
|
129
|
+
type: 'string',
|
|
130
|
+
label: 'Type',
|
|
131
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
132
|
+
enum: [Type.Router_Alert]
|
|
133
|
+
},
|
|
134
|
+
alert: {
|
|
135
|
+
type: 'string',
|
|
136
|
+
label: 'Router Alert',
|
|
137
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
138
|
+
minLength: 4,
|
|
139
|
+
maxLength: 4
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
//Type=7 CALIPSO
|
|
144
|
+
{
|
|
145
|
+
type: 'object',
|
|
146
|
+
label: 'CALIPSO',
|
|
147
|
+
properties: {
|
|
148
|
+
type: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
label: 'Type',
|
|
151
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
152
|
+
enum: [Type.CALIPSO]
|
|
153
|
+
},
|
|
154
|
+
tag: {
|
|
155
|
+
type: 'string',
|
|
156
|
+
label: 'Tag',
|
|
157
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
158
|
+
minLength: 16,
|
|
159
|
+
maxLength: 16
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
//Type=8 SMF_DPD
|
|
164
|
+
{
|
|
165
|
+
type: 'object',
|
|
166
|
+
label: 'SMF_DPD',
|
|
167
|
+
properties: {
|
|
168
|
+
type: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
label: 'Type',
|
|
171
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
172
|
+
enum: [Type.SMF_DPD]
|
|
173
|
+
},
|
|
174
|
+
hash: {
|
|
175
|
+
type: 'string',
|
|
176
|
+
label: 'Hash',
|
|
177
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
//Type=11 MPL Option
|
|
182
|
+
{
|
|
183
|
+
type: 'object',
|
|
184
|
+
label: 'MPL Option',
|
|
185
|
+
properties: {
|
|
186
|
+
type: {
|
|
187
|
+
type: 'string',
|
|
188
|
+
label: 'Type',
|
|
189
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
190
|
+
enum: [Type.MPL_Option]
|
|
191
|
+
},
|
|
192
|
+
value: {
|
|
193
|
+
type: 'string',
|
|
194
|
+
label: 'Value',
|
|
195
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
//Type=12 ILNP Nonce
|
|
200
|
+
{
|
|
201
|
+
type: 'object',
|
|
202
|
+
label: 'ILNP Nonce',
|
|
203
|
+
properties: {
|
|
204
|
+
type: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
label: 'Type',
|
|
207
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
208
|
+
enum: [Type.ILNP_Nonce]
|
|
209
|
+
},
|
|
210
|
+
nonce: {
|
|
211
|
+
type: 'string',
|
|
212
|
+
label: 'Nonce',
|
|
213
|
+
minLength: 12,
|
|
214
|
+
maxLength: 12,
|
|
215
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
//Type=13 Line-Identification Option
|
|
220
|
+
{
|
|
221
|
+
type: 'object',
|
|
222
|
+
label: 'Line-Identification Option',
|
|
223
|
+
properties: {
|
|
224
|
+
type: {
|
|
225
|
+
type: 'string',
|
|
226
|
+
label: 'Type',
|
|
227
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
228
|
+
enum: [Type.Line_Identification_Option]
|
|
229
|
+
},
|
|
230
|
+
id: {
|
|
231
|
+
type: 'string',
|
|
232
|
+
label: 'Identity',
|
|
233
|
+
minLength: 8,
|
|
234
|
+
maxLength: 8,
|
|
235
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
//Type=30 IPv6 DFF Header
|
|
240
|
+
{
|
|
241
|
+
type: 'object',
|
|
242
|
+
label: 'IPv6 DFF Header',
|
|
243
|
+
properties: {
|
|
244
|
+
type: {
|
|
245
|
+
type: 'string',
|
|
246
|
+
label: 'Type',
|
|
247
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
248
|
+
enum: [Type.IPv6_DFF_Header]
|
|
249
|
+
},
|
|
250
|
+
message: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
label: 'Message',
|
|
253
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
//Type=138 Endpoint Identification
|
|
258
|
+
{
|
|
259
|
+
type: 'object',
|
|
260
|
+
label: 'Endpoint Identification',
|
|
261
|
+
properties: {
|
|
262
|
+
type: {
|
|
263
|
+
type: 'string',
|
|
264
|
+
label: 'Type',
|
|
265
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
266
|
+
enum: [Type.Endpoint_Identification]
|
|
267
|
+
},
|
|
268
|
+
id: {
|
|
269
|
+
type: 'string',
|
|
270
|
+
label: 'Identity',
|
|
271
|
+
minLength: 32,
|
|
272
|
+
maxLength: 32,
|
|
273
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
//Custom
|
|
278
|
+
{
|
|
279
|
+
type: 'object',
|
|
280
|
+
label: 'Custom',
|
|
281
|
+
properties: {
|
|
282
|
+
type: {
|
|
283
|
+
type: 'integer',
|
|
284
|
+
label: 'Type'
|
|
285
|
+
},
|
|
286
|
+
data: {
|
|
287
|
+
type: 'string',
|
|
288
|
+
label: 'Data',
|
|
289
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
},
|
|
295
|
+
decode: () => {
|
|
296
|
+
let length = this.instance.len.getValue(0) * 8 + 7;
|
|
297
|
+
while (!this.itemTLVs) {
|
|
298
|
+
try {
|
|
299
|
+
const itemTLVs = node_tlv_1.default.parseList(this.readBytes(2, length, true));
|
|
300
|
+
const joinedHex = itemTLVs.map(value => value.getTLV()).join('');
|
|
301
|
+
if (this.readBytes(2, length, true).toString('hex').padStart(length * 2, '0').toUpperCase() !== joinedHex.toUpperCase()) {
|
|
302
|
+
length -= 1;
|
|
303
|
+
if (!length)
|
|
304
|
+
break;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
this.itemTLVs = node_tlv_1.default.parseList(this.readBytes(2, length));
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
length -= 1;
|
|
311
|
+
if (!length)
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
this.itemTLVs.forEach((itemTLV) => {
|
|
316
|
+
switch (itemTLV.getTag('number')) {
|
|
317
|
+
case 0x01:
|
|
318
|
+
{
|
|
319
|
+
this.items.push({
|
|
320
|
+
type: Type.PadN,
|
|
321
|
+
n: itemTLV.getLength('number')
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
break;
|
|
325
|
+
case 0x04:
|
|
326
|
+
{
|
|
327
|
+
this.items.push({
|
|
328
|
+
type: Type.Tunnel_Encapsulation_Limit,
|
|
329
|
+
limit: (0, HexToNumber_1.HexToUInt8)(itemTLV.getValue('hex'))
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
case 0x05:
|
|
334
|
+
{
|
|
335
|
+
this.items.push({
|
|
336
|
+
type: Type.Router_Alert,
|
|
337
|
+
alert: itemTLV.getValue('hex')
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
case 0x07:
|
|
342
|
+
{
|
|
343
|
+
this.items.push({
|
|
344
|
+
type: Type.CALIPSO,
|
|
345
|
+
tag: itemTLV.getValue('hex')
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
case 0x08:
|
|
350
|
+
{
|
|
351
|
+
this.items.push({
|
|
352
|
+
type: Type.SMF_DPD,
|
|
353
|
+
hash: itemTLV.getValue('hex')
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
break;
|
|
357
|
+
case 0x0B:
|
|
358
|
+
{
|
|
359
|
+
this.items.push({
|
|
360
|
+
type: Type.MPL_Option,
|
|
361
|
+
value: itemTLV.getValue('hex')
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
break;
|
|
365
|
+
case 0x0C:
|
|
366
|
+
{
|
|
367
|
+
this.items.push({
|
|
368
|
+
type: Type.ILNP_Nonce,
|
|
369
|
+
nonce: itemTLV.getValue('hex')
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
case 0x0D:
|
|
374
|
+
{
|
|
375
|
+
this.items.push({
|
|
376
|
+
type: Type.Line_Identification_Option,
|
|
377
|
+
id: itemTLV.getValue('hex')
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
break;
|
|
381
|
+
case 0x1E:
|
|
382
|
+
{
|
|
383
|
+
this.items.push({
|
|
384
|
+
type: Type.IPv6_DFF_Header,
|
|
385
|
+
message: itemTLV.getValue('hex')
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
case 0x8A:
|
|
390
|
+
{
|
|
391
|
+
this.items.push({
|
|
392
|
+
type: Type.Endpoint_Identification,
|
|
393
|
+
id: itemTLV.getValue('hex')
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
default: {
|
|
398
|
+
this.items.push({
|
|
399
|
+
type: itemTLV.getTag('number'),
|
|
400
|
+
data: itemTLV.getValue('hex')
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
this.instance.items.setValue(this.items.length ? this.items : []);
|
|
406
|
+
},
|
|
407
|
+
encode: () => {
|
|
408
|
+
this.items = this.instance.items.getValue([]);
|
|
409
|
+
this.itemTLVs = [];
|
|
410
|
+
this.items.forEach(item => {
|
|
411
|
+
switch (item.type) {
|
|
412
|
+
case Type.PadN:
|
|
413
|
+
{
|
|
414
|
+
const typedItem = { ...item };
|
|
415
|
+
this.itemTLVs.push(new node_tlv_1.default(0x01, Buffer.alloc(typedItem.n, 0)));
|
|
416
|
+
}
|
|
417
|
+
break;
|
|
418
|
+
case Type.Tunnel_Encapsulation_Limit:
|
|
419
|
+
{
|
|
420
|
+
const typedItem = { ...item };
|
|
421
|
+
this.itemTLVs.push(new node_tlv_1.default(0x04, (0, NumberToBuffer_1.UInt8ToBuffer)(typedItem.limit)));
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
case Type.Router_Alert:
|
|
425
|
+
{
|
|
426
|
+
const typedItem = { ...item };
|
|
427
|
+
this.itemTLVs.push(new node_tlv_1.default(0x05, (0, NumberToBuffer_1.UInt16ToBuffer)((0, HexToNumber_1.HexToUInt16)(typedItem.alert))));
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
case Type.CALIPSO:
|
|
431
|
+
{
|
|
432
|
+
const typedItem = { ...item };
|
|
433
|
+
this.itemTLVs.push(new node_tlv_1.default(0x07, (0, NumberToBuffer_1.UInt64ToBuffer)((0, HexToNumber_1.HexToUInt64)(typedItem.tag))));
|
|
434
|
+
}
|
|
435
|
+
break;
|
|
436
|
+
case Type.SMF_DPD:
|
|
437
|
+
{
|
|
438
|
+
const typedItem = { ...item };
|
|
439
|
+
this.itemTLVs.push(new node_tlv_1.default(0x08, Buffer.from(typedItem.hash, 'hex')));
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
case Type.MPL_Option:
|
|
443
|
+
{
|
|
444
|
+
const typedItem = { ...item };
|
|
445
|
+
this.itemTLVs.push(new node_tlv_1.default(0x0B, Buffer.from(typedItem.value, 'hex')));
|
|
446
|
+
}
|
|
447
|
+
break;
|
|
448
|
+
case Type.ILNP_Nonce:
|
|
449
|
+
{
|
|
450
|
+
const typedItem = { ...item };
|
|
451
|
+
this.itemTLVs.push(new node_tlv_1.default(0x0C, Buffer.from(typedItem.nonce.padStart(12, '0'), 'hex')));
|
|
452
|
+
}
|
|
453
|
+
break;
|
|
454
|
+
case Type.Line_Identification_Option:
|
|
455
|
+
{
|
|
456
|
+
const typedItem = { ...item };
|
|
457
|
+
this.itemTLVs.push(new node_tlv_1.default(0x0D, (0, NumberToBuffer_1.UInt32ToBuffer)((0, HexToNumber_1.HexToUInt32)(typedItem.id))));
|
|
458
|
+
}
|
|
459
|
+
break;
|
|
460
|
+
case Type.IPv6_DFF_Header:
|
|
461
|
+
{
|
|
462
|
+
const typedItem = { ...item };
|
|
463
|
+
this.itemTLVs.push(new node_tlv_1.default(0x1E, Buffer.from(typedItem.message, 'hex')));
|
|
464
|
+
}
|
|
465
|
+
break;
|
|
466
|
+
case Type.Endpoint_Identification:
|
|
467
|
+
{
|
|
468
|
+
const typedItem = { ...item };
|
|
469
|
+
this.itemTLVs.push(new node_tlv_1.default(0x0C, Buffer.from(typedItem.id.padStart(32, '0'), 'hex')));
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
default: {
|
|
473
|
+
if (typeof item.type !== 'number')
|
|
474
|
+
return;
|
|
475
|
+
const customItem = { ...item };
|
|
476
|
+
this.itemTLVs.push(new node_tlv_1.default(customItem.type, Buffer.from(customItem.data, 'hex')));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
const itemsBuffer = Buffer.from(this.itemTLVs.map(value => value.getTLV()).join(''), 'hex');
|
|
481
|
+
this.writeBytes(2, itemsBuffer);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
this.id = 'ipv6-hopopt';
|
|
487
|
+
this.name = 'IPv6 Hop-by-Hop Option';
|
|
488
|
+
this.nickname = 'HopOpt';
|
|
489
|
+
this.isProtocol = false;
|
|
490
|
+
}
|
|
491
|
+
match() {
|
|
492
|
+
if (!this.prevCodecModule || this.prevCodecModule.id !== 'ipv6')
|
|
493
|
+
return false;
|
|
494
|
+
return this.prevCodecModule.instance.nxt.getValue() === 0x00;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
exports.IPv6HopByHopOptions = IPv6HopByHopOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TCP.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TCP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAkFlD,qBAAa,GAAI,SAAQ,UAAU;IAE/B;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;IA6CxD,MAAM,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"TCP.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TCP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAkFlD,qBAAa,GAAI,SAAQ,UAAU;IAE/B;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;IA6CxD,MAAM,EAAE,kBAAkB,CAgxBhC;IAED,SAAgB,EAAE,EAAE,MAAM,CAAQ;IAElC,SAAgB,IAAI,EAAE,MAAM,CAAkC;IAE9D,SAAgB,QAAQ,EAAE,MAAM,CAAQ;IAEjC,KAAK,IAAI,OAAO;CAM1B"}
|
|
@@ -6,15 +6,15 @@ async function DecodeAndEncode(packet) {
|
|
|
6
6
|
console.log('packetBuffer:', packetBuffer.toString('hex'));
|
|
7
7
|
const codec = new Codec_1.Codec();
|
|
8
8
|
const decodeResult = await codec.decode(packetBuffer);
|
|
9
|
-
console.log(JSON.stringify(decodeResult, null, 2))
|
|
10
|
-
for (let i = 0; i <
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
// console.log(JSON.stringify(decodeResult, null, 2))
|
|
10
|
+
// for (let i = 0; i < 100000; i++) {
|
|
11
|
+
// const encodeResult = await codec.encode(decodeResult)
|
|
12
|
+
// }
|
|
13
|
+
const encodeResult = await codec.encode(decodeResult);
|
|
14
|
+
console.log('encodeResult:', encodeResult.packet.toString('hex'));
|
|
15
|
+
console.log('packetBuffer===encodeResult', packetBuffer.toString('hex') === encodeResult.packet.toString('hex'));
|
|
16
|
+
const decodeResult1 = await codec.decode(encodeResult.packet);
|
|
17
|
+
console.log(JSON.stringify(decodeResult1, null, 2));
|
|
18
18
|
}
|
|
19
19
|
async function GOOSE_Codec(packet) {
|
|
20
20
|
await DecodeAndEncode(packet);
|
|
@@ -25,6 +25,9 @@ async function IEC61850SampleValues_Codec(packet) {
|
|
|
25
25
|
async function IPv4_Codec(packet) {
|
|
26
26
|
await DecodeAndEncode(packet);
|
|
27
27
|
}
|
|
28
|
+
async function IPv6_Codec(packet) {
|
|
29
|
+
await DecodeAndEncode(packet);
|
|
30
|
+
}
|
|
28
31
|
async function ARP_Codec(packet) {
|
|
29
32
|
await DecodeAndEncode(packet);
|
|
30
33
|
}
|
|
@@ -37,6 +40,7 @@ async function UDP_Codec(packet) {
|
|
|
37
40
|
(async () => {
|
|
38
41
|
// console.time('GOOSE')
|
|
39
42
|
// await GOOSE_Codec('AaD0CC93AKD0CC93iLgAAQCRAAAAAGGBhoAaR0VEZXZpY2VGNjUwL0xMTjAkR08kZ2NiMDGBAwCcQIIYR0VEZXZpY2VGNjUwL0xMTjAkR09PU0UxgwtGNjUwX0dPT1NFMYQIOG6780IXKAqFAQGGAQuHAQCIAQGJAQCKAQirIIMBAIQDAwAAgwEAhAMDAACDAQCEAwMAAIMBAIQDAwAA')
|
|
43
|
+
// await GOOSE_Codec('AQzNAQNVABAAAANVgQAABoi4A1UAlgAAAABhgYuAGlBMMTEwMVBJR08wMS9MTE4wJEdPJGdvY2IwgQInEIIZUEwxMTAxUElHTzAxL0xMTjAkZHNHT09TRYMXUEwxMTAxUElHTzAxL0xMTjAuZ28AA1AAAA///wAApdAQcA==')
|
|
40
44
|
// console.timeEnd('GOOSE')
|
|
41
45
|
//
|
|
42
46
|
// console.time('IEC61850SampleValues')
|
|
@@ -45,7 +49,8 @@ async function UDP_Codec(packet) {
|
|
|
45
49
|
// await IPv4_Codec('AQBeAAD7RvyxjrRvCABFAABDFi9AAP8Rwg7AqAHI4AAA+61EFOkALwQ6AAAAAAABAAAAAAAACl9seXJhLW1kbnMEX3VkcAVsb2NhbAAADIAB')
|
|
46
50
|
console.time('IPv4');
|
|
47
51
|
// await IPv4_Codec('AAAAAAAAAAAAAAAACABLAABseDcAAEABdS1/AAABfwAAAYYWAAAAAgIQAAIAAAACAAQABQAGAO8AAAAAKVCMCgABkk2uRRMODAAICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=')
|
|
48
|
-
await IPv4_Codec('AAABAAABAAECAwQFgQAHAQgARQAD73UOAAD//cCqwFU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dQ8AAP/9wqnAVQECwAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoikeAWYiHtu0w+Ilen5pPcowdgE=')
|
|
53
|
+
await IPv4_Codec('jrqXwYfpMsUZ/NE3CABFAABU9jEAAEABAIjAqAGewKgBAQgAVeFhQwAAZ+gRVAAC3JkICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=');
|
|
49
54
|
console.timeEnd('IPv4');
|
|
50
55
|
//
|
|
51
56
|
// console.time('ARP')
|
|
@@ -61,15 +66,8 @@ async function UDP_Codec(packet) {
|
|
|
61
66
|
// console.time('UDP')
|
|
62
67
|
// await UDP_Codec('////////CAAnzP1BCABFAAD/uTJAAEAR+6XAqAHGwKgB/wCKAIoA62oQEQp9csCoAcYAigDVAAAgRkFGRUZEQ0FDQUNBQ0FDQUNBQ0FDQUNBQ0FDQUNBQUEAIEZIRVBGQ0VMRUhGQ0VQRkZGQUNBQ0FDQUNBQ0FDQUJOAP9TTUIlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAOwAAAAAAAAAAAAAAAAAAAAAAAAA7AFYAAwABAAEAAgBMAFxNQUlMU0xPVFxCUk9XU0UAAe2A/AoAUFRTAAAAAAAAAAAAAAAAAAYBA5qBAA8BVapwdHMgc2VydmVyIChTYW1iYSwgVWJ1bnR1KQA=')
|
|
63
68
|
// console.timeEnd('UDP')
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// fobj.c1.b1.ccc1.setValue('1')
|
|
70
|
-
// fobj.c1.b1.ccc2.setValue(2)
|
|
71
|
-
// fobj.c1.b1.ccc3.setValue(true)
|
|
72
|
-
// // console.log(fobj.cc2.bb4.getValue(), fobj.cc2.bb4.isUndefined())
|
|
73
|
-
// console.log(JSON.stringify(fobj.getValue(), null, 2))
|
|
74
|
-
// console.log(fobj.c1.b1.ccc4.hhh6.getPath())
|
|
69
|
+
// console.time('IPv6')
|
|
70
|
+
// await IPv6_Codec('xAI6RAAAxAA6RAAAht1gAAAAADw6QP6AAAAAAAAAxgA6//5EAAD+gAAAAAAAAMYCOv/+RAAAgQDIrxOKAAEBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0')
|
|
71
|
+
// await IPv6_Codec('MzMAAAAWxAI6RAAAht1uAAAAACQAAf6AAAAAAAAAxgI6//5EAAD/AgAAAAAAAAAAAAAAAAAWOgAFAgAAAQCPAHDCAAAAAQQAAAD/AgAAAAAAAAAAAAAAAAAC')
|
|
72
|
+
// console.timeEnd('IPv6')
|
|
75
73
|
})();
|
package/package.json
CHANGED
package/src/NetKitty.ts
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
export {BufferToHex} from './lib/codec/lib/BufferToHex'
|
|
2
|
+
export {BufferToIPv4, BufferToIPv6} from './lib/codec/lib/BufferToIP'
|
|
3
|
+
export {
|
|
4
|
+
BufferToFloat32,
|
|
5
|
+
BufferToInt16,
|
|
6
|
+
BufferToInt32,
|
|
7
|
+
BufferToInt64,
|
|
8
|
+
BufferToInt8,
|
|
9
|
+
BufferToUInt16, BufferToUInt32, BufferToUInt64,
|
|
10
|
+
BufferToUInt8
|
|
11
|
+
} from './lib/codec/lib/BufferToNumber'
|
|
12
|
+
export {FixHexString} from './lib/codec/lib/FixHexString'
|
|
13
|
+
export {FlexibleObject} from './lib/codec/lib/FlexibleObject'
|
|
14
|
+
export {
|
|
15
|
+
HexToFloat32,
|
|
16
|
+
HexToInt16,
|
|
17
|
+
HexToInt32,
|
|
18
|
+
HexToInt64,
|
|
19
|
+
HexToInt8,
|
|
20
|
+
HexToUInt16,
|
|
21
|
+
HexToUInt32, HexToUInt64,
|
|
22
|
+
HexToUInt8
|
|
23
|
+
} from './lib/codec/lib/HexToNumber'
|
|
24
|
+
export {IPv4ToBuffer, IPv6ToBuffer} from './lib/codec/lib/IPToBuffer'
|
|
25
|
+
export {
|
|
26
|
+
Int16ToBERBuffer,
|
|
27
|
+
Int32ToBERBuffer,
|
|
28
|
+
Int64ToBERBuffer,
|
|
29
|
+
Int8ToBERBuffer, UInt16ToBERBuffer, UInt32ToBERBuffer, UInt64ToBERBuffer,
|
|
30
|
+
UInt8ToBERBuffer
|
|
31
|
+
} from './lib/codec/lib/NumberToBERBuffer'
|
|
32
|
+
export {
|
|
33
|
+
Int16ToBERHex,
|
|
34
|
+
Int32ToBERHex,
|
|
35
|
+
Int64ToBERHex,
|
|
36
|
+
Int8ToBERHex,
|
|
37
|
+
UInt16ToBERHex, UInt32ToBERHex, UInt64ToBERHex,
|
|
38
|
+
UInt8ToBERHex
|
|
39
|
+
} from './lib/codec/lib/NumberToBERHex'
|
|
40
|
+
export {
|
|
41
|
+
Float32ToBuffer,
|
|
42
|
+
Int16ToBuffer,
|
|
43
|
+
Int32ToBuffer,
|
|
44
|
+
Int64ToBuffer,
|
|
45
|
+
Int8ToBuffer,
|
|
46
|
+
UInt16ToBuffer, UInt32ToBuffer, UInt64ToBuffer,
|
|
47
|
+
UInt8ToBuffer
|
|
48
|
+
} from './lib/codec/lib/NumberToBuffer'
|
|
49
|
+
export {
|
|
50
|
+
Float32ToHex,
|
|
51
|
+
Int16ToHex,
|
|
52
|
+
Int32ToHex,
|
|
53
|
+
Int64ToHex,
|
|
54
|
+
Int8ToHex,
|
|
55
|
+
UInt16ToHex,
|
|
56
|
+
UInt32ToHex, UInt64ToHex,
|
|
57
|
+
UInt8ToHex
|
|
58
|
+
} from './lib/codec/lib/NumberToHex'
|
|
59
|
+
export {StringContentEncodingEnum} from './lib/codec/lib/StringContentEncodingEnum'
|
|
60
|
+
|
|
1
61
|
export {type INetworkInterface} from './lib/nodepcap/interfaces/INetworkInterface'
|
|
2
62
|
export {type CodecEncodeResult} from './lib/codec/types/CodecEncodeResult'
|
|
3
63
|
export {type CodecEncodeInput} from './lib/codec/types/CodecEncodeInput'
|
|
@@ -29,3 +89,4 @@ export {Capture} from './lib/nodepcap/Capture'
|
|
|
29
89
|
* Network packet codec
|
|
30
90
|
*/
|
|
31
91
|
export {Codec, Headers} from './lib/codec/Codec'
|
|
92
|
+
|