@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.
@@ -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
+ ]);
@@ -8,21 +8,14 @@ export const DECRYPTION_SECRETS = 0xA;
8
8
  export const CUSTOM_COPY = 0x00000BAD;
9
9
  export const CUSTOM_NOCOPY = 0x40000BAD;
10
10
 
11
- /**
12
- * @typedef {'ipv4' | 'ipv6' | 'ipv4mask' | 'ipv6prefix' | 'eui' |
13
- * 'u32' | 'u64' | 'timestamp' | 'string' | undefined} OptionType
14
- */
11
+ export type OptionType = 'ipv4' | 'ipv6' | 'ipv4mask' | 'ipv6prefix' | 'eui' |
12
+ 'u32' | 'u64' | 'timestamp' | 'string' | undefined;
15
13
 
16
- /**
17
- * @typedef {[name: string, typ?: OptionType, pen?: boolean]} OptionDescription
18
- */
14
+ export type OptionDescription = [name: string, typ?: OptionType, pen?: boolean];
19
15
 
20
- /** @typedef {Map<number, OptionDescription>} BlockOpts*/
16
+ export type BlockOpts = Map<number, OptionDescription>;
21
17
 
22
- /**
23
- * @type {Map<number, BlockOpts>}
24
- */
25
- export const OPTION_NAMES = new Map([
18
+ export const OPTION_NAMES = new Map<number, BlockOpts>([
26
19
  [SECTION_HEADER, /** @type {BlockOpts} */ (new Map([
27
20
  [1, ['opt_comment', 'string']],
28
21
  [2, ['shb_hardware', 'string']],
package/src/utils.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Return this number padded to the nearest multiple of 4.
3
+ *
4
+ * @param n Number.
5
+ * @returns Padded.
6
+ */
7
+ export function pad4(n: number): number {
8
+ return (Math.ceil(n / 4) * 4) - n;
9
+ }
10
+
11
+ /**
12
+ * Convert buffer to hex string with colon separators (e.g. Ethernet address).
13
+ *
14
+ * @param buf Buffer.
15
+ * @returns Colon-separated string.
16
+ */
17
+ export function colons(buf: Uint8Array): string {
18
+ return Array.from(buf)
19
+ .map(x => x.toString(16).padStart(2, '0'))
20
+ .join(':');
21
+ }
@@ -1,186 +0,0 @@
1
- /**
2
- * @typedef {object} BlockProperty
3
- * @property {number} size Bytes.
4
- * @property {boolean} [signed] If true, read signed.
5
- */
6
-
7
- /**
8
- * @typedef {Record<string, BlockProperty>} BlockDescriptor
9
- */
10
-
11
- /**
12
- * @see documentation at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-section-header-block
13
- */
14
- export const sectionHeaderBlock = {
15
- byteOrderMagic: {
16
- size: 4,
17
- },
18
- majorVersion: {
19
- size: 2,
20
- },
21
- minorVersion: {
22
- size: 2,
23
- },
24
- sectionLength: {
25
- size: 8,
26
- signed: true,
27
- },
28
- };
29
-
30
- /**
31
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
32
- */
33
- export const blockType = {
34
- blockType: {
35
- size: 4,
36
- signed: true,
37
- },
38
- };
39
-
40
- export const blockTotalLength = {
41
- blockTotalLength: {
42
- size: 4,
43
- },
44
- };
45
-
46
- /**
47
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-interface-description-block
48
- */
49
- export const interfaceDescriptionBlockFormat = {
50
- linkType: {
51
- size: 2,
52
- },
53
- reserved: {
54
- size: 2,
55
- },
56
- snapLen: {
57
- size: 4,
58
- },
59
- };
60
-
61
- export const simplePacketFormat = {
62
- originalPacketLength: {
63
- size: 4,
64
- },
65
- };
66
-
67
- export const nameResolutionFormat = {
68
- recordType: {
69
- size: 2,
70
- },
71
- recordValueLength: {
72
- size: 2,
73
- },
74
- };
75
-
76
- /**
77
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
78
- */
79
- export const enhancedPacketBlockFormat = {
80
- interfaceId: {
81
- size: 4,
82
- },
83
- timestampHigh: {
84
- size: 4,
85
- },
86
- timestampLow: {
87
- size: 4,
88
- },
89
- capturedPacketLength: {
90
- size: 4,
91
- },
92
- originalPacketLength: {
93
- size: 4,
94
- },
95
-
96
- /* Packet Data */
97
- /* Options */
98
- };
99
-
100
- /**
101
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-options
102
- */
103
- export const optionBlock = {
104
- optionType: {
105
- size: 2,
106
- },
107
- dataLength: {
108
- size: 2,
109
- },
110
- };
111
-
112
- export const endLength = {
113
- endTotalLength: {
114
- size: 4,
115
- },
116
- };
117
-
118
- export const privateEnterpriseNumber = {
119
- pen: {
120
- size: 4,
121
- },
122
- };
123
-
124
- export const interfaceStatisticsFormat = {
125
- interfaceId: {
126
- size: 4,
127
- },
128
- timestampHigh: {
129
- size: 4,
130
- },
131
- timestampLow: {
132
- size: 4,
133
- },
134
- };
135
-
136
- export const decryptionSecretsFormat = {
137
- secretsType: {
138
- size: 4,
139
- },
140
- secretsLength: {
141
- size: 4,
142
- },
143
- };
144
-
145
- export const epbFlagsFormat = {
146
- flags: {
147
- size: 4,
148
- },
149
- };
150
-
151
- export const ifTsOffsetFormat = {
152
- tsoffset: {
153
- size: 8,
154
- sign: true,
155
- },
156
- };
157
-
158
- export const ipv4MaskFormat = {
159
- ipv4: {
160
- size: 4,
161
- },
162
- mask: {
163
- size: 4,
164
- },
165
- };
166
-
167
- export const u32Format = {
168
- u32: {
169
- size: 4,
170
- },
171
- };
172
-
173
- export const u64Format = {
174
- u64: {
175
- size: 8,
176
- },
177
- };
178
-
179
- export const timestampFormat = {
180
- timestampHigh: {
181
- size: 4,
182
- },
183
- timestampLow: {
184
- size: 4,
185
- },
186
- };