@cto.af/pcap-ng-parser 3.0.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.
- package/lib/blocks.mjs +1 -0
- package/lib/events.d.mts +97 -0
- package/lib/events.mjs +1 -0
- package/lib/index.d.mts +119 -0
- package/lib/index.mjs +1 -0
- package/lib/linkTypes.mjs +1 -0
- package/lib/options.d.mts +5 -0
- package/lib/options.mjs +1 -0
- package/lib/utils.mjs +1 -0
- package/package.json +2 -3
- package/src/blocks.ts +0 -89
- package/src/events.ts +0 -182
- package/src/index.ts +0 -931
- package/src/linkTypes.ts +0 -223
- package/src/options.ts +0 -98
- package/src/utils.ts +0 -21
package/lib/blocks.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const sectionHeaderBlock={byteOrderMagic:{read:`u32`},majorVersion:{read:`u16`},minorVersion:{read:`u16`},sectionLength:{read:`i64`}},interfaceDescriptionBlockFormat={linkType:{read:`u16`},reserved:{read:`u16`},snapLen:{read:`u32`}},nameResolutionFormat={recordType:{read:`u16`},recordValueLength:{read:`u16`}},enhancedPacketBlockFormat={interfaceId:{read:`u32`},timestampHigh:{read:`u32`},timestampLow:{read:`u32`},capturedPacketLength:{read:`u32`},originalPacketLength:{read:`u32`}},optionBlock={optionType:{read:`u16`},dataLength:{read:`u16`}},interfaceStatisticsFormat={interfaceId:{read:`u32`},timestampHigh:{read:`u32`},timestampLow:{read:`u32`}},decryptionSecretsFormat={secretsType:{read:`u32`},secretsLength:{read:`u32`}},timestampFormat={timestampHigh:{read:`u32`},timestampLow:{read:`u32`}},pcapHeaderFormat={byteOrderMagic:{read:`u32`},majorVersion:{read:`u16`},minorVersion:{read:`u16`},_reserved1:{read:`u32`},_reserved2:{read:`u32`},snapLen:{read:`u32`},linkType:{read:`u32`}},pcapPacketFormat={timestampHigh:{read:`u32`},timestampLow:{read:`u32`},capturedPacketLength:{read:`u32`},originalPacketLength:{read:`u32`}};export{decryptionSecretsFormat,enhancedPacketBlockFormat,interfaceDescriptionBlockFormat,interfaceStatisticsFormat,nameResolutionFormat,optionBlock,pcapHeaderFormat,pcapPacketFormat,sectionHeaderBlock,timestampFormat};
|
package/lib/events.d.mts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/events.d.ts
|
|
2
|
+
declare const EPB_FLAGS_DIRECTIONS: readonly ["notAvailable", "inbound", "outbound", "invalid"];
|
|
3
|
+
declare const EPB_FLAGS_RECEPTION: readonly ["notSpecified", "unicast", "multicast", "broadcast", "promiscuous", "invalid", "invalid", "invalid"];
|
|
4
|
+
declare const EPB_FLAGS_LINK_LAYER_ERRORS: readonly ["symbol", "preamble", "startFrameDelimiter", "unalignedFrame", "wrongInterFrameGap", "packetTooShort", "packetTooLong", "CRC", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid"];
|
|
5
|
+
interface GenericOption {
|
|
6
|
+
optionType: number;
|
|
7
|
+
dataLength?: number;
|
|
8
|
+
data?: Uint8Array;
|
|
9
|
+
str?: string;
|
|
10
|
+
bigint?: bigint;
|
|
11
|
+
date?: Date;
|
|
12
|
+
name?: string;
|
|
13
|
+
private?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface PrivateEnterpriseNumber {
|
|
16
|
+
pen?: number;
|
|
17
|
+
}
|
|
18
|
+
type Option = GenericOption & PrivateEnterpriseNumber;
|
|
19
|
+
interface PacketFlags {
|
|
20
|
+
direction?: typeof EPB_FLAGS_DIRECTIONS[number];
|
|
21
|
+
reception?: typeof EPB_FLAGS_RECEPTION[number];
|
|
22
|
+
FCSlen?: number;
|
|
23
|
+
noChecksum?: boolean;
|
|
24
|
+
checksumValid?: boolean;
|
|
25
|
+
TCPsegmentationOffload?: boolean;
|
|
26
|
+
linkLayerErrors?: typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][];
|
|
27
|
+
}
|
|
28
|
+
interface Packet {
|
|
29
|
+
interfaceId: number;
|
|
30
|
+
timestamp?: Date;
|
|
31
|
+
flags?: PacketFlags;
|
|
32
|
+
originalPacketLength: number;
|
|
33
|
+
data: Uint8Array;
|
|
34
|
+
options: Option[];
|
|
35
|
+
}
|
|
36
|
+
interface Interface {
|
|
37
|
+
/**
|
|
38
|
+
* @see See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
|
|
39
|
+
*/
|
|
40
|
+
linkType: number;
|
|
41
|
+
linkTypeName?: string;
|
|
42
|
+
snapLen: number;
|
|
43
|
+
name?: string;
|
|
44
|
+
tsoffset: bigint;
|
|
45
|
+
tsresol: bigint;
|
|
46
|
+
options: Option[];
|
|
47
|
+
}
|
|
48
|
+
type Endianess = 'BE' | 'LE';
|
|
49
|
+
interface SectionHeader {
|
|
50
|
+
endianess: Endianess;
|
|
51
|
+
majorVersion: number;
|
|
52
|
+
minorVersion: number;
|
|
53
|
+
sectionLength: bigint;
|
|
54
|
+
options: Option[];
|
|
55
|
+
}
|
|
56
|
+
interface IPv4ResolutionRecord {
|
|
57
|
+
name: 'nrb_record_ipv4';
|
|
58
|
+
ipv4: string;
|
|
59
|
+
entries: string[];
|
|
60
|
+
}
|
|
61
|
+
interface IPv6ResolutionRecord {
|
|
62
|
+
name: 'nrb_record_ipv6';
|
|
63
|
+
ipv6: string;
|
|
64
|
+
entries: string[];
|
|
65
|
+
}
|
|
66
|
+
interface EUI48ResolutionRecord {
|
|
67
|
+
name: 'nrb_record_eui48';
|
|
68
|
+
eui48: string;
|
|
69
|
+
entries: string[];
|
|
70
|
+
}
|
|
71
|
+
interface EUI64ResolutionRecord {
|
|
72
|
+
name: 'nrb_record_eui64';
|
|
73
|
+
eui64: string;
|
|
74
|
+
entries: string[];
|
|
75
|
+
}
|
|
76
|
+
type NameResolutionRecord = IPv4ResolutionRecord | IPv6ResolutionRecord | EUI48ResolutionRecord | EUI64ResolutionRecord;
|
|
77
|
+
interface NameResolution {
|
|
78
|
+
records: NameResolutionRecord[];
|
|
79
|
+
options: Option[];
|
|
80
|
+
}
|
|
81
|
+
interface InterfaceStatistics {
|
|
82
|
+
interfaceId: number;
|
|
83
|
+
timestamp: Date;
|
|
84
|
+
options: Option[];
|
|
85
|
+
}
|
|
86
|
+
interface DecryptionSecrets {
|
|
87
|
+
secretsType: number;
|
|
88
|
+
data: Uint8Array;
|
|
89
|
+
options: Option[];
|
|
90
|
+
}
|
|
91
|
+
interface CustomBlock {
|
|
92
|
+
pen: number;
|
|
93
|
+
data: Uint8Array;
|
|
94
|
+
copy: boolean;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { CustomBlock, DecryptionSecrets, EUI48ResolutionRecord, EUI64ResolutionRecord, Endianess, GenericOption, IPv4ResolutionRecord, IPv6ResolutionRecord, Interface, InterfaceStatistics, NameResolution, NameResolutionRecord, Option, Packet, PacketFlags, PrivateEnterpriseNumber, SectionHeader };
|
package/lib/events.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const EPB_FLAGS_DIRECTIONS=[`notAvailable`,`inbound`,`outbound`,`invalid`],EPB_FLAGS_RECEPTION=[`notSpecified`,`unicast`,`multicast`,`broadcast`,`promiscuous`,`invalid`,`invalid`,`invalid`],EPB_FLAGS_LINK_LAYER_ERRORS=[`symbol`,`preamble`,`startFrameDelimiter`,`unalignedFrame`,`wrongInterFrameGap`,`packetTooShort`,`packetTooLong`,`CRC`,`invalid`,`invalid`,`invalid`,`invalid`,`invalid`,`invalid`,`invalid`,`invalid`];var ErrorEventPolyfill=class extends Event{#eventInit;constructor(type,eventInitDict={}){super(type,eventInitDict),this.#eventInit=eventInitDict}get message(){return this.#eventInit.message??``}get filename(){return this.#eventInit.filename??``}get lineno(){return this.#eventInit.lineno??0}get colno(){return this.#eventInit.colno??0}get error(){return this.#eventInit.error}};const LocalErrorEvent=globalThis.ErrorEvent??ErrorEventPolyfill;export{EPB_FLAGS_DIRECTIONS,EPB_FLAGS_LINK_LAYER_ERRORS,EPB_FLAGS_RECEPTION,LocalErrorEvent};
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { OptionType } from "./options.mjs";
|
|
2
|
+
import { CustomBlock, DecryptionSecrets, EUI48ResolutionRecord, EUI64ResolutionRecord, Endianess, GenericOption, IPv4ResolutionRecord, IPv6ResolutionRecord, Interface, InterfaceStatistics, NameResolution, NameResolutionRecord, Option, Packet, PacketFlags, PrivateEnterpriseNumber, SectionHeader } from "./events.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
type EventCallback<T> = ((evt: T) => void) | {
|
|
6
|
+
handleEvent(evt: T): void;
|
|
7
|
+
} | null;
|
|
8
|
+
/**
|
|
9
|
+
* An error has occured when parsing inside a block. This error can be
|
|
10
|
+
* ignored and parsing can continue within the next block safely.
|
|
11
|
+
*/
|
|
12
|
+
declare class RecoverableError extends Error {
|
|
13
|
+
constructor(err: unknown);
|
|
14
|
+
}
|
|
15
|
+
interface ParseEvents {
|
|
16
|
+
close: Event;
|
|
17
|
+
custom: CustomEvent<CustomBlock>;
|
|
18
|
+
error: ErrorEvent;
|
|
19
|
+
interface: CustomEvent<Interface>;
|
|
20
|
+
names: CustomEvent<NameResolution>;
|
|
21
|
+
data: CustomEvent<Packet>;
|
|
22
|
+
section: CustomEvent<SectionHeader>;
|
|
23
|
+
secrets: CustomEvent<DecryptionSecrets>;
|
|
24
|
+
stats: CustomEvent<InterfaceStatistics>;
|
|
25
|
+
unknown: CustomEvent<number>;
|
|
26
|
+
}
|
|
27
|
+
type ParseEventsDetail<K extends keyof ParseEvents> = ParseEvents[K] extends CustomEvent<infer T> ? T : ParseEvents[K] extends ErrorEvent ? any : void;
|
|
28
|
+
interface ParserOptions {
|
|
29
|
+
/** If true, don't allow old PCAP format. */
|
|
30
|
+
rejectOld?: boolean;
|
|
31
|
+
/** If true, don't allow new PCAPng format. */
|
|
32
|
+
rejectNG?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse a PCAPng or old-style PCAP file from a stream.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```js
|
|
39
|
+
* import fs from 'node:fs/promises';
|
|
40
|
+
* import {PCAPNGParser} from '@cto.af/pcap-ng-parser';
|
|
41
|
+
*
|
|
42
|
+
* const parser = new PCAPNGParser();
|
|
43
|
+
* parser.on('data', pkt => console.log(pkt.data)); // Uint8Array
|
|
44
|
+
* const file = await fs.open('examples/res/myfile.pcapng');
|
|
45
|
+
* file.readableWebStream().pipeTo(parser);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare class PCAPNGParser extends WritableStream<Uint8Array> implements EventTarget {
|
|
49
|
+
#private;
|
|
50
|
+
/**
|
|
51
|
+
* Interface information receieved for the current section, in order of
|
|
52
|
+
* reception.
|
|
53
|
+
*/
|
|
54
|
+
interfaces: Interface[];
|
|
55
|
+
constructor(opts?: ParserOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Is this file in the pcap-ng format?
|
|
58
|
+
*/
|
|
59
|
+
get ng(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Endianness of the current section.
|
|
62
|
+
* Little-endian => LE.
|
|
63
|
+
* Big-endian => BE.
|
|
64
|
+
*/
|
|
65
|
+
get endianess(): Endianess;
|
|
66
|
+
/**
|
|
67
|
+
* The **`addEventListener()`** method of the EventTarget interface sets up
|
|
68
|
+
* a function that will be called whenever the specified event is delivered
|
|
69
|
+
* to the target.
|
|
70
|
+
*
|
|
71
|
+
* @see https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener
|
|
72
|
+
*/
|
|
73
|
+
addEventListener<E extends keyof ParseEvents>(type: E, callback: EventCallback<ParseEvents[E]>, options?: AddEventListenerOptions | boolean): void;
|
|
74
|
+
/**
|
|
75
|
+
* The **`dispatchEvent()`** method of the EventTarget sends an Event to the
|
|
76
|
+
* object, (synchronously) invoking the affected event listeners in the
|
|
77
|
+
* appropriate order.
|
|
78
|
+
*
|
|
79
|
+
* @see https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent
|
|
80
|
+
*/
|
|
81
|
+
dispatchEvent(event: ParseEvents[keyof ParseEvents]): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The **`removeEventListener()`** method of the EventTarget interface
|
|
84
|
+
* removes an event listener previously registered with
|
|
85
|
+
* EventTarget.addEventListener() from the target.
|
|
86
|
+
*
|
|
87
|
+
* @see https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener
|
|
88
|
+
*/
|
|
89
|
+
removeEventListener<E extends keyof ParseEvents>(event: E, calback: EventCallback<ParseEvents[E]>, options?: EventListenerOptions | boolean): void;
|
|
90
|
+
/**
|
|
91
|
+
* Listen for an event, unwrapping the detailor error in the event so that
|
|
92
|
+
* it is easier to process.
|
|
93
|
+
*
|
|
94
|
+
* @param eventName Event name.
|
|
95
|
+
* @param listener Handler.
|
|
96
|
+
* @returns This, for chaining.
|
|
97
|
+
*/
|
|
98
|
+
on<E extends keyof ParseEvents>(eventName: E, listener: (detail: ParseEventsDetail<E>) => void): this;
|
|
99
|
+
/**
|
|
100
|
+
* Listen for the first occurence of a given event. Does the same
|
|
101
|
+
* unwrapping as `on`.
|
|
102
|
+
*
|
|
103
|
+
* @param eventName Event name.
|
|
104
|
+
* @param listener Handler.
|
|
105
|
+
* @returns This, for chaining.
|
|
106
|
+
*/
|
|
107
|
+
once<E extends keyof ParseEvents>(eventName: E, listener: (detail: ParseEventsDetail<E>) => void): this;
|
|
108
|
+
/**
|
|
109
|
+
* Stop listening for the given event.
|
|
110
|
+
*
|
|
111
|
+
* @param eventName Event name.
|
|
112
|
+
* @param listener Handler to remove.
|
|
113
|
+
* @returns This, for chaining.
|
|
114
|
+
* @throws On unknown listener.
|
|
115
|
+
*/
|
|
116
|
+
off<E extends keyof ParseEvents>(eventName: E, listener: (detail: ParseEventsDetail<E>) => void): this;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { type CustomBlock, type DecryptionSecrets, type EUI48ResolutionRecord, type EUI64ResolutionRecord, type Endianess, EventCallback, type GenericOption, type IPv4ResolutionRecord, type IPv6ResolutionRecord, type Interface, type InterfaceStatistics, type NameResolution, type NameResolutionRecord, type Option, type OptionType, PCAPNGParser, PCAPNGParser as default, type Packet, type PacketFlags, ParseEvents, ParseEventsDetail, ParserOptions, type PrivateEnterpriseNumber, RecoverableError, type SectionHeader };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{decryptionSecretsFormat,enhancedPacketBlockFormat,interfaceDescriptionBlockFormat,interfaceStatisticsFormat,nameResolutionFormat,optionBlock,pcapHeaderFormat,pcapPacketFormat,sectionHeaderBlock,timestampFormat}from"./blocks.mjs";import{CUSTOM_COPY,CUSTOM_NOCOPY,DECRYPTION_SECRETS,ENHANCED_PACKET,INTERFACE_DESCRIPTION,INTERFACE_STATISTICS,NAME_RESOLUTION,OPTION_NAMES,SECTION_HEADER,SIMPLE_PACKET}from"./options.mjs";import{EPB_FLAGS_DIRECTIONS,EPB_FLAGS_LINK_LAYER_ERRORS,EPB_FLAGS_RECEPTION,LocalErrorEvent}from"./events.mjs";import{colons,pad4}from"./utils.mjs";import{LINK_TYPE_NAMES}from"./linkTypes.mjs";import{DataViewReader,DataViewWritableStream,TruncationError}from"dataview-stream";import{assert}from"@cto.af/utils";import{decode}from"@leichtgewicht/ip-codec";const TD=new TextDecoder;var RecoverableError=class extends Error{constructor(err){super(err instanceof Error?err.message:`Recoverable Error`,{cause:err})}},PCAPNGParser=class extends WritableStream{interfaces=[];#listeners=new WeakMap;#et=new EventTarget;#dv;#ng=!0;#opts;constructor(opts={}){let dv=new DataViewWritableStream,writer=dv.getWriter(),self;super({write(chunk){return writer.write(chunk)},async abort(reason){await writer.abort(reason),self?.dispatchEvent(new LocalErrorEvent(`error`,{error:reason}))},async close(){await writer.close()}}),self=this,this.#opts={rejectOld:!1,rejectNG:!1,...opts},this.#dv=dv,this.#readFile()}get ng(){return this.#ng}get endianess(){return this.#dv.littleEndian?`LE`:`BE`}addEventListener(type,callback,options){this.#et.addEventListener(type,callback,options)}dispatchEvent(event){return this.#et.dispatchEvent(event)}removeEventListener(type,callback,options){this.#et.removeEventListener(type,callback,options)}on(eventName,listener){let wrapper=ev=>{eventName===`close`&&listener(),ev instanceof CustomEvent?listener(ev.detail):ev instanceof LocalErrorEvent&&listener(ev.error)};return this.#listeners.set(listener,wrapper),this.addEventListener(eventName,wrapper),this}once(eventName,listener){let wrapper=ev=>{this.#listeners.delete(listener),eventName===`close`&&listener(),ev instanceof CustomEvent?listener(ev.detail):ev instanceof LocalErrorEvent&&listener(ev.error)};return this.#listeners.set(listener,wrapper),this.addEventListener(eventName,wrapper,{once:!0}),this}off(eventName,listener){let wrapper=this.#listeners.get(listener);if(!wrapper)throw Error(`Unknown listener`);return this.removeEventListener(eventName,wrapper),this.#listeners.delete(listener),this}#timestamp(stampHigh,stampLow,interfaceId){let stamp=BigInt(stampHigh)<<32n|BigInt(stampLow),int=this.interfaces[interfaceId];assert(int,`Interface always checked before calling`);let off=int.tsoffset+stamp/int.tsresol;return new Date(Number(off))}#dvr(bytes){return new DataViewReader(bytes,{littleEndian:this.#dv.littleEndian})}async#readFile(){try{let magicBuf=await this.#dv.peek(8),magic=this.#dvr(magicBuf).u32();if(magic===SECTION_HEADER)await this.#readSections();else if(magic===2712847316)await this.#readPCAP(!1,!1);else if(magic===3569595041)await this.#readPCAP(!0,!1);else if(magic===2712812621)await this.#readPCAP(!1,!0);else if(magic===1295823521)await this.#readPCAP(!0,!0);else throw Error(`Invalid file format: magic = ${magic}`)}catch(error){this.dispatchEvent(new LocalErrorEvent(`error`,{error}))}this.dispatchEvent(new Event(`close`))}async#readPCAP(littleEndian,nano){if(this.#opts.rejectOld)throw Error(`Old PCAP format detected and rejected`);littleEndian&&(this.#dv.littleEndian=!this.#dv.littleEndian),this.#ng=!1;let{linkType,snapLen}=await this.#dv.struct(pcapHeaderFormat),tsresol=nano?1000000n:1000n,int={linkType:linkType&65535,snapLen,tsresol,tsoffset:0n,options:[]},ltName=LINK_TYPE_NAMES.get(int.linkType);if(ltName&&(int.linkTypeName=ltName),linkType&67108864){let FCSlen=linkType>>28;int.options.push({optionType:13,name:`if_fcslen`,data:new Uint8Array([FCSlen*16])})}for(this.interfaces.push(int),this.dispatchEvent(new CustomEvent(`interface`,{detail:int}));;){try{await this.#dv.waitFor(4)}catch(er){if(er instanceof TruncationError&&er.requested===4)return;throw er}let{timestampHigh,timestampLow,capturedPacketLength,originalPacketLength}=await this.#dv.struct(pcapPacketFormat),data=await this.#dv.bytes(capturedPacketLength),pkt={interfaceId:0,timestamp:new Date(timestampHigh*1e3+timestampLow/Number(tsresol)),originalPacketLength,data,options:[]};this.dispatchEvent(new CustomEvent(`data`,{detail:pkt}))}}async#readSections(){if(this.#opts.rejectNG)throw Error(`PCAPng format detected and rejected`);for(;;){let block=await this.#readBlock();if(!block)break;try{switch(block.blockType){case SECTION_HEADER:await this.#processSectionHeader(block);break;case INTERFACE_DESCRIPTION:await this.#processInterface(block);break;case SIMPLE_PACKET:await this.#processSimplePacket(block);break;case NAME_RESOLUTION:await this.#processNameResolution(block);break;case INTERFACE_STATISTICS:await this.#processInterfaceStatistics(block);break;case ENHANCED_PACKET:await this.#processEnhancedPacket(block);break;case DECRYPTION_SECRETS:await this.#processDecryptionSecrets(block);break;case CUSTOM_COPY:case CUSTOM_NOCOPY:await this.#processCustom(block);break;default:this.dispatchEvent(new CustomEvent(`unknown`,{detail:block.blockType}));break}}catch(error){this.dispatchEvent(new LocalErrorEvent(`error`,{error:new RecoverableError(error)}))}}}async#readBlock(){let blockType;try{blockType=await this.#dv.u32()}catch(er){assert(er instanceof TruncationError),assert(er.requested===4);return}if(blockType===SECTION_HEADER){let prelude=await this.#dv.peek(8),dv=this.#dvr(prelude);dv.skip(4);let bom=dv.u32();if(bom!==439041101)if(bom===1295788826)this.#dv.littleEndian=!this.#dv.littleEndian;else throw Error(`Unable to determine endian from 0x${bom.toString(16)}`)}let blockTotalLength=await this.#dv.u32(),dataLen=blockTotalLength-12,data=await this.#dv.bytes(dataLen),block={blockType,blockTotalLength,data:this.#dvr(data)};await this.#dv.bytes(pad4(dataLen));let endTotalLength=await this.#dv.u32();if(endTotalLength!==blockTotalLength)throw Error(`Length mismatch, ${endTotalLength} != ${blockTotalLength}`);return block}#readOptions(block,interfaceId){let foundEndOption=!1,options=[];for(;!block.data.finished&&!foundEndOption;){let rb=block.data.struct(optionBlock);if(rb.optionType===0)foundEndOption=!0;else{let pen,name,optLen=rb.dataLength,typ,desc=OPTION_NAMES.get(block.blockType)?.get(rb.optionType);desc&&(name={name:desc[0]},typ=desc[1],desc[2]&&(pen={pen:block.data.u32()},optLen-=4));let opt={optionType:rb.optionType,...name,...pen};switch(rb.optionType&32768&&(opt.private=!0),typ){case`string`:{let left=block.data.bytes(optLen);opt.str=TD.decode(left).replaceAll(`\0`,``).trim();break}case`ipv4`:case`ipv6`:opt.str=decode(block.data.bytes(rb.dataLength));break;case`ipv4mask`:if(rb.dataLength!==8)throw Error(`Invalid ipv4mask option`);opt.str=`${decode(block.data.bytes(4))}/${decode(block.data.bytes(4))}`;break;case`ipv6prefix`:if(rb.dataLength!==17)throw Error(`Invalid ipv6prefix option`);opt.str=`${decode(block.data.bytes(16))}/${block.data.u8()}`;break;case`eui`:opt.str=colons(block.data.bytes(rb.dataLength));break;case`u32`:opt.bigint=BigInt(block.data.u32());break;case`u64`:opt.bigint=block.data.u64();break;case`timestamp`:{let{timestampHigh,timestampLow}=block.data.struct(timestampFormat);opt.date=this.#timestamp(timestampHigh,timestampLow,interfaceId);break}default:opt.data=block.data.bytes(rb.dataLength);break}block.data.skip(pad4(rb.dataLength)),options.push(opt)}}return options}#processSectionHeader(block){let detail={...block.data.struct(sectionHeaderBlock),endianess:this.endianess,options:this.#readOptions(block)};this.interfaces=[],this.dispatchEvent(new CustomEvent(`section`,{detail}))}#processInterface(block){let idRes=block.data.struct(interfaceDescriptionBlockFormat),iData={linkType:idRes.linkType,snapLen:idRes.snapLen,tsoffset:0n,tsresol:1000n,options:this.#readOptions(block)};for(let opt of iData.options)switch(opt.optionType){case 2:iData.name=opt.str;break;case 14:iData.tsoffset=opt.bigint*1000n;break;case 9:{let tsresol=opt.data[0];tsresol&128?iData.tsresol=(1n<<BigInt(tsresol&127))/1000n:iData.tsresol=10n**(BigInt(tsresol)-3n);break}}this.interfaces.push(iData),this.dispatchEvent(new CustomEvent(`interface`,{detail:iData}))}#processSimplePacket(block){let[int]=this.interfaces;if(!int)throw Error(`No interface for simple packet`);let originalPacketLength=block.data.u32(),len=Math.min(originalPacketLength,int.snapLen),pkt={interfaceId:0,originalPacketLength,data:block.data.bytes(len),options:[]};this.dispatchEvent(new CustomEvent(`data`,{detail:pkt}))}#processNameResolution(block){let res={records:[],options:[]};for(;;){let{recordType,recordValueLength}=block.data.struct(nameResolutionFormat);if(recordType===0)break;let val=block.data.bytes(recordValueLength);switch(block.data.skip(pad4(recordValueLength)),recordType){case 1:if(recordValueLength<6)throw Error(`Invalid nrb_record_ipv4 record`);res.records.push({name:`nrb_record_ipv4`,ipv4:decode(val.subarray(0,4)),entries:TD.decode(val.subarray(4)).split(`\0`).slice(0,-1)});break;case 2:if(recordValueLength<18)throw Error(`Invalid nrb_record_ipv6 record`);res.records.push({name:`nrb_record_ipv6`,ipv6:decode(val.subarray(0,16)),entries:TD.decode(val.subarray(16)).split(`\0`).slice(0,-1)});break;case 3:if(recordValueLength<8)throw Error(`Invalid nrb_record_eui48 record`);res.records.push({name:`nrb_record_eui48`,eui48:colons(val.subarray(0,6)),entries:TD.decode(val.subarray(6)).split(`\0`).slice(0,-1)});break;case 4:if(recordValueLength<10)throw Error(`Invalid nrb_record_eui64 record`);res.records.push({name:`nrb_record_eui64`,eui64:colons(val.subarray(0,8)),entries:TD.decode(val.subarray(8)).split(`\0`).slice(0,-1)});break}}res.options=this.#readOptions(block),this.dispatchEvent(new CustomEvent(`names`,{detail:res}))}#processInterfaceStatistics(block){let{interfaceId,timestampHigh,timestampLow}=block.data.struct(interfaceStatisticsFormat);if(interfaceId>=this.interfaces.length)throw Error(`Invalid interface id: ${interfaceId}`);let stats={interfaceId,timestamp:this.#timestamp(timestampHigh,timestampLow,interfaceId),options:this.#readOptions(block,interfaceId)};this.dispatchEvent(new CustomEvent(`stats`,{detail:stats}))}#processEnhancedPacket(block){let{interfaceId,timestampHigh,timestampLow,capturedPacketLength,originalPacketLength}=block.data.struct(enhancedPacketBlockFormat);if(interfaceId>=this.interfaces.length)throw Error(`Invalid interface ID: ${interfaceId} >= ${this.interfaces.length}`);let data=block.data.bytes(capturedPacketLength),pkt={interfaceId,timestamp:this.#timestamp(timestampHigh,timestampLow,interfaceId),originalPacketLength,data,options:[]};block.data.skip(pad4(capturedPacketLength)),pkt.options=this.#readOptions(block,interfaceId);for(let o of pkt.options)if(o.optionType===2){assert(o.data);let flags=this.#dvr(o.data).u32();pkt.flags={direction:EPB_FLAGS_DIRECTIONS[flags&3],reception:EPB_FLAGS_RECEPTION[flags>>2&7],FCSlen:flags>>5&15,noChecksum:!!(flags>>9&1),checksumValid:!!(flags>>10&1),TCPsegmentationOffload:!!(flags>>11&1),linkLayerErrors:[]},flags>>=16;for(let i=0;i<8;i++)flags&1&&pkt.flags.linkLayerErrors?.push(EPB_FLAGS_LINK_LAYER_ERRORS[i]),flags>>=1}this.dispatchEvent(new CustomEvent(`data`,{detail:pkt}))}#processDecryptionSecrets(block){let{secretsType,secretsLength}=block.data.struct(decryptionSecretsFormat),detail={secretsType,data:block.data.bytes(secretsLength),options:[]};block.data.skip(pad4(secretsLength)),detail.options=this.#readOptions(block),this.dispatchEvent(new CustomEvent(`secrets`,{detail}))}#processCustom(block){let detail={pen:block.data.u32(),data:block.data.unused(),copy:block.blockType===CUSTOM_COPY};this.dispatchEvent(new CustomEvent(`custom`,{detail}))}},src_default=PCAPNGParser;export{PCAPNGParser,RecoverableError,src_default as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const LINK_TYPE_NAMES=new Map([[0,`NULL`],[1,`ETHERNET`],[2,`EXP_ETHERNET`],[3,`AX25`],[4,`PRONET`],[5,`CHAOS`],[6,`IEEE802_5`],[7,`ARCNET_BSD`],[8,`SLIP`],[9,`PPP`],[10,`FDDI`],[50,`PPP_HDLC`],[51,`PPP_ETHER`],[99,`SYMANTEC_FIREWALL`],[100,`ATM_RFC1483`],[101,`RAW`],[102,`SLIP_BSDOS`],[103,`PPP_BSDOS`],[104,`C_HDLC`],[105,`IEEE802_11`],[106,`ATM_CLIP`],[107,`FRELAY`],[108,`LOOP`],[109,`ENC`],[110,`LANE8023`],[111,`HIPPI`],[112,`HDLC`],[113,`LINUX_SLL`],[114,`LTALK`],[115,`ECONET`],[116,`IPFILTER`],[117,`PFLOG`],[118,`CISCO_IOS`],[119,`IEEE802_11_PRISM`],[120,`IEEE802_11_AIRONET`],[121,`HHDLC`],[122,`IP_OVER_FC`],[123,`SUNATM`],[124,`RIO`],[125,`PCI_EXP`],[126,`AURORA`],[127,`IEEE802_11_RADIOTAP`],[128,`TZSP`],[129,`ARCNET_LINUX`],[130,`JUNIPER_MLPPP`],[131,`JUNIPER_MLFR`],[132,`JUNIPER_ES`],[133,`JUNIPER_GGSN`],[134,`JUNIPER_MFR`],[135,`JUNIPER_ATM2`],[136,`JUNIPER_SERVICES`],[137,`JUNIPER_ATM1`],[138,`APPLE_IP_OVER_IEEE1394`],[139,`MTP2_WITH_PHDR`],[140,`MTP2`],[141,`MTP3`],[142,`SCCP`],[143,`DOCSIS`],[144,`LINUX_IRDA`],[145,`IBM_SP`],[146,`IBM_SN`],[147,`RESERVED_01`],[148,`RESERVED_02`],[149,`RESERVED_03`],[150,`RESERVED_04`],[151,`RESERVED_05`],[152,`RESERVED_06`],[153,`RESERVED_07`],[154,`RESERVED_08`],[155,`RESERVED_09`],[156,`RESERVED_10`],[157,`RESERVED_11`],[158,`RESERVED_12`],[159,`RESERVED_13`],[160,`RESERVED_14`],[161,`RESERVED_15`],[162,`RESERVED_16`],[163,`IEEE802_11_AVS`],[164,`JUNIPER_MONITOR`],[165,`BACNET_MS_TP`],[166,`PPP_PPPD`],[167,`JUNIPER_PPPOE`],[168,`JUNIPER_PPPOE_ATM`],[169,`GPRS_LLC`],[170,`GPF_T`],[171,`GPF_F`],[172,`GCOM_T1E1`],[173,`GCOM_SERIAL`],[174,`JUNIPER_PIC_PEER`],[175,`ERF_ETH`],[176,`ERF_POS`],[177,`LINUX_LAPD`],[178,`JUNIPER_ETHER`],[179,`JUNIPER_PPP`],[180,`JUNIPER_FRELAY`],[181,`JUNIPER_CHDLC`],[182,`MFR`],[183,`JUNIPER_VP`],[184,`A429`],[185,`A653_ICM`],[186,`USB_FREEBSD`],[187,`BLUETOOTH_HCI_H4`],[188,`IEEE802_16_MAC_CPS`],[189,`USB_LINUX`],[190,`CAN20B`],[191,`IEEE802_15_4_LINUX`],[192,`PPI`],[193,`IEEE802_16_MAC_CPS_RADIO`],[194,`JUNIPER_ISM`],[195,`IEEE802_15_4_WITHFCS`],[196,`SITA`],[197,`ERF`],[198,`RAIF1`],[199,`IPMB_KONTRON`],[200,`JUNIPER_ST`],[201,`BLUETOOTH_HCI_H4_WITH_PHDR`],[202,`AX25_KISS`],[203,`LAPD`],[204,`PPP_WITH_DIR`],[205,`C_HDLC_WITH_DIR`],[206,`FRELAY_WITH_DIR`],[207,`LAPB_WITH_DIR`],[208,`WillBarker-Proprietary`],[209,`I2C_LINUX`],[210,`FLEXRAY`],[211,`MOST`],[212,`LIN`],[213,`X2E_SERIAL`],[214,`X2E_XORAYA`],[215,`IEEE802_15_4_NONASK_PHY`],[216,`LINUX_EVDEV`],[217,`GSMTAP_UM`],[218,`GSMTAP_ABIS`],[219,`MPLS`],[220,`USB_LINUX_MMAPPED`],[221,`DECT`],[222,`AOS`],[223,`WIHART`],[224,`FC_2`],[225,`FC_2_WITH_FRAME_DELIMS`],[226,`IPNET`],[227,`CAN_SOCKETCAN`],[228,`IPV4`],[229,`IPV6`],[230,`IEEE802_15_4_NOFCS`],[231,`DBUS`],[232,`JUNIPER_VS`],[233,`JUNIPER_SRX_E2E`],[234,`JUNIPER_FIBRECHANNEL`],[235,`DVB_CI`],[236,`MUX27010`],[237,`STANAG_5066_D_PDU`],[238,`JUNIPER_ATM_CEMIC`],[239,`NFLOG`],[240,`NETANALYZER`],[241,`NETANALYZER_TRANSPARENT`],[242,`IPOIB`],[243,`MPEG_2_TS`],[244,`NG40`],[245,`NFC_LLCP`],[246,`PFSYNC`],[247,`INFINIBAND`],[248,`SCTP`],[249,`USBPCAP`],[250,`RTAC_SERIAL`],[251,`BLUETOOTH_LE_LL`],[252,`WIRESHARK_UPPER_PDU`],[253,`NETLINK`],[254,`BLUETOOTH_LINUX_MONITOR`],[255,`BLUETOOTH_BREDR_BB`],[256,`BLUETOOTH_LE_LL_WITH_PHDR`],[257,`PROFIBUS_DL`],[258,`PKTAP`],[259,`EPON`],[260,`IPMI_HPM_2`],[261,`ZWAVE_R1_R2`],[262,`ZWAVE_R3`],[263,`WATTSTOPPER_DLM`],[264,`ISO_14443`],[265,`RDS`],[266,`USB_DARWIN`],[267,`OPENFLOW`],[268,`SDLC`],[269,`TI_LLN_SNIFFER`],[270,`LORATAP`],[271,`VSOCK`],[272,`NORDIC_BLE`],[273,`DOCSIS31_XRA31`],[274,`ETHERNET_MPACKET`],[275,`DISPLAYPORT_AUX`],[276,`LINUX_SLL2`],[277,`SERCOS_MONITOR`],[278,`OPENVIZSLA`],[279,`EBHSCR`],[280,`VPP_DISPATCH`],[281,`DSA_TAG_BRCM`],[282,`DSA_TAG_BRCM_PREPEND`],[283,`IEEE802_15_4_TAP`],[284,`DSA_TAG_DSA`],[285,`DSA_TAG_EDSA`],[286,`ELEE`],[287,`Z_WAVE_SERIAL`],[288,`USB_2_0`],[289,`ATSC_ALP`],[290,`ETW`],[291,`NETANALYZER_NG`],[292,`ZBOSS_NCP`],[293,`USB_2_0_LOW_SPEED`],[294,`USB_2_0_FULL_SPEED`],[295,`USB_2_0_HIGH_SPEED`],[296,`AUERSWALD_LOG`],[297,`ZWAVE_TAP`],[298,`SILABS_DEBUG_CHANNEL`],[299,`FIRA_UCI`],[300,`MDB`],[301,`DECT_NR`]]);export{LINK_TYPE_NAMES};
|
package/lib/options.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const SECTION_HEADER=168627466,INTERFACE_DESCRIPTION=1,SIMPLE_PACKET=3,NAME_RESOLUTION=4,INTERFACE_STATISTICS=5,ENHANCED_PACKET=6,DECRYPTION_SECRETS=10,CUSTOM_COPY=2989,CUSTOM_NOCOPY=1073744813,OPTION_NAMES=new Map([[SECTION_HEADER,new Map([[1,[`opt_comment`,`string`]],[2,[`shb_hardware`,`string`]],[3,[`shb_os`,`string`]],[4,[`shb_userappl`,`string`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])],[1,new Map([[1,[`opt_comment`,`string`]],[2,[`if_name`,`string`]],[3,[`if_description`,`string`]],[4,[`if_IPv4addr`,`ipv4mask`]],[5,[`if_IPv6addr`,`ipv6prefix`]],[6,[`if_MACaddr`,`eui`]],[7,[`if_EUIaddr`,`eui`]],[8,[`if_speed`]],[9,[`if_tsresol`]],[10,[`if_tzone`]],[11,[`if_filter`]],[12,[`if_os`,`string`]],[13,[`if_fcslen`]],[14,[`if_tsoffset`,`u64`]],[15,[`if_hardware`,`string`]],[16,[`if_txspeed`,`u64`]],[17,[`if_rxspeed`,`u64`]],[18,[`if_iana_tzname`,`string`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])],[4,new Map([[1,[`opt_comment`,`string`]],[2,[`ns_dnsname`,`string`]],[3,[`ns_dnsIP4addr`,`ipv4`]],[4,[`ns_dnsIP6addr`,`ipv6`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])],[5,new Map([[1,[`opt_comment`,`string`]],[2,[`isb_starttime`,`timestamp`]],[3,[`isb_endtime`,`timestamp`]],[4,[`isb_ifrecv`,`u64`]],[5,[`isb_ifdrop`,`u64`]],[6,[`isb_filteraccept`,`u64`]],[7,[`isb_osdrop`,`u64`]],[8,[`isb_usrdeliv`,`u64`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])],[6,new Map([[1,[`opt_comment`,`string`]],[2,[`epb_flags`]],[3,[`epb_hash`]],[4,[`epb_dropcount`,`u64`]],[5,[`epb_packetid`,`u64`]],[6,[`epb_queue`,`u32`]],[7,[`epb_verdict`]],[8,[`epb_processid_threadid`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])],[10,new Map([[1,[`opt_comment`,`string`]],[2988,[`opt_custom`,`string`,!0]],[2989,[`opt_custom`,void 0,!0]],[19372,[`opt_custom`,`string`,!0]],[19373,[`opt_custom`,void 0,!0]]])]]);export{CUSTOM_COPY,CUSTOM_NOCOPY,DECRYPTION_SECRETS,ENHANCED_PACKET,INTERFACE_DESCRIPTION,INTERFACE_STATISTICS,NAME_RESOLUTION,OPTION_NAMES,SECTION_HEADER,SIMPLE_PACKET};
|
package/lib/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function pad4(n){return Math.ceil(n/4)*4-n}function colons(buf){return Array.from(buf).map(x=>x.toString(16).padStart(2,`0`)).join(`:`)}export{colons,pad4};
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/pcap-ng-parser",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Node.js Module for parsing .pcapng files and tcpdump output.",
|
|
5
5
|
"main": "./lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"types",
|
|
8
|
+
"lib",
|
|
10
9
|
"docs/LICENSE.md"
|
|
11
10
|
],
|
|
12
11
|
"repository": {
|
package/src/blocks.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see documentation at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-section-header-block
|
|
3
|
-
*/
|
|
4
|
-
export const sectionHeaderBlock = {
|
|
5
|
-
byteOrderMagic: {read: 'u32'},
|
|
6
|
-
majorVersion: {read: 'u16'},
|
|
7
|
-
minorVersion: {read: 'u16'},
|
|
8
|
-
sectionLength: {read: 'i64'},
|
|
9
|
-
} as const;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
|
|
13
|
-
*/
|
|
14
|
-
export const blockType = {
|
|
15
|
-
blockType: {read: 'i32'},
|
|
16
|
-
} as const;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-interface-description-block
|
|
20
|
-
*/
|
|
21
|
-
export const interfaceDescriptionBlockFormat = {
|
|
22
|
-
linkType: {read: 'u16'},
|
|
23
|
-
reserved: {read: 'u16'},
|
|
24
|
-
snapLen: {read: 'u32'},
|
|
25
|
-
} as const;
|
|
26
|
-
|
|
27
|
-
export const nameResolutionFormat = {
|
|
28
|
-
recordType: {read: 'u16'},
|
|
29
|
-
recordValueLength: {read: 'u16'},
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
|
|
34
|
-
*/
|
|
35
|
-
export const enhancedPacketBlockFormat = {
|
|
36
|
-
interfaceId: {read: 'u32'},
|
|
37
|
-
timestampHigh: {read: 'u32'},
|
|
38
|
-
timestampLow: {read: 'u32'},
|
|
39
|
-
capturedPacketLength: {read: 'u32'},
|
|
40
|
-
originalPacketLength: {read: 'u32'},
|
|
41
|
-
|
|
42
|
-
/* Packet Data */
|
|
43
|
-
/* Options */
|
|
44
|
-
} as const;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-options
|
|
48
|
-
*/
|
|
49
|
-
export const optionBlock = {
|
|
50
|
-
optionType: {read: 'u16'},
|
|
51
|
-
dataLength: {read: 'u16'},
|
|
52
|
-
} as const;
|
|
53
|
-
|
|
54
|
-
export const interfaceStatisticsFormat = {
|
|
55
|
-
interfaceId: {read: 'u32'},
|
|
56
|
-
timestampHigh: {read: 'u32'},
|
|
57
|
-
timestampLow: {read: 'u32'},
|
|
58
|
-
} as const;
|
|
59
|
-
|
|
60
|
-
export const decryptionSecretsFormat = {
|
|
61
|
-
secretsType: {read: 'u32'},
|
|
62
|
-
secretsLength: {read: 'u32'},
|
|
63
|
-
} as const;
|
|
64
|
-
|
|
65
|
-
export const ifTsOffsetFormat = {
|
|
66
|
-
tsoffset: {size: 8, sign: true},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const timestampFormat = {
|
|
70
|
-
timestampHigh: {read: 'u32'},
|
|
71
|
-
timestampLow: {read: 'u32'},
|
|
72
|
-
} as const;
|
|
73
|
-
|
|
74
|
-
export const pcapHeaderFormat = {
|
|
75
|
-
byteOrderMagic: {read: 'u32'},
|
|
76
|
-
majorVersion: {read: 'u16'},
|
|
77
|
-
minorVersion: {read: 'u16'},
|
|
78
|
-
_reserved1: {read: 'u32'},
|
|
79
|
-
_reserved2: {read: 'u32'},
|
|
80
|
-
snapLen: {read: 'u32'},
|
|
81
|
-
linkType: {read: 'u32'},
|
|
82
|
-
} as const;
|
|
83
|
-
|
|
84
|
-
export const pcapPacketFormat = {
|
|
85
|
-
timestampHigh: {read: 'u32'},
|
|
86
|
-
timestampLow: {read: 'u32'},
|
|
87
|
-
capturedPacketLength: {read: 'u32'},
|
|
88
|
-
originalPacketLength: {read: 'u32'},
|
|
89
|
-
} as const;
|
package/src/events.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
export const EPB_FLAGS_DIRECTIONS = [
|
|
2
|
-
'notAvailable',
|
|
3
|
-
'inbound',
|
|
4
|
-
'outbound',
|
|
5
|
-
'invalid',
|
|
6
|
-
] as const;
|
|
7
|
-
|
|
8
|
-
export const EPB_FLAGS_RECEPTION = [
|
|
9
|
-
'notSpecified',
|
|
10
|
-
'unicast',
|
|
11
|
-
'multicast',
|
|
12
|
-
'broadcast',
|
|
13
|
-
'promiscuous',
|
|
14
|
-
'invalid',
|
|
15
|
-
'invalid',
|
|
16
|
-
'invalid',
|
|
17
|
-
] as const;
|
|
18
|
-
|
|
19
|
-
export const EPB_FLAGS_LINK_LAYER_ERRORS = [
|
|
20
|
-
'symbol',
|
|
21
|
-
'preamble',
|
|
22
|
-
'startFrameDelimiter',
|
|
23
|
-
'unalignedFrame',
|
|
24
|
-
'wrongInterFrameGap',
|
|
25
|
-
'packetTooShort',
|
|
26
|
-
'packetTooLong',
|
|
27
|
-
'CRC',
|
|
28
|
-
'invalid',
|
|
29
|
-
'invalid',
|
|
30
|
-
'invalid',
|
|
31
|
-
'invalid',
|
|
32
|
-
'invalid',
|
|
33
|
-
'invalid',
|
|
34
|
-
'invalid',
|
|
35
|
-
'invalid',
|
|
36
|
-
] as const;
|
|
37
|
-
|
|
38
|
-
export interface GenericOption {
|
|
39
|
-
optionType: number;
|
|
40
|
-
dataLength?: number;
|
|
41
|
-
data?: Uint8Array;
|
|
42
|
-
str?: string;
|
|
43
|
-
bigint?: bigint;
|
|
44
|
-
date?: Date;
|
|
45
|
-
name?: string;
|
|
46
|
-
private?: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface PrivateEnterpriseNumber {
|
|
50
|
-
pen?: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type Option = GenericOption & PrivateEnterpriseNumber;
|
|
54
|
-
|
|
55
|
-
export interface PacketFlags {
|
|
56
|
-
direction?: typeof EPB_FLAGS_DIRECTIONS[number];
|
|
57
|
-
reception?: typeof EPB_FLAGS_RECEPTION[number];
|
|
58
|
-
FCSlen?: number;
|
|
59
|
-
noChecksum?: boolean;
|
|
60
|
-
checksumValid?: boolean;
|
|
61
|
-
TCPsegmentationOffload?: boolean;
|
|
62
|
-
linkLayerErrors?: typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface Packet {
|
|
66
|
-
interfaceId: number;
|
|
67
|
-
timestamp?: Date; // To be replaced with Temporal.Instant one day.
|
|
68
|
-
flags?: PacketFlags;
|
|
69
|
-
originalPacketLength: number;
|
|
70
|
-
data: Uint8Array;
|
|
71
|
-
options: Option[];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface Interface {
|
|
75
|
-
/**
|
|
76
|
-
* @see See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
|
|
77
|
-
*/
|
|
78
|
-
linkType: number;
|
|
79
|
-
linkTypeName?: string;
|
|
80
|
-
snapLen: number;
|
|
81
|
-
name?: string;
|
|
82
|
-
tsoffset: bigint; // Offset, in MS, applied to each timestamp.
|
|
83
|
-
tsresol: bigint; // Timestamp resolution in MS.
|
|
84
|
-
options: Option[];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type Endianess = 'BE' | 'LE';
|
|
88
|
-
|
|
89
|
-
export interface SectionHeader {
|
|
90
|
-
endianess: Endianess;
|
|
91
|
-
majorVersion: number;
|
|
92
|
-
minorVersion: number;
|
|
93
|
-
sectionLength: bigint;
|
|
94
|
-
options: Option[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface IPv4ResolutionRecord {
|
|
98
|
-
name: 'nrb_record_ipv4';
|
|
99
|
-
ipv4: string;
|
|
100
|
-
entries: string[];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface IPv6ResolutionRecord {
|
|
104
|
-
name: 'nrb_record_ipv6';
|
|
105
|
-
ipv6: string;
|
|
106
|
-
entries: string[];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface EUI48ResolutionRecord {
|
|
110
|
-
name: 'nrb_record_eui48';
|
|
111
|
-
eui48: string;
|
|
112
|
-
entries: string[];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface EUI64ResolutionRecord {
|
|
116
|
-
name: 'nrb_record_eui64';
|
|
117
|
-
eui64: string;
|
|
118
|
-
entries: string[];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export type NameResolutionRecord =
|
|
122
|
-
IPv4ResolutionRecord | IPv6ResolutionRecord |
|
|
123
|
-
EUI48ResolutionRecord | EUI64ResolutionRecord;
|
|
124
|
-
|
|
125
|
-
export interface NameResolution {
|
|
126
|
-
records: NameResolutionRecord[];
|
|
127
|
-
options: Option[];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface InterfaceStatistics {
|
|
131
|
-
interfaceId: number;
|
|
132
|
-
timestamp: Date;
|
|
133
|
-
options: Option[];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface DecryptionSecrets {
|
|
137
|
-
secretsType: number;
|
|
138
|
-
data: Uint8Array;
|
|
139
|
-
options: Option[];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface CustomBlock {
|
|
143
|
-
pen: number;
|
|
144
|
-
data: Uint8Array;
|
|
145
|
-
copy: boolean;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Needed before node 25.0.0.
|
|
149
|
-
export class ErrorEventPolyfill extends Event implements ErrorEvent {
|
|
150
|
-
#eventInit;
|
|
151
|
-
|
|
152
|
-
public constructor(type: string, eventInitDict: ErrorEventInit = {}) {
|
|
153
|
-
super(type, eventInitDict);
|
|
154
|
-
this.#eventInit = eventInitDict;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public get message(): string {
|
|
158
|
-
return this.#eventInit.message ?? '';
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public get filename(): string {
|
|
162
|
-
return this.#eventInit.filename ?? '';
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public get lineno(): number {
|
|
166
|
-
return this.#eventInit.lineno ?? 0;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public get colno(): number {
|
|
170
|
-
return this.#eventInit.colno ?? 0;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
public get error(): any {
|
|
174
|
-
return this.#eventInit.error;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const LocalErrorEvent = globalThis.ErrorEvent ?? ErrorEventPolyfill;
|
|
179
|
-
|
|
180
|
-
export {
|
|
181
|
-
LocalErrorEvent as ErrorEvent,
|
|
182
|
-
};
|