netkitty 0.0.15 → 0.0.17

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.
Files changed (262) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +1 -1
  2. package/README.md +1 -1
  3. package/assets/NetKitty.png +0 -0
  4. package/package.json +28 -4
  5. package/src/CodecExports.ts +33 -0
  6. package/src/CodecHeaderExports.ts +1 -0
  7. package/src/HelperExports.ts +78 -0
  8. package/src/NetKitty.ts +91 -31
  9. package/src/NetworkExports.ts +12 -0
  10. package/src/PcapExports.ts +16 -0
  11. package/src/lib/codec/Codec.ts +2 -21
  12. package/src/lib/codec/PacketHeaders.ts +13 -0
  13. package/src/lib/codec/headers/ARP.ts +7 -7
  14. package/src/lib/codec/headers/EthernetII.ts +1 -1
  15. package/src/lib/codec/headers/Goose.ts +6 -6
  16. package/src/lib/codec/headers/ICMP.ts +151 -0
  17. package/src/lib/codec/headers/ICMPv6.ts +128 -0
  18. package/src/lib/codec/headers/IEC61850SampledValues.ts +5 -5
  19. package/src/lib/codec/headers/IPv4.ts +8 -8
  20. package/src/lib/codec/headers/IPv6.ts +176 -0
  21. package/src/lib/codec/headers/IPv6HopByHopOptions.ts +532 -0
  22. package/src/lib/codec/headers/RawData.ts +1 -1
  23. package/src/lib/codec/headers/TCP.ts +6 -5
  24. package/src/lib/codec/headers/UDP.ts +3 -3
  25. package/src/lib/codec/headers/VLAN_802dot1Q.ts +2 -2
  26. package/src/lib/helper/HexToBuffer.ts +22 -0
  27. package/src/tests/units/Codec.spec.ts +13 -14
  28. package/dist/NetKitty.d.ts +0 -32
  29. package/dist/NetKitty.d.ts.map +0 -1
  30. package/dist/NetKitty.js +0 -34
  31. package/dist/errors/ActionNotFoundError.d.ts +0 -5
  32. package/dist/errors/ActionNotFoundError.d.ts.map +0 -1
  33. package/dist/errors/ActionNotFoundError.js +0 -12
  34. package/dist/errors/CodecSchemaValidateError.d.ts +0 -5
  35. package/dist/errors/CodecSchemaValidateError.d.ts.map +0 -1
  36. package/dist/errors/CodecSchemaValidateError.js +0 -12
  37. package/dist/errors/DeviceNotFoundError.d.ts +0 -5
  38. package/dist/errors/DeviceNotFoundError.d.ts.map +0 -1
  39. package/dist/errors/DeviceNotFoundError.js +0 -12
  40. package/dist/errors/NoAvailableCodecError.d.ts +0 -5
  41. package/dist/errors/NoAvailableCodecError.d.ts.map +0 -1
  42. package/dist/errors/NoAvailableCodecError.js +0 -12
  43. package/dist/errors/NpcapLoadError.d.ts +0 -5
  44. package/dist/errors/NpcapLoadError.d.ts.map +0 -1
  45. package/dist/errors/NpcapLoadError.js +0 -12
  46. package/dist/errors/SocketDownError.d.ts +0 -5
  47. package/dist/errors/SocketDownError.d.ts.map +0 -1
  48. package/dist/errors/SocketDownError.js +0 -12
  49. package/dist/errors/UnknownPipeMessageTypeError.d.ts +0 -5
  50. package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +0 -1
  51. package/dist/errors/UnknownPipeMessageTypeError.js +0 -12
  52. package/dist/errors/common/ErrorCode.d.ts +0 -31
  53. package/dist/errors/common/ErrorCode.d.ts.map +0 -1
  54. package/dist/errors/common/ErrorCode.js +0 -33
  55. package/dist/lib/GeneratePipeAddress.d.ts +0 -7
  56. package/dist/lib/GeneratePipeAddress.d.ts.map +0 -1
  57. package/dist/lib/GeneratePipeAddress.js +0 -23
  58. package/dist/lib/GetBinding.d.ts +0 -2
  59. package/dist/lib/GetBinding.d.ts.map +0 -1
  60. package/dist/lib/GetBinding.js +0 -6
  61. package/dist/lib/GetCaptureTemporaryDirectory.d.ts +0 -7
  62. package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +0 -1
  63. package/dist/lib/GetCaptureTemporaryDirectory.js +0 -15
  64. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +0 -8
  65. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +0 -1
  66. package/dist/lib/GetDeviceCaptureTemporaryFilename.js +0 -18
  67. package/dist/lib/codec/Codec.d.ts +0 -33
  68. package/dist/lib/codec/Codec.d.ts.map +0 -1
  69. package/dist/lib/codec/Codec.js +0 -168
  70. package/dist/lib/codec/abstracts/BaseHeader.d.ts +0 -217
  71. package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +0 -1
  72. package/dist/lib/codec/abstracts/BaseHeader.js +0 -356
  73. package/dist/lib/codec/headers/ARP.d.ts +0 -10
  74. package/dist/lib/codec/headers/ARP.d.ts.map +0 -1
  75. package/dist/lib/codec/headers/ARP.js +0 -224
  76. package/dist/lib/codec/headers/EthernetII.d.ts +0 -10
  77. package/dist/lib/codec/headers/EthernetII.d.ts.map +0 -1
  78. package/dist/lib/codec/headers/EthernetII.js +0 -81
  79. package/dist/lib/codec/headers/Goose.d.ts +0 -13
  80. package/dist/lib/codec/headers/Goose.d.ts.map +0 -1
  81. package/dist/lib/codec/headers/Goose.js +0 -720
  82. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +0 -13
  83. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +0 -1
  84. package/dist/lib/codec/headers/IEC61850SampledValues.js +0 -370
  85. package/dist/lib/codec/headers/IPv4.d.ts +0 -16
  86. package/dist/lib/codec/headers/IPv4.d.ts.map +0 -1
  87. package/dist/lib/codec/headers/IPv4.js +0 -339
  88. package/dist/lib/codec/headers/RawData.d.ts +0 -11
  89. package/dist/lib/codec/headers/RawData.d.ts.map +0 -1
  90. package/dist/lib/codec/headers/RawData.js +0 -36
  91. package/dist/lib/codec/headers/TCP.d.ts +0 -16
  92. package/dist/lib/codec/headers/TCP.d.ts.map +0 -1
  93. package/dist/lib/codec/headers/TCP.js +0 -898
  94. package/dist/lib/codec/headers/UDP.d.ts +0 -16
  95. package/dist/lib/codec/headers/UDP.d.ts.map +0 -1
  96. package/dist/lib/codec/headers/UDP.js +0 -192
  97. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +0 -10
  98. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +0 -1
  99. package/dist/lib/codec/headers/VLAN_802dot1Q.js +0 -78
  100. package/dist/lib/codec/lib/BufferToHex.d.ts +0 -2
  101. package/dist/lib/codec/lib/BufferToHex.d.ts.map +0 -1
  102. package/dist/lib/codec/lib/BufferToHex.js +0 -6
  103. package/dist/lib/codec/lib/BufferToIP.d.ts +0 -13
  104. package/dist/lib/codec/lib/BufferToIP.d.ts.map +0 -1
  105. package/dist/lib/codec/lib/BufferToIP.js +0 -21
  106. package/dist/lib/codec/lib/BufferToNumber.d.ts +0 -10
  107. package/dist/lib/codec/lib/BufferToNumber.d.ts.map +0 -1
  108. package/dist/lib/codec/lib/BufferToNumber.js +0 -22
  109. package/dist/lib/codec/lib/FixHexString.d.ts +0 -7
  110. package/dist/lib/codec/lib/FixHexString.d.ts.map +0 -1
  111. package/dist/lib/codec/lib/FixHexString.js +0 -11
  112. package/dist/lib/codec/lib/FlexibleObject.d.ts +0 -28
  113. package/dist/lib/codec/lib/FlexibleObject.d.ts.map +0 -1
  114. package/dist/lib/codec/lib/FlexibleObject.js +0 -102
  115. package/dist/lib/codec/lib/HexToNumber.d.ts +0 -10
  116. package/dist/lib/codec/lib/HexToNumber.d.ts.map +0 -1
  117. package/dist/lib/codec/lib/HexToNumber.js +0 -39
  118. package/dist/lib/codec/lib/IPToBuffer.d.ts +0 -13
  119. package/dist/lib/codec/lib/IPToBuffer.d.ts.map +0 -1
  120. package/dist/lib/codec/lib/IPToBuffer.js +0 -28
  121. package/dist/lib/codec/lib/NumberToBERBuffer.d.ts +0 -9
  122. package/dist/lib/codec/lib/NumberToBERBuffer.d.ts.map +0 -1
  123. package/dist/lib/codec/lib/NumberToBERBuffer.js +0 -20
  124. package/dist/lib/codec/lib/NumberToBERHex.d.ts +0 -9
  125. package/dist/lib/codec/lib/NumberToBERHex.d.ts.map +0 -1
  126. package/dist/lib/codec/lib/NumberToBERHex.js +0 -23
  127. package/dist/lib/codec/lib/NumberToBuffer.d.ts +0 -10
  128. package/dist/lib/codec/lib/NumberToBuffer.d.ts.map +0 -1
  129. package/dist/lib/codec/lib/NumberToBuffer.js +0 -22
  130. package/dist/lib/codec/lib/NumberToHex.d.ts +0 -10
  131. package/dist/lib/codec/lib/NumberToHex.d.ts.map +0 -1
  132. package/dist/lib/codec/lib/NumberToHex.js +0 -26
  133. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +0 -14
  134. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +0 -1
  135. package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +0 -53
  136. package/dist/lib/codec/lib/SortPostHandlers.d.ts +0 -8
  137. package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +0 -1
  138. package/dist/lib/codec/lib/SortPostHandlers.js +0 -11
  139. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +0 -11
  140. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +0 -1
  141. package/dist/lib/codec/lib/StringContentEncodingEnum.js +0 -14
  142. package/dist/lib/codec/types/CodecData.d.ts +0 -7
  143. package/dist/lib/codec/types/CodecData.d.ts.map +0 -1
  144. package/dist/lib/codec/types/CodecData.js +0 -2
  145. package/dist/lib/codec/types/CodecDecodeResult.d.ts +0 -11
  146. package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +0 -1
  147. package/dist/lib/codec/types/CodecDecodeResult.js +0 -2
  148. package/dist/lib/codec/types/CodecEncodeInput.d.ts +0 -9
  149. package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +0 -1
  150. package/dist/lib/codec/types/CodecEncodeInput.js +0 -2
  151. package/dist/lib/codec/types/CodecEncodeResult.d.ts +0 -6
  152. package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +0 -1
  153. package/dist/lib/codec/types/CodecEncodeResult.js +0 -2
  154. package/dist/lib/codec/types/CodecErrorInfo.d.ts +0 -6
  155. package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +0 -1
  156. package/dist/lib/codec/types/CodecErrorInfo.js +0 -2
  157. package/dist/lib/codec/types/CodecModule.d.ts +0 -3
  158. package/dist/lib/codec/types/CodecModule.d.ts.map +0 -1
  159. package/dist/lib/codec/types/CodecModule.js +0 -2
  160. package/dist/lib/codec/types/CodecModuleConstructor.d.ts +0 -3
  161. package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +0 -1
  162. package/dist/lib/codec/types/CodecModuleConstructor.js +0 -2
  163. package/dist/lib/codec/types/CodecSchema.d.ts +0 -7
  164. package/dist/lib/codec/types/CodecSchema.d.ts.map +0 -1
  165. package/dist/lib/codec/types/CodecSchema.js +0 -2
  166. package/dist/lib/codec/types/HeaderTreeNode.d.ts +0 -5
  167. package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +0 -1
  168. package/dist/lib/codec/types/HeaderTreeNode.js +0 -2
  169. package/dist/lib/codec/types/PostHandlerItem.d.ts +0 -5
  170. package/dist/lib/codec/types/PostHandlerItem.d.ts.map +0 -1
  171. package/dist/lib/codec/types/PostHandlerItem.js +0 -2
  172. package/dist/lib/nodepcap/Capture.d.ts +0 -75
  173. package/dist/lib/nodepcap/Capture.d.ts.map +0 -1
  174. package/dist/lib/nodepcap/Capture.js +0 -309
  175. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +0 -7
  176. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +0 -1
  177. package/dist/lib/nodepcap/GetNetworkInterfaces.js +0 -22
  178. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +0 -16
  179. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +0 -1
  180. package/dist/lib/nodepcap/interfaces/IBindingCapture.js +0 -2
  181. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +0 -5
  182. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +0 -1
  183. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +0 -2
  184. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +0 -19
  185. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +0 -1
  186. package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +0 -2
  187. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +0 -5
  188. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +0 -1
  189. package/dist/lib/nodepcap/interfaces/INetworkInterface.js +0 -2
  190. package/dist/lib/nodepcap/lib/BindingCapture.d.ts +0 -15
  191. package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +0 -1
  192. package/dist/lib/nodepcap/lib/BindingCapture.js +0 -35
  193. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +0 -2
  194. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +0 -1
  195. package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +0 -55
  196. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +0 -3
  197. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +0 -1
  198. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +0 -18
  199. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +0 -2
  200. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +0 -1
  201. package/dist/lib/nodepcap/workers/CaptureWorker.js +0 -25
  202. package/dist/lib/pcap/PCAPGenerator.d.ts +0 -34
  203. package/dist/lib/pcap/PCAPGenerator.d.ts.map +0 -1
  204. package/dist/lib/pcap/PCAPGenerator.js +0 -95
  205. package/dist/lib/pcap/PcapParser.d.ts +0 -27
  206. package/dist/lib/pcap/PcapParser.d.ts.map +0 -1
  207. package/dist/lib/pcap/PcapParser.js +0 -149
  208. package/dist/lib/pcap/PcapReader.d.ts +0 -89
  209. package/dist/lib/pcap/PcapReader.d.ts.map +0 -1
  210. package/dist/lib/pcap/PcapReader.js +0 -209
  211. package/dist/lib/pcap/PcapWriter.d.ts +0 -29
  212. package/dist/lib/pcap/PcapWriter.d.ts.map +0 -1
  213. package/dist/lib/pcap/PcapWriter.js +0 -80
  214. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +0 -13
  215. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +0 -1
  216. package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +0 -2
  217. package/dist/lib/pipe/PipeClient.d.ts +0 -35
  218. package/dist/lib/pipe/PipeClient.d.ts.map +0 -1
  219. package/dist/lib/pipe/PipeClient.js +0 -71
  220. package/dist/lib/pipe/PipeClientSocket.d.ts +0 -39
  221. package/dist/lib/pipe/PipeClientSocket.d.ts.map +0 -1
  222. package/dist/lib/pipe/PipeClientSocket.js +0 -82
  223. package/dist/lib/pipe/PipeMessage.d.ts +0 -27
  224. package/dist/lib/pipe/PipeMessage.d.ts.map +0 -1
  225. package/dist/lib/pipe/PipeMessage.js +0 -61
  226. package/dist/lib/pipe/PipeMessageHandler.d.ts +0 -16
  227. package/dist/lib/pipe/PipeMessageHandler.d.ts.map +0 -1
  228. package/dist/lib/pipe/PipeMessageHandler.js +0 -95
  229. package/dist/lib/pipe/PipeServer.d.ts +0 -25
  230. package/dist/lib/pipe/PipeServer.d.ts.map +0 -1
  231. package/dist/lib/pipe/PipeServer.js +0 -59
  232. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +0 -35
  233. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +0 -1
  234. package/dist/lib/schema/ProtocolFieldJSONSchema.js +0 -2
  235. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +0 -3
  236. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +0 -1
  237. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +0 -2
  238. package/dist/lib/schema/ProtocolJSONSchema.d.ts +0 -32
  239. package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +0 -1
  240. package/dist/lib/schema/ProtocolJSONSchema.js +0 -2
  241. package/dist/tests/Test.spec.d.ts +0 -2
  242. package/dist/tests/Test.spec.d.ts.map +0 -1
  243. package/dist/tests/Test.spec.js +0 -25
  244. package/dist/tests/units/CaptureTest.spec.d.ts +0 -2
  245. package/dist/tests/units/CaptureTest.spec.d.ts.map +0 -1
  246. package/dist/tests/units/CaptureTest.spec.js +0 -31
  247. package/dist/tests/units/Codec.spec.d.ts +0 -2
  248. package/dist/tests/units/Codec.spec.d.ts.map +0 -1
  249. package/dist/tests/units/Codec.spec.js +0 -76
  250. package/dist/tests/units/ReadPCAP.spec.d.ts +0 -2
  251. package/dist/tests/units/ReadPCAP.spec.d.ts.map +0 -1
  252. package/dist/tests/units/ReadPCAP.spec.js +0 -14
  253. package/src/lib/codec/lib/FixHexString.ts +0 -8
  254. /package/src/lib/{codec/lib → helper}/BufferToHex.ts +0 -0
  255. /package/src/lib/{codec/lib → helper}/BufferToIP.ts +0 -0
  256. /package/src/lib/{codec/lib → helper}/BufferToNumber.ts +0 -0
  257. /package/src/lib/{codec/lib → helper}/HexToNumber.ts +0 -0
  258. /package/src/lib/{codec/lib → helper}/IPToBuffer.ts +0 -0
  259. /package/src/lib/{codec/lib → helper}/NumberToBERBuffer.ts +0 -0
  260. /package/src/lib/{codec/lib → helper}/NumberToBERHex.ts +0 -0
  261. /package/src/lib/{codec/lib → helper}/NumberToBuffer.ts +0 -0
  262. /package/src/lib/{codec/lib → helper}/NumberToHex.ts +0 -0
