@cto.af/pcap-ng-parser 2.1.0 → 3.0.1

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