@cto.af/pcap-ng-parser 2.1.0 → 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.
@@ -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,141 +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: {size: 4},
16
- majorVersion: {size: 2},
17
- minorVersion: {size: 2},
18
- sectionLength: {
19
- size: 8,
20
- signed: true,
21
- },
22
- };
23
-
24
- /**
25
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
26
- */
27
- export const blockType = {
28
- blockType: {
29
- size: 4,
30
- signed: true,
31
- },
32
- };
33
-
34
- export const blockTotalLength = {
35
- blockTotalLength: {size: 4},
36
- };
37
-
38
- /**
39
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-interface-description-block
40
- */
41
- export const interfaceDescriptionBlockFormat = {
42
- linkType: {size: 2},
43
- reserved: {size: 2},
44
- snapLen: {size: 4},
45
- };
46
-
47
- export const simplePacketFormat = {
48
- originalPacketLength: {size: 4},
49
- };
50
-
51
- export const nameResolutionFormat = {
52
- recordType: {size: 2},
53
- recordValueLength: {size: 2},
54
- };
55
-
56
- /**
57
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-enhanced-packet-block
58
- */
59
- export const enhancedPacketBlockFormat = {
60
- interfaceId: {size: 4},
61
- timestampHigh: {size: 4},
62
- timestampLow: {size: 4},
63
- capturedPacketLength: {size: 4},
64
- originalPacketLength: {size: 4},
65
-
66
- /* Packet Data */
67
- /* Options */
68
- };
69
-
70
- /**
71
- * @see definition at https://www.ietf.org/archive/id/draft-ietf-opsawg-pcapng-04.html#name-options
72
- */
73
- export const optionBlock = {
74
- optionType: {size: 2},
75
- dataLength: {size: 2},
76
- };
77
-
78
- export const endLength = {
79
- endTotalLength: {size: 4},
80
- };
81
-
82
- export const privateEnterpriseNumber = {
83
- pen: {size: 4},
84
- };
85
-
86
- export const interfaceStatisticsFormat = {
87
- interfaceId: {size: 4},
88
- timestampHigh: {size: 4},
89
- timestampLow: {size: 4},
90
- };
91
-
92
- export const decryptionSecretsFormat = {
93
- secretsType: {size: 4},
94
- secretsLength: {size: 4},
95
- };
96
-
97
- export const epbFlagsFormat = {
98
- flags: {size: 4},
99
- };
100
-
101
- export const ifTsOffsetFormat = {
102
- tsoffset: {
103
- size: 8,
104
- sign: true,
105
- },
106
- };
107
-
108
- export const ipv4MaskFormat = {
109
- ipv4: {size: 4},
110
- mask: {size: 4},
111
- };
112
-
113
- export const u32Format = {
114
- u32: {size: 4},
115
- };
116
-
117
- export const u64Format = {
118
- u64: {size: 8},
119
- };
120
-
121
- export const timestampFormat = {
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},
141
- };