@@ -0,0 +1,128 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {BaseHeader} from '../abstracts/BaseHeader'
3
+ import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
4
+ import {BufferToUInt16, BufferToUInt8} from '../../helper/BufferToNumber'
5
+ import {UInt16ToBuffer, UInt32ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
6
+ import {BufferToHex} from '../../helper/BufferToHex'
7
+ import {CodecModule} from '../types/CodecModule'
8
+ import {IPv6ToBuffer} from '../../helper/IPToBuffer'
9
+
10
+ export class ICMPv6 extends BaseHeader {
11
+
12
+ /**
13
+ * Calculate ICMPv6 checksum
14
+ * @protected
15
+ */
16
+ protected calculateIcmpv6Checksum(): number {
17
+ const ipv6Header: CodecModule | undefined = this.prevCodecModules.find((prevCodecModule: CodecModule): boolean => prevCodecModule.id === 'ipv6')
18
+ if (!ipv6Header) return 0
19
+ const messageBody: Buffer = Buffer.from(this.instance.message.getValue(''), 'hex')
20
+ const sip: string = ipv6Header.instance.sip.getValue('0000:0000:0000:0000:0000:0000:0000:0000')
21
+ const dip: string = ipv6Header.instance.dip.getValue('0000:0000:0000:0000:0000:0000:0000:0000')
22
+ const pseudoHeader: Buffer = Buffer.concat([
23
+ IPv6ToBuffer(sip),
24
+ IPv6ToBuffer(dip),
25
+ UInt32ToBuffer(messageBody.length + 4),
26
+ UInt8ToBuffer(0x00),
27
+ UInt8ToBuffer(0x00),
28
+ UInt8ToBuffer(0x00),
29
+ UInt8ToBuffer(0x3a)
30
+ ])
31
+
32
+ const icmpHeader: Buffer = Buffer.concat([
33
+ UInt8ToBuffer(this.instance.type.getValue(0)),
34
+ UInt8ToBuffer(this.instance.code.getValue(0)),
35
+ UInt16ToBuffer(this.instance.checksum.getValue(0))
36
+ ])
37
+ const buffer: Buffer = Buffer.concat([
38
+ pseudoHeader,
39
+ icmpHeader,
40
+ messageBody
41
+ ])
42
+ const paddedBuffer: Buffer = buffer.length % 2 === 1 ? Buffer.concat([buffer, UInt8ToBuffer(0)]) : buffer
43
+ let checksum: number = 0
44
+ for (let i: number = 0; i < paddedBuffer.length; i += 2) {
45
+ checksum += (paddedBuffer[i] << 8) | (paddedBuffer[i + 1] || 0)
46
+ if (checksum > 0xFFFF) checksum = (checksum & 0xFFFF) + 1
47
+ }
48
+ return (~checksum) & 0xFFFF
49
+ }
50
+
51
+ public SCHEMA: ProtocolJSONSchema = {
52
+ type: 'object',
53
+ properties: {
54
+ type: {
55
+ type: 'integer',
56
+ label: 'Type',
57
+ minimum: 0,
58
+ maximum: 255,
59
+ decode: (): void => {
60
+ this.instance.type.setValue(BufferToUInt8(this.readBytes(0, 1)))
61
+ },
62
+ encode: (): void => {
63
+ const type: number = this.instance.type.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
64
+ this.instance.type.setValue(type)
65
+ this.writeBytes(0, UInt8ToBuffer(type))
66
+ }
67
+ },
68
+ code: {
69
+ type: 'integer',
70
+ label: 'Code',
71
+ minimum: 0,
72
+ maximum: 255,
73
+ decode: (): void => {
74
+ this.instance.code.setValue(BufferToUInt8(this.readBytes(1, 1)))
75
+ },
76
+ encode: (): void => {
77
+ const code: number = this.instance.code.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
78
+ this.instance.code.setValue(code)
79
+ this.writeBytes(1, UInt8ToBuffer(code))
80
+ }
81
+ },
82
+ checksum: {
83
+ type: 'integer',
84
+ label: 'Checksum',
85
+ minimum: 0,
86
+ maximum: 65535,
87
+ decode: (): void => {
88
+ this.instance.checksum.setValue(BufferToUInt16(this.readBytes(2, 2)))
89
+ },
90
+ encode: (): void => {
91
+ let checksum: number = this.instance.checksum.getValue(0)
92
+ this.instance.checksum.setValue(checksum)
93
+ this.writeBytes(2, UInt16ToBuffer(checksum))
94
+ if (!checksum) {
95
+ checksum = this.calculateIcmpv6Checksum()
96
+ this.instance.checksum.setValue(checksum)
97
+ this.writeBytes(2, UInt16ToBuffer(checksum))
98
+ }
99
+ }
100
+ },
101
+ message: {
102
+ type: 'string',
103
+ label: 'Message Body',
104
+ contentEncoding: StringContentEncodingEnum.HEX,
105
+ decode: (): void => {
106
+ const messageDataLength: number = this.packet.length - this.startPos - 4
107
+ this.instance.message.setValue(BufferToHex(this.readBytes(4, messageDataLength)))
108
+ },
109
+ encode: (): void => {
110
+ const messageHex: string = this.instance.message.getValue('')
111
+ this.instance.message.setValue(messageHex)
112
+ this.writeBytes(4, Buffer.from(messageHex, 'hex'))
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ public id: string = 'icmpv6'
119
+
120
+ public name: string = 'Internet Control Message Protocol v6'
121
+
122
+ public nickname: string = 'ICMPv6'
123
+
124
+ public match(): boolean {
125
+ if (!this.prevCodecModule) return false
126
+ return this.prevCodecModule.instance.nxt.getValue() === 0x3a
127
+ }
128
+ }
@@ -1,12 +1,12 @@
1
1
  import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
2
  import {BaseHeader} from '../abstracts/BaseHeader'
3
3
  import TLV from 'node-tlv'
4
- import {HexToUInt16} from '../lib/HexToNumber'
5
- import {UInt16ToBERHex} from '../lib/NumberToBERHex'
6
- import {UInt16ToHex, UInt32ToHex, UInt8ToHex} from '../lib/NumberToHex'
4
+ import {HexToUInt16} from '../../helper/HexToNumber'
5
+ import {UInt16ToBERHex} from '../../helper/NumberToBERHex'
6
+ import {UInt16ToHex, UInt32ToHex, UInt8ToHex} from '../../helper/NumberToHex'
7
7
  import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
8
- import {BufferToUInt16, BufferToUInt32, BufferToUInt64, BufferToUInt8} from '../lib/BufferToNumber'
9
- import {UInt16ToBuffer} from '../lib/NumberToBuffer'
8
+ import {BufferToUInt16, BufferToUInt32, BufferToUInt64, BufferToUInt8} from '../../helper/BufferToNumber'
9
+ import {UInt16ToBuffer} from '../../helper/NumberToBuffer'
10
10
 
11
11
  type ASDUItem = {
12
12
  svID: string
@@ -1,14 +1,14 @@
1
1
  import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
2
  import {BaseHeader} from '../abstracts/BaseHeader'
3
- import {UInt16ToHex} from '../lib/NumberToHex'
3
+ import {UInt16ToHex} from '../../helper/NumberToHex'
4
4
  import {CodecModule} from '../types/CodecModule'
5
5
  import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
6
- import {FixHexString} from '../lib/FixHexString'
7
- import {BufferToUInt16, BufferToUInt8} from '../lib/BufferToNumber'
8
- import {UInt16ToBuffer, UInt8ToBuffer} from '../lib/NumberToBuffer'
9
- import {BufferToHex} from '../lib/BufferToHex'
10
- import {IPv4ToBuffer} from '../lib/IPToBuffer'
11
- import {BufferToIPv4} from '../lib/BufferToIP'
6
+ import {BufferToUInt16, BufferToUInt8} from '../../helper/BufferToNumber'
7
+ import {UInt16ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
8
+ import {BufferToHex} from '../../helper/BufferToHex'
9
+ import {IPv4ToBuffer} from '../../helper/IPToBuffer'
10
+ import {BufferToIPv4} from '../../helper/BufferToIP'
11
+ import {HexToBuffer} from '../../helper/HexToBuffer'
12
12
 
13
13
  export class IPv4 extends BaseHeader {
14
14
 
@@ -301,7 +301,7 @@ export class IPv4 extends BaseHeader {
301
301
  },
302
302
  encode: (): void => {
303
303
  if (!this.instance.options.isUndefined()) {
304
- let optionsBuffer: Buffer = Buffer.from(FixHexString(this.instance.options.getValue()), 'hex')
304
+ let optionsBuffer: Buffer = HexToBuffer(this.instance.options.getValue(''))
305
305
  if (optionsBuffer.length > 40) optionsBuffer = optionsBuffer.subarray(0, 40)
306
306
  const estimateHdrLen: number = this.length + optionsBuffer.length
307
307
  if (estimateHdrLen % 4) {
@@ -0,0 +1,176 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {BaseHeader} from '../abstracts/BaseHeader'
3
+ import {UInt16ToHex} from '../../helper/NumberToHex'
4
+ import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
5
+ import {BufferToUInt16, BufferToUInt8} from '../../helper/BufferToNumber'
6
+ import {UInt16ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
7
+ import {BufferToIPv6} from '../../helper/BufferToIP'
8
+ import {IPv6ToBuffer} from '../../helper/IPToBuffer'
9
+ import {CodecModule} from '../types/CodecModule'
10
+
11
+ export class IPv6 extends BaseHeader {
12
+
13
+ public SCHEMA: ProtocolJSONSchema = {
14
+ type: 'object',
15
+ properties: {
16
+ version: {
17
+ type: 'integer',
18
+ label: 'Version',
19
+ minimum: 0,
20
+ maximum: 15,
21
+ decode: (): void => {
22
+ this.instance.version.setValue(this.readBits(0, 1, 0, 4))
23
+ },
24
+ encode: (): void => {
25
+ const version: number = this.instance.version.getValue(6, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
26
+ this.instance.version.setValue(version)
27
+ this.writeBits(0, 1, 0, 4, version)
28
+ }
29
+ },
30
+ tclass: {
31
+ type: 'object',
32
+ label: 'Traffic Class',
33
+ properties: {
34
+ dscp: {
35
+ type: 'integer',
36
+ minimum: 0,
37
+ maximum: 63,
38
+ label: 'Differentiated Services Codepoint',
39
+ decode: (): void => {
40
+ this.instance.tclass.dscp.setValue(this.readBits(0, 4, 4, 6))
41
+ },
42
+ encode: (): void => {
43
+ const dscp: number = this.instance.tclass.dscp.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
44
+ this.instance.tclass.dscp.setValue(dscp)
45
+ this.writeBits(0, 4, 4, 6, dscp)
46
+ }
47
+ },
48
+ ecn: {
49
+ type: 'integer',
50
+ label: 'Explicit Congestion Notification',
51
+ minimum: 0,
52
+ maximum: 3,
53
+ decode: (): void => {
54
+ this.instance.tclass.ecn.setValue(this.readBits(0, 4, 10, 2))
55
+ },
56
+ encode: (): void => {
57
+ const ecn: number = this.instance.tclass.ecn.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
58
+ this.instance.tclass.ecn.setValue(ecn)
59
+ this.writeBits(0, 4, 10, 2, ecn)
60
+ }
61
+ }
62
+ }
63
+ },
64
+ flow: {
65
+ type: 'integer',
66
+ label: 'Flow Label',
67
+ minimum: 0,
68
+ maximum: 1048575,
69
+ decode: (): void => {
70
+ this.instance.flow.setValue(this.readBits(1, 3, 4, 20))
71
+ },
72
+ encode: (): void => {
73
+ const flow: number = this.instance.flow.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
74
+ this.instance.flow.setValue(flow)
75
+ this.writeBits(1, 3, 4, 20, flow)
76
+ }
77
+ },
78
+ plen: {
79
+ type: 'integer',
80
+ label: 'Payload Length',
81
+ minimum: 0,
82
+ maximum: 65535,
83
+ decode: (): void => {
84
+ this.instance.plen.setValue(BufferToUInt16(this.readBytes(4, 2)))
85
+ },
86
+ encode: (): void => {
87
+ const plen: number = this.instance.plen.getValue(0)
88
+ this.instance.plen.setValue(plen)
89
+ this.writeBytes(4, UInt16ToBuffer(plen))
90
+ if (!plen) {
91
+ this.addPostPacketEncodeHandler((): void => {
92
+ let startCount: boolean = false
93
+ let totalLength: number = 0
94
+ this.codecModules.forEach((codecModule: CodecModule): void => {
95
+ if (codecModule === this) startCount = true
96
+ if (startCount) totalLength += codecModule.length
97
+ })
98
+ let payloadLength: number = totalLength - 40
99
+ //The length is set to zero when a Hop-by-Hop extension header carries a Jumbo Payload option
100
+ if (payloadLength > 65535) payloadLength = 0
101
+ this.instance.plen.setValue(payloadLength)
102
+ this.writeBytes(4, UInt16ToBuffer(payloadLength))
103
+
104
+ })
105
+ }
106
+ }
107
+ },
108
+ nxt: {
109
+ type: 'integer',
110
+ label: 'Next Header',
111
+ minimum: 0,
112
+ maximum: 255,
113
+ decode: (): void => {
114
+ this.instance.nxt.setValue(BufferToUInt8(this.readBytes(6, 1)))
115
+ },
116
+ encode: (): void => {
117
+ const nxt: number = this.instance.nxt.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
118
+ this.instance.nxt.setValue(nxt)
119
+ this.writeBytes(6, UInt8ToBuffer(nxt))
120
+ }
121
+ },
122
+ hllm: {
123
+ type: 'integer',
124
+ label: 'Hop Limit',
125
+ minimum: 0,
126
+ maximum: 255,
127
+ decode: (): void => {
128
+ this.instance.hllm.setValue(BufferToUInt8(this.readBytes(7, 1)))
129
+ },
130
+ encode: (): void => {
131
+ const hllm: number = this.instance.hllm.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
132
+ this.instance.hllm.setValue(hllm)
133
+ this.writeBytes(7, UInt8ToBuffer(hllm))
134
+ }
135
+ },
136
+ sip: {
137
+ type: 'string',
138
+ label: 'Source Address',
139
+ contentEncoding: StringContentEncodingEnum.IPv6,
140
+ decode: (): void => {
141
+ this.instance.sip.setValue(BufferToIPv6(this.readBytes(8, 16)))
142
+ },
143
+ encode: (): void => {
144
+ const sip: string = this.instance.sip.getValue('0000:0000:0000:0000:0000:0000:0000:0000', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
145
+ this.instance.sip.setValue(sip)
146
+ this.writeBytes(8, IPv6ToBuffer(sip))
147
+ }
148
+ },
149
+ dip: {
150
+ type: 'string',
151
+ label: 'Destination Address',
152
+ contentEncoding: StringContentEncodingEnum.IPv6,
153
+ decode: (): void => {
154
+ this.instance.dip.setValue(BufferToIPv6(this.readBytes(24, 16)))
155
+ },
156
+ encode: (): void => {
157
+ const dip: string = this.instance.dip.getValue('0000:0000:0000:0000:0000:0000:0000:0000', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
158
+ this.instance.dip.setValue(dip)
159
+ this.writeBytes(24, IPv6ToBuffer(dip))
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ public id: string = 'ipv6'
166
+
167
+ public name: string = 'Internet Protocol Version 6'
168
+
169
+ public nickname: string = 'IPv6'
170
+
171
+ public match(): boolean {
172
+ if (!this.prevCodecModule) return false
173
+ return this.prevCodecModule.instance.etherType.getValue() === UInt16ToHex(0x86dd)
174
+ }
175
+
176
+ }