@cto.af/pcap-ng-parser 2.0.3 → 3.0.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.
@@ -1,192 +0,0 @@
1
- export namespace sectionHeaderBlock {
2
- namespace byteOrderMagic {
3
- let size: number;
4
- }
5
- namespace majorVersion {
6
- let size_1: number;
7
- export { size_1 as size };
8
- }
9
- namespace minorVersion {
10
- let size_2: number;
11
- export { size_2 as size };
12
- }
13
- namespace sectionLength {
14
- let size_3: number;
15
- export { size_3 as size };
16
- export let signed: boolean;
17
- }
18
- }
19
- export namespace blockType {
20
- namespace blockType {
21
- let size_4: number;
22
- export { size_4 as size };
23
- let signed_1: boolean;
24
- export { signed_1 as signed };
25
- }
26
- }
27
- export namespace blockTotalLength {
28
- namespace blockTotalLength {
29
- let size_5: number;
30
- export { size_5 as size };
31
- }
32
- }
33
- export namespace interfaceDescriptionBlockFormat {
34
- namespace linkType {
35
- let size_6: number;
36
- export { size_6 as size };
37
- }
38
- namespace reserved {
39
- let size_7: number;
40
- export { size_7 as size };
41
- }
42
- namespace snapLen {
43
- let size_8: number;
44
- export { size_8 as size };
45
- }
46
- }
47
- export namespace simplePacketFormat {
48
- namespace originalPacketLength {
49
- let size_9: number;
50
- export { size_9 as size };
51
- }
52
- }
53
- export namespace nameResolutionFormat {
54
- namespace recordType {
55
- let size_10: number;
56
- export { size_10 as size };
57
- }
58
- namespace recordValueLength {
59
- let size_11: number;
60
- export { size_11 as size };
61
- }
62
- }
63
- export namespace enhancedPacketBlockFormat {
64
- export namespace interfaceId {
65
- let size_12: number;
66
- export { size_12 as size };
67
- }
68
- export namespace timestampHigh {
69
- let size_13: number;
70
- export { size_13 as size };
71
- }
72
- export namespace timestampLow {
73
- let size_14: number;
74
- export { size_14 as size };
75
- }
76
- export namespace capturedPacketLength {
77
- let size_15: number;
78
- export { size_15 as size };
79
- }
80
- export namespace originalPacketLength_1 {
81
- let size_16: number;
82
- export { size_16 as size };
83
- }
84
- export { originalPacketLength_1 as originalPacketLength };
85
- }
86
- export namespace optionBlock {
87
- namespace optionType {
88
- let size_17: number;
89
- export { size_17 as size };
90
- }
91
- namespace dataLength {
92
- let size_18: number;
93
- export { size_18 as size };
94
- }
95
- }
96
- export namespace endLength {
97
- namespace endTotalLength {
98
- let size_19: number;
99
- export { size_19 as size };
100
- }
101
- }
102
- export namespace privateEnterpriseNumber {
103
- namespace pen {
104
- let size_20: number;
105
- export { size_20 as size };
106
- }
107
- }
108
- export namespace interfaceStatisticsFormat {
109
- export namespace interfaceId_1 {
110
- let size_21: number;
111
- export { size_21 as size };
112
- }
113
- export { interfaceId_1 as interfaceId };
114
- export namespace timestampHigh_1 {
115
- let size_22: number;
116
- export { size_22 as size };
117
- }
118
- export { timestampHigh_1 as timestampHigh };
119
- export namespace timestampLow_1 {
120
- let size_23: number;
121
- export { size_23 as size };
122
- }
123
- export { timestampLow_1 as timestampLow };
124
- }
125
- export namespace decryptionSecretsFormat {
126
- namespace secretsType {
127
- let size_24: number;
128
- export { size_24 as size };
129
- }
130
- namespace secretsLength {
131
- let size_25: number;
132
- export { size_25 as size };
133
- }
134
- }
135
- export namespace epbFlagsFormat {
136
- namespace flags {
137
- let size_26: number;
138
- export { size_26 as size };
139
- }
140
- }
141
- export namespace ifTsOffsetFormat {
142
- namespace tsoffset {
143
- let size_27: number;
144
- export { size_27 as size };
145
- export let sign: boolean;
146
- }
147
- }
148
- export namespace ipv4MaskFormat {
149
- namespace ipv4 {
150
- let size_28: number;
151
- export { size_28 as size };
152
- }
153
- namespace mask {
154
- let size_29: number;
155
- export { size_29 as size };
156
- }
157
- }
158
- export namespace u32Format {
159
- namespace u32 {
160
- let size_30: number;
161
- export { size_30 as size };
162
- }
163
- }
164
- export namespace u64Format {
165
- namespace u64 {
166
- let size_31: number;
167
- export { size_31 as size };
168
- }
169
- }
170
- export namespace timestampFormat {
171
- export namespace timestampHigh_2 {
172
- let size_32: number;
173
- export { size_32 as size };
174
- }
175
- export { timestampHigh_2 as timestampHigh };
176
- export namespace timestampLow_2 {
177
- let size_33: number;
178
- export { size_33 as size };
179
- }
180
- export { timestampLow_2 as timestampLow };
181
- }
182
- export type BlockProperty = {
183
- /**
184
- * Bytes.
185
- */
186
- size: number;
187
- /**
188
- * If true, read signed.
189
- */
190
- signed?: boolean;
191
- };
192
- export type BlockDescriptor = Record<string, BlockProperty>;
@@ -1,417 +0,0 @@
1
- /**
2
- * @typedef {object} Interface
3
- * @property {number} linkType See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
4
- * @property {number} snapLen Capture length.
5
- * @property {string} [name] Interface name.
6
- * @property {bigint} tsoffset Offset, in MS, applied to each timestamp.
7
- * @property {bigint} tsresol Timestamp resolution in MS.
8
- * @property {Option[]} options All interface options.
9
- */
10
- /**
11
- * @typedef {object} IPv4ResolutionRecord
12
- * @property {'nrb_record_ipv4'} name
13
- * @property {string} ipv4
14
- * @property {string[]} entries
15
- */
16
- /**
17
- * @typedef {object} IPv6ResolutionRecord
18
- * @property {'nrb_record_ipv6'} name
19
- * @property {string} ipv6
20
- * @property {string[]} entries
21
- */
22
- /**
23
- * @typedef {object} EUI48ResolutionRecord
24
- * @property {'nrb_record_eui48'} name
25
- * @property {string} eui48
26
- * @property {string[]} entries
27
- */
28
- /**
29
- * @typedef {object} EUI64ResolutionRecord
30
- * @property {'nrb_record_eui64'} name
31
- * @property {string} eui64
32
- * @property {string[]} entries
33
- */
34
- /**
35
- * @typedef {IPv4ResolutionRecord | IPv6ResolutionRecord |
36
- * EUI48ResolutionRecord | EUI64ResolutionRecord} NameResolutionRecord
37
- */
38
- /**
39
- * @typedef {object} NameResolution
40
- * @property {NameResolutionRecord[]} records
41
- * @property {Option[]} options NameResolution options.
42
- */
43
- /**
44
- * @typedef {object} PacketFlags
45
- * @property {typeof EPB_FLAGS_DIRECTIONS[number]} direction
46
- * @property {typeof EPB_FLAGS_RECEPTION[number]} reception
47
- * @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
52
- */
53
- /**
54
- * @typedef {object} Packet
55
- * @property {number} interfaceId
56
- * @property {Date} [timestamp]
57
- * @property {PacketFlags} [flags]
58
- * @property {number} originalPacketLength
59
- * @property {Buffer} data
60
- * @property {Option[]} options
61
- */
62
- /**
63
- * @typedef {object} InterfaceStatistics
64
- * @property {number} interfaceId
65
- * @property {Date} timestamp
66
- * @property {Option[]} options
67
- */
68
- /**
69
- * @typedef {object} DecryptionSecrets
70
- * @property {number} secretsType
71
- * @property {Buffer} data
72
- * @property {Option[]} options
73
- */
74
- /**
75
- * @typedef {object} CustomBlock
76
- * @property {number} pen
77
- * @property {Buffer} data
78
- * @property {boolean} copy
79
- */
80
- /**
81
- * @typedef {object} BlockConfig
82
- * @property {number} blockType
83
- * @property {number} blockTotalLength
84
- */
85
- /**
86
- * @typedef {object} Data
87
- * @property {NoFilter} data
88
- */
89
- /**
90
- * @typedef {BlockConfig & Data} Block
91
- */
92
- /**
93
- * @typedef {object} GenericOption
94
- * @property {number} optionType
95
- * @property {number} [dataLength]
96
- * @property {Buffer} [data]
97
- * @property {string} [str]
98
- * @property {bigint} [bigint]
99
- * @property {Date} [date]
100
- * @property {string} [name]
101
- * @property {boolean} [private]
102
- */
103
- /**
104
- * @typedef {object} PrivateEnterpriseNumber
105
- * @property {number} [pen]
106
- */
107
- /** @typedef {GenericOption & PrivateEnterpriseNumber} Option */
108
- /** @typedef {"BE" | "LE"} Endianess */
109
- /**
110
- * @typedef {object} SectionHeader
111
- * @property {Endianess} endianess
112
- * @property {number} majorVersion
113
- * @property {number} minorVersion
114
- * @property {number} sectionLength
115
- * @property {Option[]} [options]
116
- */
117
- /**
118
- * @typedef {object} ParseEvents
119
- * @property {[number]} blockType Unknown block type received.
120
- * @property {[]} close Both ends of the stream have closed.
121
- * @property {[CustomBlock]} custom A Custom block was read.
122
- * @property {[Packet]} data A Simple or Extended Packet was read.
123
- * @property {[]} drain If a call to stream.write(chunk) returns false, the
124
- * 'drain' event will be emitted when it is appropriate to resume writing
125
- * data to the stream.
126
- * @property {[]} end There is no more data to be consumed from the stream.
127
- * @property {[unknown]} error Error in parsing.
128
- * @property {[]} finish The input to the parse stream has ended.
129
- * @property {[Interface]} interface An Interface record was read.
130
- * @property {[NameResolution]} names A NameResolution record was read.
131
- * @property {[]} pause `stream.pause()` was called.
132
- * @property {[Readable]} pipe Output of stream was redirect.
133
- * @property {[SectionHeader]} section A new Section has started. Always emitted
134
- * before other parse events in a valid file.
135
- * @property {[]} readable Data is available to be read from the stream.
136
- * @property {[]} resume `stream.resume()` was called.
137
- * @property {[DecryptionSecrets]} secrets A Decryption Secrets block was read.
138
- * @property {[InterfaceStatistics]} stats Interface Statistics block was read.
139
- * @property {[Readable]} unpipe `stream.unpipe()` was called.
140
- */
141
- /**
142
- * @typedef {object} ParserOptions
143
- * @property {AbortSignal} [signal]
144
- */
145
- export class PCAPNGParser extends Transform {
146
- /**
147
- * @param {ParserOptions} opts
148
- */
149
- constructor(opts?: ParserOptions);
150
- /** @type {Interface[]} */
151
- interfaces: Interface[];
152
- /**
153
- * Transform chunks of data into packets and interface events.
154
- * DO NOT call directly.
155
- *
156
- * @param {Buffer} chunk Data to process.
157
- * @param {string} _encoding Ignored.
158
- * @param {TransformCallback} callback Called when finished with chunk.
159
- */
160
- _transform(chunk: Buffer, _encoding: string, callback: TransformCallback): void;
161
- /**
162
- * @template {keyof ParseEvents} K
163
- * @param {K} eventName
164
- * @param {ParseEvents[K]} args
165
- * @returns {boolean}
166
- */
167
- emit<K extends keyof ParseEvents>(eventName: K, ...args: ParseEvents[K]): boolean;
168
- /**
169
- * @template {keyof ParseEvents} K
170
- * @param {K} eventName
171
- * @param {(...args: ParseEvents[K]) => void} listener
172
- * @returns {this}
173
- */
174
- addListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
175
- /**
176
- * @template {keyof ParseEvents} K
177
- * @param {K} eventName
178
- * @param {(...args: ParseEvents[K]) => void} listener
179
- * @returns {this}
180
- */
181
- prependListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
182
- /**
183
- * @template {keyof ParseEvents} K
184
- * @param {K} eventName
185
- * @param {(...args: ParseEvents[K]) => void} listener
186
- * @returns {this}
187
- */
188
- prependOnceListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
189
- /**
190
- * @template {keyof ParseEvents} K
191
- * @param {K} eventName
192
- * @param {(...args: ParseEvents[K]) => void} listener
193
- * @returns {this}
194
- */
195
- removeListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
196
- /**
197
- * @template {keyof ParseEvents} K
198
- * @param {K} eventName
199
- * @param {(...args: ParseEvents[K]) => void} listener
200
- * @returns {this}
201
- */
202
- on<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
203
- /**
204
- * @template {keyof ParseEvents} K
205
- * @param {K} eventName
206
- * @param {(...args: ParseEvents[K]) => void} listener
207
- * @returns {this}
208
- */
209
- once<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
210
- #private;
211
- }
212
- export default PCAPNGParser;
213
- export type Interface = {
214
- /**
215
- * See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
216
- */
217
- linkType: number;
218
- /**
219
- * Capture length.
220
- */
221
- snapLen: number;
222
- /**
223
- * Interface name.
224
- */
225
- name?: string;
226
- /**
227
- * Offset, in MS, applied to each timestamp.
228
- */
229
- tsoffset: bigint;
230
- /**
231
- * Timestamp resolution in MS.
232
- */
233
- tsresol: bigint;
234
- /**
235
- * All interface options.
236
- */
237
- options: Option[];
238
- };
239
- export type IPv4ResolutionRecord = {
240
- name: "nrb_record_ipv4";
241
- ipv4: string;
242
- entries: string[];
243
- };
244
- export type IPv6ResolutionRecord = {
245
- name: "nrb_record_ipv6";
246
- ipv6: string;
247
- entries: string[];
248
- };
249
- export type EUI48ResolutionRecord = {
250
- name: "nrb_record_eui48";
251
- eui48: string;
252
- entries: string[];
253
- };
254
- export type EUI64ResolutionRecord = {
255
- name: "nrb_record_eui64";
256
- eui64: string;
257
- entries: string[];
258
- };
259
- export type NameResolutionRecord = IPv4ResolutionRecord | IPv6ResolutionRecord | EUI48ResolutionRecord | EUI64ResolutionRecord;
260
- export type NameResolution = {
261
- records: NameResolutionRecord[];
262
- /**
263
- * NameResolution options.
264
- */
265
- options: Option[];
266
- };
267
- export type PacketFlags = {
268
- direction: (typeof EPB_FLAGS_DIRECTIONS)[number];
269
- reception: (typeof EPB_FLAGS_RECEPTION)[number];
270
- FCSlen: number;
271
- noChecksum: boolean;
272
- checksumValid: boolean;
273
- TCPsegmentationOfflad: boolean;
274
- linkLayerErrors: (typeof EPB_FLAGS_LINK_LAYER_ERRORS)[number][];
275
- };
276
- export type Packet = {
277
- interfaceId: number;
278
- timestamp?: Date;
279
- flags?: PacketFlags;
280
- originalPacketLength: number;
281
- data: Buffer;
282
- options: Option[];
283
- };
284
- export type InterfaceStatistics = {
285
- interfaceId: number;
286
- timestamp: Date;
287
- options: Option[];
288
- };
289
- export type DecryptionSecrets = {
290
- secretsType: number;
291
- data: Buffer;
292
- options: Option[];
293
- };
294
- export type CustomBlock = {
295
- pen: number;
296
- data: Buffer;
297
- copy: boolean;
298
- };
299
- export type BlockConfig = {
300
- blockType: number;
301
- blockTotalLength: number;
302
- };
303
- export type Data = {
304
- data: NoFilter;
305
- };
306
- export type Block = BlockConfig & Data;
307
- export type GenericOption = {
308
- optionType: number;
309
- dataLength?: number;
310
- data?: Buffer;
311
- str?: string;
312
- bigint?: bigint;
313
- date?: Date;
314
- name?: string;
315
- private?: boolean;
316
- };
317
- export type PrivateEnterpriseNumber = {
318
- pen?: number;
319
- };
320
- export type Option = GenericOption & PrivateEnterpriseNumber;
321
- export type Endianess = "BE" | "LE";
322
- export type SectionHeader = {
323
- endianess: Endianess;
324
- majorVersion: number;
325
- minorVersion: number;
326
- sectionLength: number;
327
- options?: Option[];
328
- };
329
- export type ParseEvents = {
330
- /**
331
- * Unknown block type received.
332
- */
333
- blockType: [number];
334
- /**
335
- * Both ends of the stream have closed.
336
- */
337
- close: [];
338
- /**
339
- * A Custom block was read.
340
- */
341
- custom: [CustomBlock];
342
- /**
343
- * A Simple or Extended Packet was read.
344
- */
345
- data: [Packet];
346
- /**
347
- * If a call to stream.write(chunk) returns false, the
348
- * 'drain' event will be emitted when it is appropriate to resume writing
349
- * data to the stream.
350
- */
351
- drain: [];
352
- /**
353
- * There is no more data to be consumed from the stream.
354
- */
355
- end: [];
356
- /**
357
- * Error in parsing.
358
- */
359
- error: [unknown];
360
- /**
361
- * The input to the parse stream has ended.
362
- */
363
- finish: [];
364
- /**
365
- * An Interface record was read.
366
- */
367
- interface: [Interface];
368
- /**
369
- * A NameResolution record was read.
370
- */
371
- names: [NameResolution];
372
- /**
373
- * `stream.pause()` was called.
374
- */
375
- pause: [];
376
- /**
377
- * Output of stream was redirect.
378
- */
379
- pipe: [Readable];
380
- /**
381
- * A new Section has started. Always emitted
382
- * before other parse events in a valid file.
383
- */
384
- section: [SectionHeader];
385
- /**
386
- * Data is available to be read from the stream.
387
- */
388
- readable: [];
389
- /**
390
- * `stream.resume()` was called.
391
- */
392
- resume: [];
393
- /**
394
- * A Decryption Secrets block was read.
395
- */
396
- secrets: [DecryptionSecrets];
397
- /**
398
- * Interface Statistics block was read.
399
- */
400
- stats: [InterfaceStatistics];
401
- /**
402
- * `stream.unpipe()` was called.
403
- */
404
- unpipe: [Readable];
405
- };
406
- export type ParserOptions = {
407
- signal?: AbortSignal;
408
- };
409
- import { Transform } from 'node:stream';
410
- import type { TransformCallback } from 'node:stream';
411
- /** @import {Readable, TransformCallback} from 'node:stream' */
412
- /** @import {OptionType} from './options.js' */
413
- declare const EPB_FLAGS_DIRECTIONS: readonly ["notAvailable", "inbound", "outbound", "invalid"];
414
- declare const EPB_FLAGS_RECEPTION: readonly ["notSpecified", "unicast", "multicast", "broadcast", "promiscuous", "invalid", "invalid", "invalid"];
415
- declare const EPB_FLAGS_LINK_LAYER_ERRORS: readonly ["symbol", "preamble", "startFrameDelimiter", "unalignedFrame", "wrongInterFrameGap", "packetTooShort", "packetTooLong", "CRC", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid"];
416
- import { NoFilter } from 'nofilter';
417
- import type { Readable } from 'node:stream';
@@ -1,24 +0,0 @@
1
- export const SECTION_HEADER: 168627466;
2
- export const INTERFACE_DESCRIPTION: 1;
3
- export const SIMPLE_PACKET: 3;
4
- export const NAME_RESOLUTION: 4;
5
- export const INTERFACE_STATISTICS: 5;
6
- export const ENHANCED_PACKET: 6;
7
- export const DECRYPTION_SECRETS: 10;
8
- export const CUSTOM_COPY: 2989;
9
- export const CUSTOM_NOCOPY: 1073744813;
10
- /**
11
- * @typedef {'ipv4' | 'ipv6' | 'ipv4mask' | 'ipv6prefix' | 'eui' |
12
- * 'u32' | 'u64' | 'timestamp' | 'string' | undefined} OptionType
13
- */
14
- /**
15
- * @typedef {[name: string, typ?: OptionType, pen?: boolean]} OptionDescription
16
- */
17
- /** @typedef {Map<number, OptionDescription>} BlockOpts*/
18
- /**
19
- * @type {Map<number, BlockOpts>}
20
- */
21
- export const OPTION_NAMES: Map<number, BlockOpts>;
22
- export type OptionType = "ipv4" | "ipv6" | "ipv4mask" | "ipv6prefix" | "eui" | "u32" | "u64" | "timestamp" | "string" | undefined;
23
- export type OptionDescription = [name: string, typ?: OptionType, pen?: boolean];
24
- export type BlockOpts = Map<number, OptionDescription>;