@cto.af/pcap-ng-parser 2.0.2 → 2.1.0
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/README.md +16 -2
- package/package.json +6 -6
- package/src/BlockConfig.js +48 -93
- package/src/PCAPNGParser.js +164 -56
- package/src/linkTypes.js +223 -0
- package/types/BlockConfig.d.ts +57 -0
- package/types/PCAPNGParser.d.ts +28 -19
- package/types/linkTypes.d.ts +6 -0
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
# Overview
|
|
3
|
-
@cto.af/pcap-ng-parser is a stream-based module to decode, print and analyze
|
|
3
|
+
@cto.af/pcap-ng-parser is a stream-based module to decode, print and analyze
|
|
4
|
+
network traffic packets. With this module, you can read from an existing
|
|
5
|
+
.pcap or .pcapng file or connect it to an active stream.
|
|
6
|
+
|
|
7
|
+
Implements:
|
|
8
|
+
- [draft-ietf-opsawg-pcap-06](https://www.ietf.org/archive/id/draft-ietf-opsawg-pcap-06.html)
|
|
9
|
+
- [draft-ietf-opsawg-pcapng-04](https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html)
|
|
4
10
|
|
|
5
11
|
# Installation
|
|
6
12
|
|
|
@@ -63,6 +69,10 @@ longer uses the pcapng format.
|
|
|
63
69
|
|
|
64
70
|
Additional examples can be found in the [examples directory](/examples/).
|
|
65
71
|
|
|
72
|
+
It allows you to read from a sample capture file (the default), a file (if you
|
|
73
|
+
specify a file name on the command line), or stdin (if you specify "-" as the
|
|
74
|
+
input file).
|
|
75
|
+
|
|
66
76
|
# Class PCAPNGParser
|
|
67
77
|
|
|
68
78
|
PCAPNGParser is an extension of the [stream.Transform
|
|
@@ -78,7 +88,8 @@ PCAPNGParser class fires the following events:
|
|
|
78
88
|
- `custom`: A Custom block was parsed.
|
|
79
89
|
- `blockType`: An unknown block type has been received.
|
|
80
90
|
|
|
81
|
-
See the full API documentation for
|
|
91
|
+
See the full [API documentation](https://cto-af.github.io/pcap-ng-parser/) for
|
|
92
|
+
the types of the event parameters.
|
|
82
93
|
|
|
83
94
|
# Contribution
|
|
84
95
|
|
|
@@ -122,6 +133,9 @@ The following things have been added:
|
|
|
122
133
|
- Added support for Custom blocks.
|
|
123
134
|
- Added Enhanced Packet flag decoding.
|
|
124
135
|
- Added converting timestamps to JS Dates. Does not handle timezones yet. (BREAKING)
|
|
136
|
+
- Added generate API documentation.
|
|
137
|
+
- Added implementation of old .pcap format, with auto-detection.
|
|
138
|
+
- Added decoding of linkType names.
|
|
125
139
|
|
|
126
140
|
[](https://github.com/cto-af/pcap-ng-parser/actions/workflows/node.js.yml)
|
|
127
141
|
[](https://codecov.io/gh/cto-af/pcap-ng-parser)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/pcap-ng-parser",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Node.js Module for parsing .pcapng files and tcpdump output.",
|
|
5
5
|
"main": "./src/PCAPNGParser.js",
|
|
6
6
|
"types": "./types/PCAPNGParser.d.ts",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
38
|
"license": "BSD-3",
|
|
39
|
-
"packageManager": "pnpm@10.19.0",
|
|
40
|
-
"engines": {
|
|
41
|
-
"node": ">=20"
|
|
42
|
-
},
|
|
43
39
|
"dependencies": {
|
|
44
40
|
"@leichtgewicht/ip-codec": "2.0.5",
|
|
45
|
-
"nofilter": "6.
|
|
41
|
+
"nofilter": "6.4.0"
|
|
42
|
+
},
|
|
43
|
+
"packageManager": "pnpm@10.20.0",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/BlockConfig.js
CHANGED
|
@@ -12,15 +12,9 @@
|
|
|
12
12
|
* @see documentation at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-section-header-block
|
|
13
13
|
*/
|
|
14
14
|
export const sectionHeaderBlock = {
|
|
15
|
-
byteOrderMagic: {
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
majorVersion: {
|
|
19
|
-
size: 2,
|
|
20
|
-
},
|
|
21
|
-
minorVersion: {
|
|
22
|
-
size: 2,
|
|
23
|
-
},
|
|
15
|
+
byteOrderMagic: {size: 4},
|
|
16
|
+
majorVersion: {size: 2},
|
|
17
|
+
minorVersion: {size: 2},
|
|
24
18
|
sectionLength: {
|
|
25
19
|
size: 8,
|
|
26
20
|
signed: true,
|
|
@@ -38,60 +32,36 @@ export const blockType = {
|
|
|
38
32
|
};
|
|
39
33
|
|
|
40
34
|
export const blockTotalLength = {
|
|
41
|
-
blockTotalLength: {
|
|
42
|
-
size: 4,
|
|
43
|
-
},
|
|
35
|
+
blockTotalLength: {size: 4},
|
|
44
36
|
};
|
|
45
37
|
|
|
46
38
|
/**
|
|
47
39
|
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-interface-description-block
|
|
48
40
|
*/
|
|
49
41
|
export const interfaceDescriptionBlockFormat = {
|
|
50
|
-
linkType: {
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
reserved: {
|
|
54
|
-
size: 2,
|
|
55
|
-
},
|
|
56
|
-
snapLen: {
|
|
57
|
-
size: 4,
|
|
58
|
-
},
|
|
42
|
+
linkType: {size: 2},
|
|
43
|
+
reserved: {size: 2},
|
|
44
|
+
snapLen: {size: 4},
|
|
59
45
|
};
|
|
60
46
|
|
|
61
47
|
export const simplePacketFormat = {
|
|
62
|
-
originalPacketLength: {
|
|
63
|
-
size: 4,
|
|
64
|
-
},
|
|
48
|
+
originalPacketLength: {size: 4},
|
|
65
49
|
};
|
|
66
50
|
|
|
67
51
|
export const nameResolutionFormat = {
|
|
68
|
-
recordType: {
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
recordValueLength: {
|
|
72
|
-
size: 2,
|
|
73
|
-
},
|
|
52
|
+
recordType: {size: 2},
|
|
53
|
+
recordValueLength: {size: 2},
|
|
74
54
|
};
|
|
75
55
|
|
|
76
56
|
/**
|
|
77
57
|
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
|
|
78
58
|
*/
|
|
79
59
|
export const enhancedPacketBlockFormat = {
|
|
80
|
-
interfaceId: {
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
timestampLow: {
|
|
87
|
-
size: 4,
|
|
88
|
-
},
|
|
89
|
-
capturedPacketLength: {
|
|
90
|
-
size: 4,
|
|
91
|
-
},
|
|
92
|
-
originalPacketLength: {
|
|
93
|
-
size: 4,
|
|
94
|
-
},
|
|
60
|
+
interfaceId: {size: 4},
|
|
61
|
+
timestampHigh: {size: 4},
|
|
62
|
+
timestampLow: {size: 4},
|
|
63
|
+
capturedPacketLength: {size: 4},
|
|
64
|
+
originalPacketLength: {size: 4},
|
|
95
65
|
|
|
96
66
|
/* Packet Data */
|
|
97
67
|
/* Options */
|
|
@@ -101,51 +71,31 @@ export const enhancedPacketBlockFormat = {
|
|
|
101
71
|
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-options
|
|
102
72
|
*/
|
|
103
73
|
export const optionBlock = {
|
|
104
|
-
optionType: {
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
dataLength: {
|
|
108
|
-
size: 2,
|
|
109
|
-
},
|
|
74
|
+
optionType: {size: 2},
|
|
75
|
+
dataLength: {size: 2},
|
|
110
76
|
};
|
|
111
77
|
|
|
112
78
|
export const endLength = {
|
|
113
|
-
endTotalLength: {
|
|
114
|
-
size: 4,
|
|
115
|
-
},
|
|
79
|
+
endTotalLength: {size: 4},
|
|
116
80
|
};
|
|
117
81
|
|
|
118
82
|
export const privateEnterpriseNumber = {
|
|
119
|
-
pen: {
|
|
120
|
-
size: 4,
|
|
121
|
-
},
|
|
83
|
+
pen: {size: 4},
|
|
122
84
|
};
|
|
123
85
|
|
|
124
86
|
export const interfaceStatisticsFormat = {
|
|
125
|
-
interfaceId: {
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
timestampHigh: {
|
|
129
|
-
size: 4,
|
|
130
|
-
},
|
|
131
|
-
timestampLow: {
|
|
132
|
-
size: 4,
|
|
133
|
-
},
|
|
87
|
+
interfaceId: {size: 4},
|
|
88
|
+
timestampHigh: {size: 4},
|
|
89
|
+
timestampLow: {size: 4},
|
|
134
90
|
};
|
|
135
91
|
|
|
136
92
|
export const decryptionSecretsFormat = {
|
|
137
|
-
secretsType: {
|
|
138
|
-
|
|
139
|
-
},
|
|
140
|
-
secretsLength: {
|
|
141
|
-
size: 4,
|
|
142
|
-
},
|
|
93
|
+
secretsType: {size: 4},
|
|
94
|
+
secretsLength: {size: 4},
|
|
143
95
|
};
|
|
144
96
|
|
|
145
97
|
export const epbFlagsFormat = {
|
|
146
|
-
flags: {
|
|
147
|
-
size: 4,
|
|
148
|
-
},
|
|
98
|
+
flags: {size: 4},
|
|
149
99
|
};
|
|
150
100
|
|
|
151
101
|
export const ifTsOffsetFormat = {
|
|
@@ -156,31 +106,36 @@ export const ifTsOffsetFormat = {
|
|
|
156
106
|
};
|
|
157
107
|
|
|
158
108
|
export const ipv4MaskFormat = {
|
|
159
|
-
ipv4: {
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
mask: {
|
|
163
|
-
size: 4,
|
|
164
|
-
},
|
|
109
|
+
ipv4: {size: 4},
|
|
110
|
+
mask: {size: 4},
|
|
165
111
|
};
|
|
166
112
|
|
|
167
113
|
export const u32Format = {
|
|
168
|
-
u32: {
|
|
169
|
-
size: 4,
|
|
170
|
-
},
|
|
114
|
+
u32: {size: 4},
|
|
171
115
|
};
|
|
172
116
|
|
|
173
117
|
export const u64Format = {
|
|
174
|
-
u64: {
|
|
175
|
-
size: 8,
|
|
176
|
-
},
|
|
118
|
+
u64: {size: 8},
|
|
177
119
|
};
|
|
178
120
|
|
|
179
121
|
export const timestampFormat = {
|
|
180
|
-
timestampHigh: {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
},
|
|
122
|
+
timestampHigh: {size: 4},
|
|
123
|
+
timestampLow: {size: 4},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const pcapHeaderFormat = {
|
|
127
|
+
byteOrderMagic: {size: 4},
|
|
128
|
+
majorVersion: {size: 2},
|
|
129
|
+
minorVersion: {size: 2},
|
|
130
|
+
reserved1: {size: 4},
|
|
131
|
+
reserved2: {size: 4},
|
|
132
|
+
snapLen: {size: 4},
|
|
133
|
+
linkType: {size: 4},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const pcapPacketFormat = {
|
|
137
|
+
timestampHigh: {size: 4},
|
|
138
|
+
timestampLow: {size: 4},
|
|
139
|
+
capturedPacketLength: {size: 4},
|
|
140
|
+
originalPacketLength: {size: 4},
|
|
186
141
|
};
|
package/src/PCAPNGParser.js
CHANGED
|
@@ -12,9 +12,16 @@ import {
|
|
|
12
12
|
SIMPLE_PACKET,
|
|
13
13
|
} from './options.js';
|
|
14
14
|
import {NoFilter, TruncationError} from 'nofilter';
|
|
15
|
+
import {Buffer} from 'node:buffer';
|
|
16
|
+
import {LINK_TYPE_NAMES} from './linkTypes.js';
|
|
15
17
|
import {Transform} from 'node:stream';
|
|
16
18
|
import {decode as ipDecode} from '@leichtgewicht/ip-codec';
|
|
17
19
|
|
|
20
|
+
const PCAP_MAGIC_MICRO = 0xA1B2C3D4;
|
|
21
|
+
const PCAP_MAGIC_NANO = 0xA1B23C4D;
|
|
22
|
+
const PCAP_MAGIC_MICRO_LE = 0xD4C3B2A1;
|
|
23
|
+
const PCAP_MAGIC_NANO_LE = 0x4D3CB2A1;
|
|
24
|
+
|
|
18
25
|
/** @import {Readable, TransformCallback} from 'node:stream' */
|
|
19
26
|
/** @import {OptionType} from './options.js' */
|
|
20
27
|
|
|
@@ -97,6 +104,7 @@ function colons(buf) {
|
|
|
97
104
|
/**
|
|
98
105
|
* @typedef {object} Interface
|
|
99
106
|
* @property {number} linkType See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
|
|
107
|
+
* @property {string} [linkTypeName]
|
|
100
108
|
* @property {number} snapLen Capture length.
|
|
101
109
|
* @property {string} [name] Interface name.
|
|
102
110
|
* @property {bigint} tsoffset Offset, in MS, applied to each timestamp.
|
|
@@ -145,13 +153,13 @@ function colons(buf) {
|
|
|
145
153
|
|
|
146
154
|
/**
|
|
147
155
|
* @typedef {object} PacketFlags
|
|
148
|
-
* @property {typeof EPB_FLAGS_DIRECTIONS[number]} direction
|
|
149
|
-
* @property {typeof EPB_FLAGS_RECEPTION[number]} reception
|
|
156
|
+
* @property {typeof EPB_FLAGS_DIRECTIONS[number]} [direction]
|
|
157
|
+
* @property {typeof EPB_FLAGS_RECEPTION[number]} [reception]
|
|
150
158
|
* @property {number} FCSlen
|
|
151
|
-
* @property {boolean} noChecksum
|
|
152
|
-
* @property {boolean} checksumValid
|
|
153
|
-
* @property {boolean} TCPsegmentationOfflad
|
|
154
|
-
* @property {typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][]} linkLayerErrors
|
|
159
|
+
* @property {boolean} [noChecksum]
|
|
160
|
+
* @property {boolean} [checksumValid]
|
|
161
|
+
* @property {boolean} [TCPsegmentationOfflad]
|
|
162
|
+
* @property {typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][]} [linkLayerErrors]
|
|
155
163
|
*/
|
|
156
164
|
|
|
157
165
|
/**
|
|
@@ -286,6 +294,9 @@ export class PCAPNGParser extends Transform {
|
|
|
286
294
|
/** @type {AbortSignal | undefined} */
|
|
287
295
|
#signal = undefined;
|
|
288
296
|
|
|
297
|
+
/** Is this the -ng format, or the older format? */
|
|
298
|
+
#ng = true;
|
|
299
|
+
|
|
289
300
|
// #region Transform
|
|
290
301
|
|
|
291
302
|
/**
|
|
@@ -302,6 +313,15 @@ export class PCAPNGParser extends Transform {
|
|
|
302
313
|
this.#signal = signal;
|
|
303
314
|
}
|
|
304
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Is this file in the pcap-ng format?
|
|
318
|
+
*
|
|
319
|
+
* @returns If false, in the old pcap format.
|
|
320
|
+
*/
|
|
321
|
+
get ng() {
|
|
322
|
+
return this.#ng;
|
|
323
|
+
}
|
|
324
|
+
|
|
305
325
|
/**
|
|
306
326
|
* Transform chunks of data into packets and interface events.
|
|
307
327
|
* DO NOT call directly.
|
|
@@ -349,53 +369,133 @@ export class PCAPNGParser extends Transform {
|
|
|
349
369
|
async #readFile(nof) {
|
|
350
370
|
try {
|
|
351
371
|
await nof.waitFor(4);
|
|
352
|
-
const magic = /** @type {Buffer} */(
|
|
353
|
-
if (magic
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const block = await this.#readBlock(nof);
|
|
358
|
-
if (!block) {
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
switch (block.blockType) {
|
|
362
|
-
case SECTION_HEADER:
|
|
363
|
-
await this.#processSectionHeader(block);
|
|
364
|
-
break;
|
|
365
|
-
case INTERFACE_DESCRIPTION:
|
|
366
|
-
await this.#processInterface(block);
|
|
367
|
-
break;
|
|
368
|
-
case SIMPLE_PACKET:
|
|
369
|
-
await this.#processSimplePacket(block);
|
|
370
|
-
break;
|
|
371
|
-
case NAME_RESOLUTION:
|
|
372
|
-
await this.#processNameResolution(block);
|
|
373
|
-
break;
|
|
374
|
-
case INTERFACE_STATISTICS:
|
|
375
|
-
await this.#processInterfaceStatistics(block);
|
|
376
|
-
break;
|
|
377
|
-
case ENHANCED_PACKET:
|
|
378
|
-
await this.#processEnhancedPacket(block);
|
|
379
|
-
break;
|
|
380
|
-
case DECRYPTION_SECRETS:
|
|
381
|
-
await this.#processDecryptionSecrets(block);
|
|
382
|
-
break;
|
|
383
|
-
case CUSTOM_COPY:
|
|
384
|
-
case CUSTOM_NOCOPY:
|
|
385
|
-
await this.#processCustom(block);
|
|
386
|
-
break;
|
|
387
|
-
default:
|
|
388
|
-
if (block.blockType >= 0) {
|
|
389
|
-
this.emit('blockType', block.blockType);
|
|
390
|
-
}
|
|
372
|
+
const magic = /** @type {Buffer} */(nof.slice(0, 4)).readUint32BE(0);
|
|
373
|
+
if (magic === SECTION_HEADER) {
|
|
374
|
+
while (true) {
|
|
375
|
+
const block = await this.#readBlock(nof);
|
|
376
|
+
if (!block) {
|
|
391
377
|
break;
|
|
378
|
+
}
|
|
379
|
+
switch (block.blockType) {
|
|
380
|
+
case SECTION_HEADER:
|
|
381
|
+
await this.#processSectionHeader(block);
|
|
382
|
+
break;
|
|
383
|
+
case INTERFACE_DESCRIPTION:
|
|
384
|
+
await this.#processInterface(block);
|
|
385
|
+
break;
|
|
386
|
+
case SIMPLE_PACKET:
|
|
387
|
+
await this.#processSimplePacket(block);
|
|
388
|
+
break;
|
|
389
|
+
case NAME_RESOLUTION:
|
|
390
|
+
await this.#processNameResolution(block);
|
|
391
|
+
break;
|
|
392
|
+
case INTERFACE_STATISTICS:
|
|
393
|
+
await this.#processInterfaceStatistics(block);
|
|
394
|
+
break;
|
|
395
|
+
case ENHANCED_PACKET:
|
|
396
|
+
await this.#processEnhancedPacket(block);
|
|
397
|
+
break;
|
|
398
|
+
case DECRYPTION_SECRETS:
|
|
399
|
+
await this.#processDecryptionSecrets(block);
|
|
400
|
+
break;
|
|
401
|
+
case CUSTOM_COPY:
|
|
402
|
+
case CUSTOM_NOCOPY:
|
|
403
|
+
await this.#processCustom(block);
|
|
404
|
+
break;
|
|
405
|
+
default:
|
|
406
|
+
if (block.blockType >= 0) {
|
|
407
|
+
this.emit('blockType', block.blockType);
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
392
411
|
}
|
|
412
|
+
} else if (magic === PCAP_MAGIC_MICRO) {
|
|
413
|
+
await this.#readPCAP(nof, 'BE', false);
|
|
414
|
+
} else if (magic === PCAP_MAGIC_MICRO_LE) {
|
|
415
|
+
await this.#readPCAP(nof, 'LE', false);
|
|
416
|
+
} else if (magic === PCAP_MAGIC_NANO) {
|
|
417
|
+
await this.#readPCAP(nof, 'BE', true);
|
|
418
|
+
} else if (magic === PCAP_MAGIC_NANO_LE) {
|
|
419
|
+
await this.#readPCAP(nof, 'LE', true);
|
|
420
|
+
} else {
|
|
421
|
+
throw new Error(`Invalid file format: magic = ${magic}`);
|
|
393
422
|
}
|
|
394
423
|
} catch (er) {
|
|
395
424
|
this.emit('error', er);
|
|
396
425
|
}
|
|
397
426
|
}
|
|
398
427
|
|
|
428
|
+
/**
|
|
429
|
+
* Read an old-style PCAP file.
|
|
430
|
+
*
|
|
431
|
+
* @param {NoFilter} nof
|
|
432
|
+
* @param {Endianess} endian
|
|
433
|
+
* @param {boolean} nano
|
|
434
|
+
* @see https://www.ietf.org/archive/id/draft-ietf-opsawg-pcap-06.html
|
|
435
|
+
*/
|
|
436
|
+
async #readPCAP(nof, endian, nano) {
|
|
437
|
+
this.#endianess = endian;
|
|
438
|
+
this.#ng = false;
|
|
439
|
+
const {linkType, snapLen} = await this.#readNumbers(
|
|
440
|
+
nof, BlockConfig.pcapHeaderFormat
|
|
441
|
+
);
|
|
442
|
+
const tsresol = nano ? 1000000n : 1000n;
|
|
443
|
+
|
|
444
|
+
/** @type {Interface} */
|
|
445
|
+
const int = {
|
|
446
|
+
linkType: linkType & 0xffff,
|
|
447
|
+
snapLen,
|
|
448
|
+
tsresol,
|
|
449
|
+
tsoffset: 0n,
|
|
450
|
+
options: [],
|
|
451
|
+
};
|
|
452
|
+
const ltName = LINK_TYPE_NAMES.get(int.linkType);
|
|
453
|
+
if (ltName) {
|
|
454
|
+
int.linkTypeName = ltName;
|
|
455
|
+
}
|
|
456
|
+
const fcsPresent = Boolean(linkType & 0x04000000);
|
|
457
|
+
if (fcsPresent) {
|
|
458
|
+
const FCSlen = linkType >> 28; // 16 bit words
|
|
459
|
+
int.options.push({
|
|
460
|
+
optionType: 13,
|
|
461
|
+
name: 'if_fcslen',
|
|
462
|
+
data: Buffer.from([FCSlen * 16]), // Bits
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
this.interfaces.push(int);
|
|
466
|
+
this.emit('interface', int);
|
|
467
|
+
|
|
468
|
+
while (true) {
|
|
469
|
+
try {
|
|
470
|
+
await nof.waitFor(4);
|
|
471
|
+
} catch (er) {
|
|
472
|
+
if (er instanceof TruncationError && er.size === 4) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
throw er;
|
|
476
|
+
}
|
|
477
|
+
const {
|
|
478
|
+
timestampHigh, timestampLow, capturedPacketLength, originalPacketLength,
|
|
479
|
+
} = await this.#readNumbers(nof, BlockConfig.pcapPacketFormat);
|
|
480
|
+
|
|
481
|
+
const data = capturedPacketLength ?
|
|
482
|
+
/** @type {Buffer} */(await nof.readFull(capturedPacketLength)) :
|
|
483
|
+
Buffer.alloc(0);
|
|
484
|
+
|
|
485
|
+
/** @type {Packet} */
|
|
486
|
+
const pkt = {
|
|
487
|
+
interfaceId: 0,
|
|
488
|
+
timestamp: new Date(
|
|
489
|
+
(timestampHigh * 1000) + (timestampLow / Number(tsresol))
|
|
490
|
+
),
|
|
491
|
+
originalPacketLength,
|
|
492
|
+
data,
|
|
493
|
+
options: [],
|
|
494
|
+
};
|
|
495
|
+
this.push(pkt);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
399
499
|
/**
|
|
400
500
|
* Read a block.
|
|
401
501
|
*
|
|
@@ -563,7 +663,7 @@ export class PCAPNGParser extends Transform {
|
|
|
563
663
|
/**
|
|
564
664
|
* Read a set of numbers from the given input.
|
|
565
665
|
*
|
|
566
|
-
* @template {BlockDescriptor} T
|
|
666
|
+
* @template {BlockDescriptor} T Describe the name/length pairs.
|
|
567
667
|
* @param {NoFilter} nof
|
|
568
668
|
* @param {T} blockDescriptor
|
|
569
669
|
* @returns {Promise<Record<keyof T, number>>}
|
|
@@ -692,11 +792,15 @@ export class PCAPNGParser extends Transform {
|
|
|
692
792
|
);
|
|
693
793
|
const len = Math.min(originalPacketLength, int.snapLen);
|
|
694
794
|
|
|
795
|
+
const data = len ?
|
|
796
|
+
/** @type {Buffer} */(await block.data.read(len)) :
|
|
797
|
+
Buffer.alloc(0);
|
|
798
|
+
|
|
695
799
|
/** @type {Packet} */
|
|
696
800
|
const pkt = {
|
|
697
801
|
interfaceId: 0,
|
|
698
802
|
originalPacketLength,
|
|
699
|
-
data
|
|
803
|
+
data,
|
|
700
804
|
options: [],
|
|
701
805
|
};
|
|
702
806
|
// Skip dealing with padding
|
|
@@ -831,12 +935,16 @@ export class PCAPNGParser extends Transform {
|
|
|
831
935
|
throw new Error(`Invalid interface ID: ${interfaceId} >= ${this.interfaces.length}`);
|
|
832
936
|
}
|
|
833
937
|
|
|
938
|
+
const data = capturedPacketLength ?
|
|
939
|
+
/** @type {Buffer} */(block.data.read(capturedPacketLength)) :
|
|
940
|
+
Buffer.alloc(0);
|
|
941
|
+
|
|
834
942
|
/** @type {Packet} */
|
|
835
943
|
const pkt = {
|
|
836
944
|
interfaceId,
|
|
837
945
|
timestamp: this.#timestamp(timestampHigh, timestampLow, interfaceId),
|
|
838
946
|
originalPacketLength,
|
|
839
|
-
data
|
|
947
|
+
data,
|
|
840
948
|
options: [],
|
|
841
949
|
};
|
|
842
950
|
|
|
@@ -859,7 +967,7 @@ export class PCAPNGParser extends Transform {
|
|
|
859
967
|
flags >>= 16;
|
|
860
968
|
for (let i = 0; i < 8; i++) {
|
|
861
969
|
if (flags & 0x1) {
|
|
862
|
-
pkt.flags.linkLayerErrors
|
|
970
|
+
pkt.flags.linkLayerErrors?.push(EPB_FLAGS_LINK_LAYER_ERRORS[i]);
|
|
863
971
|
}
|
|
864
972
|
flags >>= 1;
|
|
865
973
|
}
|
|
@@ -921,7 +1029,7 @@ export class PCAPNGParser extends Transform {
|
|
|
921
1029
|
// safe, including the new events added by this class.
|
|
922
1030
|
|
|
923
1031
|
/**
|
|
924
|
-
* @template {keyof ParseEvents} K
|
|
1032
|
+
* @template {keyof ParseEvents} K Event name.
|
|
925
1033
|
* @param {K} eventName
|
|
926
1034
|
* @param {ParseEvents[K]} args
|
|
927
1035
|
* @returns {boolean}
|
|
@@ -931,7 +1039,7 @@ export class PCAPNGParser extends Transform {
|
|
|
931
1039
|
}
|
|
932
1040
|
|
|
933
1041
|
/**
|
|
934
|
-
* @template {keyof ParseEvents} K
|
|
1042
|
+
* @template {keyof ParseEvents} K Event name.
|
|
935
1043
|
* @param {K} eventName
|
|
936
1044
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
937
1045
|
* @returns {this}
|
|
@@ -942,7 +1050,7 @@ export class PCAPNGParser extends Transform {
|
|
|
942
1050
|
}
|
|
943
1051
|
|
|
944
1052
|
/**
|
|
945
|
-
* @template {keyof ParseEvents} K
|
|
1053
|
+
* @template {keyof ParseEvents} K Event name.
|
|
946
1054
|
* @param {K} eventName
|
|
947
1055
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
948
1056
|
* @returns {this}
|
|
@@ -953,7 +1061,7 @@ export class PCAPNGParser extends Transform {
|
|
|
953
1061
|
}
|
|
954
1062
|
|
|
955
1063
|
/**
|
|
956
|
-
* @template {keyof ParseEvents} K
|
|
1064
|
+
* @template {keyof ParseEvents} K Event name.
|
|
957
1065
|
* @param {K} eventName
|
|
958
1066
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
959
1067
|
* @returns {this}
|
|
@@ -964,7 +1072,7 @@ export class PCAPNGParser extends Transform {
|
|
|
964
1072
|
}
|
|
965
1073
|
|
|
966
1074
|
/**
|
|
967
|
-
* @template {keyof ParseEvents} K
|
|
1075
|
+
* @template {keyof ParseEvents} K Event name.
|
|
968
1076
|
* @param {K} eventName
|
|
969
1077
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
970
1078
|
* @returns {this}
|
|
@@ -975,7 +1083,7 @@ export class PCAPNGParser extends Transform {
|
|
|
975
1083
|
}
|
|
976
1084
|
|
|
977
1085
|
/**
|
|
978
|
-
* @template {keyof ParseEvents} K
|
|
1086
|
+
* @template {keyof ParseEvents} K Event name.
|
|
979
1087
|
* @param {K} eventName
|
|
980
1088
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
981
1089
|
* @returns {this}
|
|
@@ -986,7 +1094,7 @@ export class PCAPNGParser extends Transform {
|
|
|
986
1094
|
}
|
|
987
1095
|
|
|
988
1096
|
/**
|
|
989
|
-
* @template {keyof ParseEvents} K
|
|
1097
|
+
* @template {keyof ParseEvents} K Event name.
|
|
990
1098
|
* @param {K} eventName
|
|
991
1099
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
992
1100
|
* @returns {this}
|
package/src/linkTypes.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This will eventually have come from an IANA registry.
|
|
3
|
+
*
|
|
4
|
+
* @see https://www.ietf.org/archive/id/draft-ietf-opsawg-pcaplinktype-13.html
|
|
5
|
+
*/
|
|
6
|
+
export const LINK_TYPE_NAMES = new Map([
|
|
7
|
+
[0, 'NULL'],
|
|
8
|
+
[1, 'ETHERNET'],
|
|
9
|
+
[2, 'EXP_ETHERNET'],
|
|
10
|
+
[3, 'AX25'],
|
|
11
|
+
[4, 'PRONET'],
|
|
12
|
+
[5, 'CHAOS'],
|
|
13
|
+
[6, 'IEEE802_5'],
|
|
14
|
+
[7, 'ARCNET_BSD'],
|
|
15
|
+
[8, 'SLIP'],
|
|
16
|
+
[9, 'PPP'],
|
|
17
|
+
[10, 'FDDI'],
|
|
18
|
+
[50, 'PPP_HDLC'],
|
|
19
|
+
[51, 'PPP_ETHER'],
|
|
20
|
+
[99, 'SYMANTEC_FIREWALL'],
|
|
21
|
+
[100, 'ATM_RFC1483'],
|
|
22
|
+
[101, 'RAW'],
|
|
23
|
+
[102, 'SLIP_BSDOS'],
|
|
24
|
+
[103, 'PPP_BSDOS'],
|
|
25
|
+
[104, 'C_HDLC'],
|
|
26
|
+
[105, 'IEEE802_11'],
|
|
27
|
+
[106, 'ATM_CLIP'],
|
|
28
|
+
[107, 'FRELAY'],
|
|
29
|
+
[108, 'LOOP'],
|
|
30
|
+
[109, 'ENC'],
|
|
31
|
+
[110, 'LANE8023'],
|
|
32
|
+
[111, 'HIPPI'],
|
|
33
|
+
[112, 'HDLC'],
|
|
34
|
+
[113, 'LINUX_SLL'],
|
|
35
|
+
[114, 'LTALK'],
|
|
36
|
+
[115, 'ECONET'],
|
|
37
|
+
[116, 'IPFILTER'],
|
|
38
|
+
[117, 'PFLOG'],
|
|
39
|
+
[118, 'CISCO_IOS'],
|
|
40
|
+
[119, 'IEEE802_11_PRISM'],
|
|
41
|
+
[120, 'IEEE802_11_AIRONET'],
|
|
42
|
+
[121, 'HHDLC'],
|
|
43
|
+
[122, 'IP_OVER_FC'],
|
|
44
|
+
[123, 'SUNATM'],
|
|
45
|
+
[124, 'RIO'],
|
|
46
|
+
[125, 'PCI_EXP'],
|
|
47
|
+
[126, 'AURORA'],
|
|
48
|
+
[127, 'IEEE802_11_RADIOTAP'],
|
|
49
|
+
[128, 'TZSP'],
|
|
50
|
+
[129, 'ARCNET_LINUX'],
|
|
51
|
+
[130, 'JUNIPER_MLPPP'],
|
|
52
|
+
[131, 'JUNIPER_MLFR'],
|
|
53
|
+
[132, 'JUNIPER_ES'],
|
|
54
|
+
[133, 'JUNIPER_GGSN'],
|
|
55
|
+
[134, 'JUNIPER_MFR'],
|
|
56
|
+
[135, 'JUNIPER_ATM2'],
|
|
57
|
+
[136, 'JUNIPER_SERVICES'],
|
|
58
|
+
[137, 'JUNIPER_ATM1'],
|
|
59
|
+
[138, 'APPLE_IP_OVER_IEEE1394'],
|
|
60
|
+
[139, 'MTP2_WITH_PHDR'],
|
|
61
|
+
[140, 'MTP2'],
|
|
62
|
+
[141, 'MTP3'],
|
|
63
|
+
[142, 'SCCP'],
|
|
64
|
+
[143, 'DOCSIS'],
|
|
65
|
+
[144, 'LINUX_IRDA'],
|
|
66
|
+
[145, 'IBM_SP'],
|
|
67
|
+
[146, 'IBM_SN'],
|
|
68
|
+
[147, 'RESERVED_01'],
|
|
69
|
+
[148, 'RESERVED_02'],
|
|
70
|
+
[149, 'RESERVED_03'],
|
|
71
|
+
[150, 'RESERVED_04'],
|
|
72
|
+
[151, 'RESERVED_05'],
|
|
73
|
+
[152, 'RESERVED_06'],
|
|
74
|
+
[153, 'RESERVED_07'],
|
|
75
|
+
[154, 'RESERVED_08'],
|
|
76
|
+
[155, 'RESERVED_09'],
|
|
77
|
+
[156, 'RESERVED_10'],
|
|
78
|
+
[157, 'RESERVED_11'],
|
|
79
|
+
[158, 'RESERVED_12'],
|
|
80
|
+
[159, 'RESERVED_13'],
|
|
81
|
+
[160, 'RESERVED_14'],
|
|
82
|
+
[161, 'RESERVED_15'],
|
|
83
|
+
[162, 'RESERVED_16'],
|
|
84
|
+
[163, 'IEEE802_11_AVS'],
|
|
85
|
+
[164, 'JUNIPER_MONITOR'],
|
|
86
|
+
[165, 'BACNET_MS_TP'],
|
|
87
|
+
[166, 'PPP_PPPD'],
|
|
88
|
+
[167, 'JUNIPER_PPPOE'],
|
|
89
|
+
[168, 'JUNIPER_PPPOE_ATM'],
|
|
90
|
+
[169, 'GPRS_LLC'],
|
|
91
|
+
[170, 'GPF_T'],
|
|
92
|
+
[171, 'GPF_F'],
|
|
93
|
+
[172, 'GCOM_T1E1'],
|
|
94
|
+
[173, 'GCOM_SERIAL'],
|
|
95
|
+
[174, 'JUNIPER_PIC_PEER'],
|
|
96
|
+
[175, 'ERF_ETH'],
|
|
97
|
+
[176, 'ERF_POS'],
|
|
98
|
+
[177, 'LINUX_LAPD'],
|
|
99
|
+
[178, 'JUNIPER_ETHER'],
|
|
100
|
+
[179, 'JUNIPER_PPP'],
|
|
101
|
+
[180, 'JUNIPER_FRELAY'],
|
|
102
|
+
[181, 'JUNIPER_CHDLC'],
|
|
103
|
+
[182, 'MFR'],
|
|
104
|
+
[183, 'JUNIPER_VP'],
|
|
105
|
+
[184, 'A429'],
|
|
106
|
+
[185, 'A653_ICM'],
|
|
107
|
+
[186, 'USB_FREEBSD'],
|
|
108
|
+
[187, 'BLUETOOTH_HCI_H4'],
|
|
109
|
+
[188, 'IEEE802_16_MAC_CPS'],
|
|
110
|
+
[189, 'USB_LINUX'],
|
|
111
|
+
[190, 'CAN20B'],
|
|
112
|
+
[191, 'IEEE802_15_4_LINUX'],
|
|
113
|
+
[192, 'PPI'],
|
|
114
|
+
[193, 'IEEE802_16_MAC_CPS_RADIO'],
|
|
115
|
+
[194, 'JUNIPER_ISM'],
|
|
116
|
+
[195, 'IEEE802_15_4_WITHFCS'],
|
|
117
|
+
[196, 'SITA'],
|
|
118
|
+
[197, 'ERF'],
|
|
119
|
+
[198, 'RAIF1'],
|
|
120
|
+
[199, 'IPMB_KONTRON'],
|
|
121
|
+
[200, 'JUNIPER_ST'],
|
|
122
|
+
[201, 'BLUETOOTH_HCI_H4_WITH_PHDR'],
|
|
123
|
+
[202, 'AX25_KISS'],
|
|
124
|
+
[203, 'LAPD'],
|
|
125
|
+
[204, 'PPP_WITH_DIR'],
|
|
126
|
+
[205, 'C_HDLC_WITH_DIR'],
|
|
127
|
+
[206, 'FRELAY_WITH_DIR'],
|
|
128
|
+
[207, 'LAPB_WITH_DIR'],
|
|
129
|
+
[208, 'WillBarker-Proprietary'],
|
|
130
|
+
[209, 'I2C_LINUX'],
|
|
131
|
+
[210, 'FLEXRAY'],
|
|
132
|
+
[211, 'MOST'],
|
|
133
|
+
[212, 'LIN'],
|
|
134
|
+
[213, 'X2E_SERIAL'],
|
|
135
|
+
[214, 'X2E_XORAYA'],
|
|
136
|
+
[215, 'IEEE802_15_4_NONASK_PHY'],
|
|
137
|
+
[216, 'LINUX_EVDEV'],
|
|
138
|
+
[217, 'GSMTAP_UM'],
|
|
139
|
+
[218, 'GSMTAP_ABIS'],
|
|
140
|
+
[219, 'MPLS'],
|
|
141
|
+
[220, 'USB_LINUX_MMAPPED'],
|
|
142
|
+
[221, 'DECT'],
|
|
143
|
+
[222, 'AOS'],
|
|
144
|
+
[223, 'WIHART'],
|
|
145
|
+
[224, 'FC_2'],
|
|
146
|
+
[225, 'FC_2_WITH_FRAME_DELIMS'],
|
|
147
|
+
[226, 'IPNET'],
|
|
148
|
+
[227, 'CAN_SOCKETCAN'],
|
|
149
|
+
[228, 'IPV4'],
|
|
150
|
+
[229, 'IPV6'],
|
|
151
|
+
[230, 'IEEE802_15_4_NOFCS'],
|
|
152
|
+
[231, 'DBUS'],
|
|
153
|
+
[232, 'JUNIPER_VS'],
|
|
154
|
+
[233, 'JUNIPER_SRX_E2E'],
|
|
155
|
+
[234, 'JUNIPER_FIBRECHANNEL'],
|
|
156
|
+
[235, 'DVB_CI'],
|
|
157
|
+
[236, 'MUX27010'],
|
|
158
|
+
[237, 'STANAG_5066_D_PDU'],
|
|
159
|
+
[238, 'JUNIPER_ATM_CEMIC'],
|
|
160
|
+
[239, 'NFLOG'],
|
|
161
|
+
[240, 'NETANALYZER'],
|
|
162
|
+
[241, 'NETANALYZER_TRANSPARENT'],
|
|
163
|
+
[242, 'IPOIB'],
|
|
164
|
+
[243, 'MPEG_2_TS'],
|
|
165
|
+
[244, 'NG40'],
|
|
166
|
+
[245, 'NFC_LLCP'],
|
|
167
|
+
[246, 'PFSYNC'],
|
|
168
|
+
[247, 'INFINIBAND'],
|
|
169
|
+
[248, 'SCTP'],
|
|
170
|
+
[249, 'USBPCAP'],
|
|
171
|
+
[250, 'RTAC_SERIAL'],
|
|
172
|
+
[251, 'BLUETOOTH_LE_LL'],
|
|
173
|
+
[252, 'WIRESHARK_UPPER_PDU'],
|
|
174
|
+
[253, 'NETLINK'],
|
|
175
|
+
[254, 'BLUETOOTH_LINUX_MONITOR'],
|
|
176
|
+
[255, 'BLUETOOTH_BREDR_BB'],
|
|
177
|
+
[256, 'BLUETOOTH_LE_LL_WITH_PHDR'],
|
|
178
|
+
[257, 'PROFIBUS_DL'],
|
|
179
|
+
[258, 'PKTAP'],
|
|
180
|
+
[259, 'EPON'],
|
|
181
|
+
[260, 'IPMI_HPM_2'],
|
|
182
|
+
[261, 'ZWAVE_R1_R2'],
|
|
183
|
+
[262, 'ZWAVE_R3'],
|
|
184
|
+
[263, 'WATTSTOPPER_DLM'],
|
|
185
|
+
[264, 'ISO_14443'],
|
|
186
|
+
[265, 'RDS'],
|
|
187
|
+
[266, 'USB_DARWIN'],
|
|
188
|
+
[267, 'OPENFLOW'],
|
|
189
|
+
[268, 'SDLC'],
|
|
190
|
+
[269, 'TI_LLN_SNIFFER'],
|
|
191
|
+
[270, 'LORATAP'],
|
|
192
|
+
[271, 'VSOCK'],
|
|
193
|
+
[272, 'NORDIC_BLE'],
|
|
194
|
+
[273, 'DOCSIS31_XRA31'],
|
|
195
|
+
[274, 'ETHERNET_MPACKET'],
|
|
196
|
+
[275, 'DISPLAYPORT_AUX'],
|
|
197
|
+
[276, 'LINUX_SLL2'],
|
|
198
|
+
[277, 'SERCOS_MONITOR'],
|
|
199
|
+
[278, 'OPENVIZSLA'],
|
|
200
|
+
[279, 'EBHSCR'],
|
|
201
|
+
[280, 'VPP_DISPATCH'],
|
|
202
|
+
[281, 'DSA_TAG_BRCM'],
|
|
203
|
+
[282, 'DSA_TAG_BRCM_PREPEND'],
|
|
204
|
+
[283, 'IEEE802_15_4_TAP'],
|
|
205
|
+
[284, 'DSA_TAG_DSA'],
|
|
206
|
+
[285, 'DSA_TAG_EDSA'],
|
|
207
|
+
[286, 'ELEE'],
|
|
208
|
+
[287, 'Z_WAVE_SERIAL'],
|
|
209
|
+
[288, 'USB_2_0'],
|
|
210
|
+
[289, 'ATSC_ALP'],
|
|
211
|
+
[290, 'ETW'],
|
|
212
|
+
[291, 'NETANALYZER_NG'],
|
|
213
|
+
[292, 'ZBOSS_NCP'],
|
|
214
|
+
[293, 'USB_2_0_LOW_SPEED'],
|
|
215
|
+
[294, 'USB_2_0_FULL_SPEED'],
|
|
216
|
+
[295, 'USB_2_0_HIGH_SPEED'],
|
|
217
|
+
[296, 'AUERSWALD_LOG'],
|
|
218
|
+
[297, 'ZWAVE_TAP'],
|
|
219
|
+
[298, 'SILABS_DEBUG_CHANNEL'],
|
|
220
|
+
[299, 'FIRA_UCI'],
|
|
221
|
+
[300, 'MDB'],
|
|
222
|
+
[301, 'DECT_NR'],
|
|
223
|
+
]);
|
package/types/BlockConfig.d.ts
CHANGED
|
@@ -179,6 +179,63 @@ export namespace timestampFormat {
|
|
|
179
179
|
}
|
|
180
180
|
export { timestampLow_2 as timestampLow };
|
|
181
181
|
}
|
|
182
|
+
export namespace pcapHeaderFormat {
|
|
183
|
+
export namespace byteOrderMagic_1 {
|
|
184
|
+
let size_34: number;
|
|
185
|
+
export { size_34 as size };
|
|
186
|
+
}
|
|
187
|
+
export { byteOrderMagic_1 as byteOrderMagic };
|
|
188
|
+
export namespace majorVersion_1 {
|
|
189
|
+
let size_35: number;
|
|
190
|
+
export { size_35 as size };
|
|
191
|
+
}
|
|
192
|
+
export { majorVersion_1 as majorVersion };
|
|
193
|
+
export namespace minorVersion_1 {
|
|
194
|
+
let size_36: number;
|
|
195
|
+
export { size_36 as size };
|
|
196
|
+
}
|
|
197
|
+
export { minorVersion_1 as minorVersion };
|
|
198
|
+
export namespace reserved1 {
|
|
199
|
+
let size_37: number;
|
|
200
|
+
export { size_37 as size };
|
|
201
|
+
}
|
|
202
|
+
export namespace reserved2 {
|
|
203
|
+
let size_38: number;
|
|
204
|
+
export { size_38 as size };
|
|
205
|
+
}
|
|
206
|
+
export namespace snapLen_1 {
|
|
207
|
+
let size_39: number;
|
|
208
|
+
export { size_39 as size };
|
|
209
|
+
}
|
|
210
|
+
export { snapLen_1 as snapLen };
|
|
211
|
+
export namespace linkType_1 {
|
|
212
|
+
let size_40: number;
|
|
213
|
+
export { size_40 as size };
|
|
214
|
+
}
|
|
215
|
+
export { linkType_1 as linkType };
|
|
216
|
+
}
|
|
217
|
+
export namespace pcapPacketFormat {
|
|
218
|
+
export namespace timestampHigh_3 {
|
|
219
|
+
let size_41: number;
|
|
220
|
+
export { size_41 as size };
|
|
221
|
+
}
|
|
222
|
+
export { timestampHigh_3 as timestampHigh };
|
|
223
|
+
export namespace timestampLow_3 {
|
|
224
|
+
let size_42: number;
|
|
225
|
+
export { size_42 as size };
|
|
226
|
+
}
|
|
227
|
+
export { timestampLow_3 as timestampLow };
|
|
228
|
+
export namespace capturedPacketLength_1 {
|
|
229
|
+
let size_43: number;
|
|
230
|
+
export { size_43 as size };
|
|
231
|
+
}
|
|
232
|
+
export { capturedPacketLength_1 as capturedPacketLength };
|
|
233
|
+
export namespace originalPacketLength_2 {
|
|
234
|
+
let size_44: number;
|
|
235
|
+
export { size_44 as size };
|
|
236
|
+
}
|
|
237
|
+
export { originalPacketLength_2 as originalPacketLength };
|
|
238
|
+
}
|
|
182
239
|
export type BlockProperty = {
|
|
183
240
|
/**
|
|
184
241
|
* Bytes.
|
package/types/PCAPNGParser.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {object} Interface
|
|
3
3
|
* @property {number} linkType See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
|
|
4
|
+
* @property {string} [linkTypeName]
|
|
4
5
|
* @property {number} snapLen Capture length.
|
|
5
6
|
* @property {string} [name] Interface name.
|
|
6
7
|
* @property {bigint} tsoffset Offset, in MS, applied to each timestamp.
|
|
@@ -42,13 +43,13 @@
|
|
|
42
43
|
*/
|
|
43
44
|
/**
|
|
44
45
|
* @typedef {object} PacketFlags
|
|
45
|
-
* @property {typeof EPB_FLAGS_DIRECTIONS[number]} direction
|
|
46
|
-
* @property {typeof EPB_FLAGS_RECEPTION[number]} reception
|
|
46
|
+
* @property {typeof EPB_FLAGS_DIRECTIONS[number]} [direction]
|
|
47
|
+
* @property {typeof EPB_FLAGS_RECEPTION[number]} [reception]
|
|
47
48
|
* @property {number} FCSlen
|
|
48
|
-
* @property {boolean} noChecksum
|
|
49
|
-
* @property {boolean} checksumValid
|
|
50
|
-
* @property {boolean} TCPsegmentationOfflad
|
|
51
|
-
* @property {typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][]} linkLayerErrors
|
|
49
|
+
* @property {boolean} [noChecksum]
|
|
50
|
+
* @property {boolean} [checksumValid]
|
|
51
|
+
* @property {boolean} [TCPsegmentationOfflad]
|
|
52
|
+
* @property {typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][]} [linkLayerErrors]
|
|
52
53
|
*/
|
|
53
54
|
/**
|
|
54
55
|
* @typedef {object} Packet
|
|
@@ -149,6 +150,12 @@ export class PCAPNGParser extends Transform {
|
|
|
149
150
|
constructor(opts?: ParserOptions);
|
|
150
151
|
/** @type {Interface[]} */
|
|
151
152
|
interfaces: Interface[];
|
|
153
|
+
/**
|
|
154
|
+
* Is this file in the pcap-ng format?
|
|
155
|
+
*
|
|
156
|
+
* @returns If false, in the old pcap format.
|
|
157
|
+
*/
|
|
158
|
+
get ng(): boolean;
|
|
152
159
|
/**
|
|
153
160
|
* Transform chunks of data into packets and interface events.
|
|
154
161
|
* DO NOT call directly.
|
|
@@ -159,49 +166,49 @@ export class PCAPNGParser extends Transform {
|
|
|
159
166
|
*/
|
|
160
167
|
_transform(chunk: Buffer, _encoding: string, callback: TransformCallback): void;
|
|
161
168
|
/**
|
|
162
|
-
* @template {keyof ParseEvents} K
|
|
169
|
+
* @template {keyof ParseEvents} K Event name.
|
|
163
170
|
* @param {K} eventName
|
|
164
171
|
* @param {ParseEvents[K]} args
|
|
165
172
|
* @returns {boolean}
|
|
166
173
|
*/
|
|
167
174
|
emit<K extends keyof ParseEvents>(eventName: K, ...args: ParseEvents[K]): boolean;
|
|
168
175
|
/**
|
|
169
|
-
* @template {keyof ParseEvents} K
|
|
176
|
+
* @template {keyof ParseEvents} K Event name.
|
|
170
177
|
* @param {K} eventName
|
|
171
178
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
172
179
|
* @returns {this}
|
|
173
180
|
*/
|
|
174
181
|
addListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
|
|
175
182
|
/**
|
|
176
|
-
* @template {keyof ParseEvents} K
|
|
183
|
+
* @template {keyof ParseEvents} K Event name.
|
|
177
184
|
* @param {K} eventName
|
|
178
185
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
179
186
|
* @returns {this}
|
|
180
187
|
*/
|
|
181
188
|
prependListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
|
|
182
189
|
/**
|
|
183
|
-
* @template {keyof ParseEvents} K
|
|
190
|
+
* @template {keyof ParseEvents} K Event name.
|
|
184
191
|
* @param {K} eventName
|
|
185
192
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
186
193
|
* @returns {this}
|
|
187
194
|
*/
|
|
188
195
|
prependOnceListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
|
|
189
196
|
/**
|
|
190
|
-
* @template {keyof ParseEvents} K
|
|
197
|
+
* @template {keyof ParseEvents} K Event name.
|
|
191
198
|
* @param {K} eventName
|
|
192
199
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
193
200
|
* @returns {this}
|
|
194
201
|
*/
|
|
195
202
|
removeListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
|
|
196
203
|
/**
|
|
197
|
-
* @template {keyof ParseEvents} K
|
|
204
|
+
* @template {keyof ParseEvents} K Event name.
|
|
198
205
|
* @param {K} eventName
|
|
199
206
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
200
207
|
* @returns {this}
|
|
201
208
|
*/
|
|
202
209
|
on<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
|
|
203
210
|
/**
|
|
204
|
-
* @template {keyof ParseEvents} K
|
|
211
|
+
* @template {keyof ParseEvents} K Event name.
|
|
205
212
|
* @param {K} eventName
|
|
206
213
|
* @param {(...args: ParseEvents[K]) => void} listener
|
|
207
214
|
* @returns {this}
|
|
@@ -215,6 +222,7 @@ export type Interface = {
|
|
|
215
222
|
* See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
|
|
216
223
|
*/
|
|
217
224
|
linkType: number;
|
|
225
|
+
linkTypeName?: string;
|
|
218
226
|
/**
|
|
219
227
|
* Capture length.
|
|
220
228
|
*/
|
|
@@ -265,13 +273,13 @@ export type NameResolution = {
|
|
|
265
273
|
options: Option[];
|
|
266
274
|
};
|
|
267
275
|
export type PacketFlags = {
|
|
268
|
-
direction
|
|
269
|
-
reception
|
|
276
|
+
direction?: (typeof EPB_FLAGS_DIRECTIONS)[number];
|
|
277
|
+
reception?: (typeof EPB_FLAGS_RECEPTION)[number];
|
|
270
278
|
FCSlen: number;
|
|
271
|
-
noChecksum
|
|
272
|
-
checksumValid
|
|
273
|
-
TCPsegmentationOfflad
|
|
274
|
-
linkLayerErrors
|
|
279
|
+
noChecksum?: boolean;
|
|
280
|
+
checksumValid?: boolean;
|
|
281
|
+
TCPsegmentationOfflad?: boolean;
|
|
282
|
+
linkLayerErrors?: (typeof EPB_FLAGS_LINK_LAYER_ERRORS)[number][];
|
|
275
283
|
};
|
|
276
284
|
export type Packet = {
|
|
277
285
|
interfaceId: number;
|
|
@@ -407,6 +415,7 @@ export type ParserOptions = {
|
|
|
407
415
|
signal?: AbortSignal;
|
|
408
416
|
};
|
|
409
417
|
import { Transform } from 'node:stream';
|
|
418
|
+
import { Buffer } from 'node:buffer';
|
|
410
419
|
import type { TransformCallback } from 'node:stream';
|
|
411
420
|
/** @import {Readable, TransformCallback} from 'node:stream' */
|
|
412
421
|
/** @import {OptionType} from './options.js' */
|