netkitty 0.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.
Files changed (338) hide show
  1. package/.eslintrc.json +53 -0
  2. package/.idea/codeStyles/Project.xml +18 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +10 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/netkitty.iml +13 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/LICENSE +21 -0
  9. package/README.md +2 -0
  10. package/binding.gyp +5 -0
  11. package/build/NetKitty.d.ts +31 -0
  12. package/build/NetKitty.d.ts.map +1 -0
  13. package/build/NetKitty.js +33 -0
  14. package/build/errors/ActionNotFoundError.d.ts +5 -0
  15. package/build/errors/ActionNotFoundError.d.ts.map +1 -0
  16. package/build/errors/ActionNotFoundError.js +12 -0
  17. package/build/errors/CodecSchemaValidateError.d.ts +5 -0
  18. package/build/errors/CodecSchemaValidateError.d.ts.map +1 -0
  19. package/build/errors/CodecSchemaValidateError.js +12 -0
  20. package/build/errors/DeviceNotFoundError.d.ts +5 -0
  21. package/build/errors/DeviceNotFoundError.d.ts.map +1 -0
  22. package/build/errors/DeviceNotFoundError.js +12 -0
  23. package/build/errors/NoAvailableCodecError.d.ts +5 -0
  24. package/build/errors/NoAvailableCodecError.d.ts.map +1 -0
  25. package/build/errors/NoAvailableCodecError.js +12 -0
  26. package/build/errors/NpcapLoadError.d.ts +5 -0
  27. package/build/errors/NpcapLoadError.d.ts.map +1 -0
  28. package/build/errors/NpcapLoadError.js +12 -0
  29. package/build/errors/SocketDownError.d.ts +5 -0
  30. package/build/errors/SocketDownError.d.ts.map +1 -0
  31. package/build/errors/SocketDownError.js +12 -0
  32. package/build/errors/UnknownPipeMessageTypeError.d.ts +5 -0
  33. package/build/errors/UnknownPipeMessageTypeError.d.ts.map +1 -0
  34. package/build/errors/UnknownPipeMessageTypeError.js +12 -0
  35. package/build/errors/common/ErrorCode.d.ts +31 -0
  36. package/build/errors/common/ErrorCode.d.ts.map +1 -0
  37. package/build/errors/common/ErrorCode.js +33 -0
  38. package/build/lib/GeneratePipeAddress.d.ts +7 -0
  39. package/build/lib/GeneratePipeAddress.d.ts.map +1 -0
  40. package/build/lib/GeneratePipeAddress.js +23 -0
  41. package/build/lib/GetBinding.d.ts +2 -0
  42. package/build/lib/GetBinding.d.ts.map +1 -0
  43. package/build/lib/GetBinding.js +6 -0
  44. package/build/lib/GetCaptureTemporaryDirectory.d.ts +7 -0
  45. package/build/lib/GetCaptureTemporaryDirectory.d.ts.map +1 -0
  46. package/build/lib/GetCaptureTemporaryDirectory.js +15 -0
  47. package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts +8 -0
  48. package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +1 -0
  49. package/build/lib/GetDeviceCaptureTemporaryFilename.js +18 -0
  50. package/build/lib/codec/Codec.d.ts +33 -0
  51. package/build/lib/codec/Codec.d.ts.map +1 -0
  52. package/build/lib/codec/Codec.js +166 -0
  53. package/build/lib/codec/abstracts/BaseHeader.d.ts +204 -0
  54. package/build/lib/codec/abstracts/BaseHeader.d.ts.map +1 -0
  55. package/build/lib/codec/abstracts/BaseHeader.js +339 -0
  56. package/build/lib/codec/headers/ARP.d.ts +9 -0
  57. package/build/lib/codec/headers/ARP.d.ts.map +1 -0
  58. package/build/lib/codec/headers/ARP.js +223 -0
  59. package/build/lib/codec/headers/EthernetII.d.ts +9 -0
  60. package/build/lib/codec/headers/EthernetII.d.ts.map +1 -0
  61. package/build/lib/codec/headers/EthernetII.js +80 -0
  62. package/build/lib/codec/headers/Goose.d.ts +12 -0
  63. package/build/lib/codec/headers/Goose.d.ts.map +1 -0
  64. package/build/lib/codec/headers/Goose.js +701 -0
  65. package/build/lib/codec/headers/IEC61850SampledValues.d.ts +12 -0
  66. package/build/lib/codec/headers/IEC61850SampledValues.d.ts.map +1 -0
  67. package/build/lib/codec/headers/IEC61850SampledValues.js +369 -0
  68. package/build/lib/codec/headers/IPv4.d.ts +15 -0
  69. package/build/lib/codec/headers/IPv4.d.ts.map +1 -0
  70. package/build/lib/codec/headers/IPv4.js +338 -0
  71. package/build/lib/codec/headers/RawData.d.ts +9 -0
  72. package/build/lib/codec/headers/RawData.d.ts.map +1 -0
  73. package/build/lib/codec/headers/RawData.js +34 -0
  74. package/build/lib/codec/headers/TCP.d.ts +15 -0
  75. package/build/lib/codec/headers/TCP.d.ts.map +1 -0
  76. package/build/lib/codec/headers/TCP.js +897 -0
  77. package/build/lib/codec/headers/UDP.d.ts +15 -0
  78. package/build/lib/codec/headers/UDP.d.ts.map +1 -0
  79. package/build/lib/codec/headers/UDP.js +191 -0
  80. package/build/lib/codec/headers/VLAN_802dot1Q.d.ts +9 -0
  81. package/build/lib/codec/headers/VLAN_802dot1Q.d.ts.map +1 -0
  82. package/build/lib/codec/headers/VLAN_802dot1Q.js +77 -0
  83. package/build/lib/codec/lib/BufferToHex.d.ts +2 -0
  84. package/build/lib/codec/lib/BufferToHex.d.ts.map +1 -0
  85. package/build/lib/codec/lib/BufferToHex.js +6 -0
  86. package/build/lib/codec/lib/BufferToIP.d.ts +13 -0
  87. package/build/lib/codec/lib/BufferToIP.d.ts.map +1 -0
  88. package/build/lib/codec/lib/BufferToIP.js +21 -0
  89. package/build/lib/codec/lib/BufferToNumber.d.ts +10 -0
  90. package/build/lib/codec/lib/BufferToNumber.d.ts.map +1 -0
  91. package/build/lib/codec/lib/BufferToNumber.js +22 -0
  92. package/build/lib/codec/lib/FixHexString.d.ts +7 -0
  93. package/build/lib/codec/lib/FixHexString.d.ts.map +1 -0
  94. package/build/lib/codec/lib/FixHexString.js +11 -0
  95. package/build/lib/codec/lib/FlexibleObject.d.ts +28 -0
  96. package/build/lib/codec/lib/FlexibleObject.d.ts.map +1 -0
  97. package/build/lib/codec/lib/FlexibleObject.js +102 -0
  98. package/build/lib/codec/lib/HexToNumber.d.ts +10 -0
  99. package/build/lib/codec/lib/HexToNumber.d.ts.map +1 -0
  100. package/build/lib/codec/lib/HexToNumber.js +39 -0
  101. package/build/lib/codec/lib/IPToBuffer.d.ts +13 -0
  102. package/build/lib/codec/lib/IPToBuffer.d.ts.map +1 -0
  103. package/build/lib/codec/lib/IPToBuffer.js +28 -0
  104. package/build/lib/codec/lib/NumberToBERBuffer.d.ts +9 -0
  105. package/build/lib/codec/lib/NumberToBERBuffer.d.ts.map +1 -0
  106. package/build/lib/codec/lib/NumberToBERBuffer.js +20 -0
  107. package/build/lib/codec/lib/NumberToBERHex.d.ts +9 -0
  108. package/build/lib/codec/lib/NumberToBERHex.d.ts.map +1 -0
  109. package/build/lib/codec/lib/NumberToBERHex.js +23 -0
  110. package/build/lib/codec/lib/NumberToBuffer.d.ts +10 -0
  111. package/build/lib/codec/lib/NumberToBuffer.d.ts.map +1 -0
  112. package/build/lib/codec/lib/NumberToBuffer.js +22 -0
  113. package/build/lib/codec/lib/NumberToHex.d.ts +10 -0
  114. package/build/lib/codec/lib/NumberToHex.d.ts.map +1 -0
  115. package/build/lib/codec/lib/NumberToHex.js +26 -0
  116. package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts +14 -0
  117. package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +1 -0
  118. package/build/lib/codec/lib/ProcessPacketPostHandlers.js +53 -0
  119. package/build/lib/codec/lib/SortPostHandlers.d.ts +8 -0
  120. package/build/lib/codec/lib/SortPostHandlers.d.ts.map +1 -0
  121. package/build/lib/codec/lib/SortPostHandlers.js +11 -0
  122. package/build/lib/codec/lib/StringContentEncodingEnum.d.ts +8 -0
  123. package/build/lib/codec/lib/StringContentEncodingEnum.d.ts.map +1 -0
  124. package/build/lib/codec/lib/StringContentEncodingEnum.js +11 -0
  125. package/build/lib/codec/types/CodecData.d.ts +7 -0
  126. package/build/lib/codec/types/CodecData.d.ts.map +1 -0
  127. package/build/lib/codec/types/CodecData.js +2 -0
  128. package/build/lib/codec/types/CodecDecodeResult.d.ts +9 -0
  129. package/build/lib/codec/types/CodecDecodeResult.d.ts.map +1 -0
  130. package/build/lib/codec/types/CodecDecodeResult.js +2 -0
  131. package/build/lib/codec/types/CodecEncodeInput.d.ts +5 -0
  132. package/build/lib/codec/types/CodecEncodeInput.d.ts.map +1 -0
  133. package/build/lib/codec/types/CodecEncodeInput.js +2 -0
  134. package/build/lib/codec/types/CodecEncodeResult.d.ts +6 -0
  135. package/build/lib/codec/types/CodecEncodeResult.d.ts.map +1 -0
  136. package/build/lib/codec/types/CodecEncodeResult.js +2 -0
  137. package/build/lib/codec/types/CodecErrorInfo.d.ts +6 -0
  138. package/build/lib/codec/types/CodecErrorInfo.d.ts.map +1 -0
  139. package/build/lib/codec/types/CodecErrorInfo.js +2 -0
  140. package/build/lib/codec/types/CodecModule.d.ts +3 -0
  141. package/build/lib/codec/types/CodecModule.d.ts.map +1 -0
  142. package/build/lib/codec/types/CodecModule.js +2 -0
  143. package/build/lib/codec/types/CodecModuleConstructor.d.ts +3 -0
  144. package/build/lib/codec/types/CodecModuleConstructor.d.ts.map +1 -0
  145. package/build/lib/codec/types/CodecModuleConstructor.js +2 -0
  146. package/build/lib/codec/types/CodecSchema.d.ts +7 -0
  147. package/build/lib/codec/types/CodecSchema.d.ts.map +1 -0
  148. package/build/lib/codec/types/CodecSchema.js +2 -0
  149. package/build/lib/codec/types/HeaderTreeNode.d.ts +5 -0
  150. package/build/lib/codec/types/HeaderTreeNode.d.ts.map +1 -0
  151. package/build/lib/codec/types/HeaderTreeNode.js +2 -0
  152. package/build/lib/codec/types/PostHandlerItem.d.ts +5 -0
  153. package/build/lib/codec/types/PostHandlerItem.d.ts.map +1 -0
  154. package/build/lib/codec/types/PostHandlerItem.js +2 -0
  155. package/build/lib/nodepcap/Capture.d.ts +75 -0
  156. package/build/lib/nodepcap/Capture.d.ts.map +1 -0
  157. package/build/lib/nodepcap/Capture.js +309 -0
  158. package/build/lib/nodepcap/GetNetworkInterfaces.d.ts +7 -0
  159. package/build/lib/nodepcap/GetNetworkInterfaces.d.ts.map +1 -0
  160. package/build/lib/nodepcap/GetNetworkInterfaces.js +22 -0
  161. package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts +16 -0
  162. package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +1 -0
  163. package/build/lib/nodepcap/interfaces/IBindingCapture.js +2 -0
  164. package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +5 -0
  165. package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +1 -0
  166. package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.js +2 -0
  167. package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts +19 -0
  168. package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -0
  169. package/build/lib/nodepcap/interfaces/ICaptureOptions.js +2 -0
  170. package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts +5 -0
  171. package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +1 -0
  172. package/build/lib/nodepcap/interfaces/INetworkInterface.js +2 -0
  173. package/build/lib/nodepcap/lib/BindingCapture.d.ts +15 -0
  174. package/build/lib/nodepcap/lib/BindingCapture.d.ts.map +1 -0
  175. package/build/lib/nodepcap/lib/BindingCapture.js +35 -0
  176. package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts +2 -0
  177. package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +1 -0
  178. package/build/lib/nodepcap/lib/GetNodePcapBinding.js +55 -0
  179. package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +3 -0
  180. package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +1 -0
  181. package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.js +18 -0
  182. package/build/lib/nodepcap/workers/CaptureWorker.d.ts +2 -0
  183. package/build/lib/nodepcap/workers/CaptureWorker.d.ts.map +1 -0
  184. package/build/lib/nodepcap/workers/CaptureWorker.js +25 -0
  185. package/build/lib/pcap/PCAPGenerator.d.ts +34 -0
  186. package/build/lib/pcap/PCAPGenerator.d.ts.map +1 -0
  187. package/build/lib/pcap/PCAPGenerator.js +95 -0
  188. package/build/lib/pcap/PcapParser.d.ts +27 -0
  189. package/build/lib/pcap/PcapParser.d.ts.map +1 -0
  190. package/build/lib/pcap/PcapParser.js +149 -0
  191. package/build/lib/pcap/PcapReader.d.ts +87 -0
  192. package/build/lib/pcap/PcapReader.d.ts.map +1 -0
  193. package/build/lib/pcap/PcapReader.js +207 -0
  194. package/build/lib/pcap/PcapWriter.d.ts +29 -0
  195. package/build/lib/pcap/PcapWriter.d.ts.map +1 -0
  196. package/build/lib/pcap/PcapWriter.js +80 -0
  197. package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts +13 -0
  198. package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +1 -0
  199. package/build/lib/pcap/interfaces/IPcapPacketInfo.js +2 -0
  200. package/build/lib/pipe/PipeClient.d.ts +35 -0
  201. package/build/lib/pipe/PipeClient.d.ts.map +1 -0
  202. package/build/lib/pipe/PipeClient.js +71 -0
  203. package/build/lib/pipe/PipeClientSocket.d.ts +39 -0
  204. package/build/lib/pipe/PipeClientSocket.d.ts.map +1 -0
  205. package/build/lib/pipe/PipeClientSocket.js +82 -0
  206. package/build/lib/pipe/PipeMessage.d.ts +27 -0
  207. package/build/lib/pipe/PipeMessage.d.ts.map +1 -0
  208. package/build/lib/pipe/PipeMessage.js +61 -0
  209. package/build/lib/pipe/PipeMessageHandler.d.ts +16 -0
  210. package/build/lib/pipe/PipeMessageHandler.d.ts.map +1 -0
  211. package/build/lib/pipe/PipeMessageHandler.js +95 -0
  212. package/build/lib/pipe/PipeServer.d.ts +25 -0
  213. package/build/lib/pipe/PipeServer.d.ts.map +1 -0
  214. package/build/lib/pipe/PipeServer.js +59 -0
  215. package/build/lib/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  216. package/build/lib/schema/ProtocolFieldJSONSchema.d.ts.map +1 -0
  217. package/build/lib/schema/ProtocolFieldJSONSchema.js +2 -0
  218. package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +3 -0
  219. package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +1 -0
  220. package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  221. package/build/lib/schema/ProtocolJSONSchema.d.ts +32 -0
  222. package/build/lib/schema/ProtocolJSONSchema.d.ts.map +1 -0
  223. package/build/lib/schema/ProtocolJSONSchema.js +2 -0
  224. package/build/tests/Test.spec.d.ts +2 -0
  225. package/build/tests/Test.spec.d.ts.map +1 -0
  226. package/build/tests/Test.spec.js +25 -0
  227. package/build/tests/units/CaptureTest.spec.d.ts +2 -0
  228. package/build/tests/units/CaptureTest.spec.d.ts.map +1 -0
  229. package/build/tests/units/CaptureTest.spec.js +31 -0
  230. package/build/tests/units/Codec.spec.d.ts +2 -0
  231. package/build/tests/units/Codec.spec.d.ts.map +1 -0
  232. package/build/tests/units/Codec.spec.js +70 -0
  233. package/cpp/nodepcap/deps/include/Packet32.h +429 -0
  234. package/cpp/nodepcap/deps/include/pcap/bluetooth.h +56 -0
  235. package/cpp/nodepcap/deps/include/pcap/bpf.h +292 -0
  236. package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +56 -0
  237. package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +163 -0
  238. package/cpp/nodepcap/deps/include/pcap/dlt.h +1514 -0
  239. package/cpp/nodepcap/deps/include/pcap/funcattrs.h +325 -0
  240. package/cpp/nodepcap/deps/include/pcap/ipnet.h +43 -0
  241. package/cpp/nodepcap/deps/include/pcap/namedb.h +84 -0
  242. package/cpp/nodepcap/deps/include/pcap/nflog.h +94 -0
  243. package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +101 -0
  244. package/cpp/nodepcap/deps/include/pcap/pcap.h +1219 -0
  245. package/cpp/nodepcap/deps/include/pcap/sll.h +149 -0
  246. package/cpp/nodepcap/deps/include/pcap/socket.h +84 -0
  247. package/cpp/nodepcap/deps/include/pcap/usb.h +143 -0
  248. package/cpp/nodepcap/deps/include/pcap/vlan.h +46 -0
  249. package/cpp/nodepcap/deps/include/pcap-bpf.h +45 -0
  250. package/cpp/nodepcap/deps/include/pcap-namedb.h +40 -0
  251. package/cpp/nodepcap/deps/include/pcap.h +43 -0
  252. package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
  253. package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
  254. package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
  255. package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
  256. package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
  257. package/cpp/nodepcap/nodepcap.gypi +104 -0
  258. package/cpp/nodepcap/src/binding.cc +14 -0
  259. package/cpp/nodepcap/src/capture.cc +400 -0
  260. package/cpp/nodepcap/src/capture.h +53 -0
  261. package/cpp/nodepcap/src/utils.cc +218 -0
  262. package/cpp/nodepcap/src/utils.h +13 -0
  263. package/package.json +65 -0
  264. package/src/NetKitty.ts +31 -0
  265. package/src/errors/ActionNotFoundError.ts +6 -0
  266. package/src/errors/CodecSchemaValidateError.ts +6 -0
  267. package/src/errors/DeviceNotFoundError.ts +6 -0
  268. package/src/errors/NoAvailableCodecError.ts +6 -0
  269. package/src/errors/NpcapLoadError.ts +6 -0
  270. package/src/errors/SocketDownError.ts +6 -0
  271. package/src/errors/UnknownPipeMessageTypeError.ts +6 -0
  272. package/src/errors/common/ErrorCode.ts +30 -0
  273. package/src/lib/GeneratePipeAddress.ts +17 -0
  274. package/src/lib/GetBinding.ts +3 -0
  275. package/src/lib/GetCaptureTemporaryDirectory.ts +12 -0
  276. package/src/lib/GetDeviceCaptureTemporaryFilename.ts +13 -0
  277. package/src/lib/codec/Codec.ts +181 -0
  278. package/src/lib/codec/abstracts/BaseHeader.ts +413 -0
  279. package/src/lib/codec/headers/ARP.ts +218 -0
  280. package/src/lib/codec/headers/EthernetII.ts +77 -0
  281. package/src/lib/codec/headers/Goose.ts +658 -0
  282. package/src/lib/codec/headers/IEC61850SampledValues.ts +359 -0
  283. package/src/lib/codec/headers/IPv4.ts +329 -0
  284. package/src/lib/codec/headers/RawData.ts +34 -0
  285. package/src/lib/codec/headers/TCP.ts +931 -0
  286. package/src/lib/codec/headers/UDP.ts +180 -0
  287. package/src/lib/codec/headers/VLAN_802dot1Q.ts +74 -0
  288. package/src/lib/codec/lib/BufferToHex.ts +3 -0
  289. package/src/lib/codec/lib/BufferToIP.ts +19 -0
  290. package/src/lib/codec/lib/BufferToNumber.ts +31 -0
  291. package/src/lib/codec/lib/FixHexString.ts +8 -0
  292. package/src/lib/codec/lib/FlexibleObject.ts +100 -0
  293. package/src/lib/codec/lib/HexToNumber.ts +25 -0
  294. package/src/lib/codec/lib/IPToBuffer.ts +25 -0
  295. package/src/lib/codec/lib/NumberToBERBuffer.ts +19 -0
  296. package/src/lib/codec/lib/NumberToBERHex.ts +13 -0
  297. package/src/lib/codec/lib/NumberToBuffer.ts +21 -0
  298. package/src/lib/codec/lib/NumberToHex.ts +15 -0
  299. package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +53 -0
  300. package/src/lib/codec/lib/SortPostHandlers.ts +10 -0
  301. package/src/lib/codec/lib/StringContentEncodingEnum.ts +7 -0
  302. package/src/lib/codec/types/CodecData.ts +7 -0
  303. package/src/lib/codec/types/CodecDecodeResult.ts +9 -0
  304. package/src/lib/codec/types/CodecEncodeInput.ts +5 -0
  305. package/src/lib/codec/types/CodecEncodeResult.ts +6 -0
  306. package/src/lib/codec/types/CodecErrorInfo.ts +5 -0
  307. package/src/lib/codec/types/CodecModule.ts +3 -0
  308. package/src/lib/codec/types/CodecModuleConstructor.ts +3 -0
  309. package/src/lib/codec/types/CodecSchema.ts +7 -0
  310. package/src/lib/codec/types/HeaderTreeNode.ts +5 -0
  311. package/src/lib/codec/types/PostHandlerItem.ts +4 -0
  312. package/src/lib/nodepcap/Capture.ts +291 -0
  313. package/src/lib/nodepcap/GetNetworkInterfaces.ts +18 -0
  314. package/src/lib/nodepcap/interfaces/IBindingCapture.ts +27 -0
  315. package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +4 -0
  316. package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +19 -0
  317. package/src/lib/nodepcap/interfaces/INetworkInterface.ts +4 -0
  318. package/src/lib/nodepcap/lib/BindingCapture.ts +46 -0
  319. package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +17 -0
  320. package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +15 -0
  321. package/src/lib/nodepcap/workers/CaptureWorker.ts +30 -0
  322. package/src/lib/pcap/PCAPGenerator.ts +118 -0
  323. package/src/lib/pcap/PcapParser.ts +170 -0
  324. package/src/lib/pcap/PcapReader.ts +239 -0
  325. package/src/lib/pcap/PcapWriter.ts +93 -0
  326. package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +12 -0
  327. package/src/lib/pipe/PipeClient.ts +91 -0
  328. package/src/lib/pipe/PipeClientSocket.ts +99 -0
  329. package/src/lib/pipe/PipeMessage.ts +74 -0
  330. package/src/lib/pipe/PipeMessageHandler.ts +91 -0
  331. package/src/lib/pipe/PipeServer.ts +74 -0
  332. package/src/lib/schema/ProtocolFieldJSONSchema.ts +45 -0
  333. package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +3 -0
  334. package/src/lib/schema/ProtocolJSONSchema.ts +37 -0
  335. package/src/tests/Test.spec.ts +22 -0
  336. package/src/tests/units/CaptureTest.spec.ts +30 -0
  337. package/src/tests/units/Codec.spec.ts +85 -0
  338. package/tsconfig.json +41 -0
@@ -0,0 +1,413 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {CodecModule} from '../types/CodecModule'
3
+ import {ProtocolFieldJSONSchema} from '../../schema/ProtocolFieldJSONSchema'
4
+ import {CodecErrorInfo} from '../types/CodecErrorInfo'
5
+ import {PostHandlerItem} from '../types/PostHandlerItem'
6
+ import {SortPostHandlers} from '../lib/SortPostHandlers'
7
+ import {CodecData} from '../types/CodecData'
8
+ import {FlexibleObject} from '../lib/FlexibleObject'
9
+ import {Ajv, ErrorObject, ValidateFunction} from 'ajv'
10
+ import {HeaderTreeNode} from '../types/HeaderTreeNode'
11
+ import {CodecSchemaValidateError} from '../../../errors/CodecSchemaValidateError'
12
+
13
+ const CONSTRUCTOR_VALIDATE_KEY: string = '__validate'
14
+
15
+ export abstract class BaseHeader {
16
+
17
+ protected static get CODEC_INSTANCE(): CodecModule {
18
+ return new (this as any)()
19
+ }
20
+
21
+ protected static CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules: CodecModule[]): CodecModule {
22
+ return new (this as any)(undefined, codecModules, [])
23
+ }
24
+
25
+ public static get PROTOCOL_ID(): string {
26
+ return this.CODEC_INSTANCE.id
27
+ }
28
+
29
+ public static get PROTOCOL_NAME(): string {
30
+ return this.CODEC_INSTANCE.name
31
+ }
32
+
33
+ public static get PROTOCOL_SCHEMA(): ProtocolJSONSchema {
34
+ const schema: ProtocolJSONSchema = JSON.parse(JSON.stringify(this.CODEC_INSTANCE.SCHEMA))
35
+ if (!Object.hasOwn(this, CONSTRUCTOR_VALIDATE_KEY)) {
36
+ const validate: ValidateFunction = new Ajv({
37
+ strict: false,
38
+ useDefaults: true,
39
+ coerceTypes: true
40
+ }).compile(schema)
41
+ Object.defineProperty(this, CONSTRUCTOR_VALIDATE_KEY, {
42
+ enumerable: false,
43
+ configurable: false,
44
+ value: validate
45
+ })
46
+ }
47
+ return schema
48
+ }
49
+
50
+ public static MATCH(codecModules: CodecModule[]): boolean {
51
+ return this.CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules ? codecModules : []).match()
52
+ }
53
+
54
+ public static CREATE_INSTANCE(codecData: CodecData, codecModules: CodecModule[]): CodecModule {
55
+ return new (this as any)(codecData, codecModules)
56
+ }
57
+
58
+ /**
59
+ * Protocol schema definition
60
+ */
61
+ public readonly abstract SCHEMA: ProtocolJSONSchema
62
+
63
+ /**
64
+ * Program used header id
65
+ */
66
+ public readonly abstract id: string
67
+
68
+ /**
69
+ * Human-readable header name
70
+ */
71
+ public readonly abstract name: string
72
+
73
+ /**
74
+ * Encode/Decode error info objects
75
+ */
76
+ public errors: CodecErrorInfo[] = []
77
+
78
+ /**
79
+ * Header schema instance
80
+ */
81
+ public instance: FlexibleObject = new FlexibleObject()
82
+
83
+ /**
84
+ * Entire packet buffer data getter
85
+ */
86
+ public get packet(): Buffer {
87
+ return this.codecData.packet
88
+ }
89
+
90
+ /**
91
+ * Entire packet buffer data setter
92
+ * @param packet
93
+ */
94
+ public set packet(packet: Buffer) {
95
+ this.codecData.packet = packet
96
+ }
97
+
98
+ /**
99
+ * The start position of this header in the entire packet's buffer
100
+ */
101
+ public startPos: number = 0
102
+
103
+ /**
104
+ * The end position of this header in the entire packet's buffer
105
+ */
106
+ public get endPos(): number {
107
+ return this.startPos + this.headerLength
108
+ }
109
+
110
+ /**
111
+ * Readonly Header length
112
+ */
113
+ public get length(): number {
114
+ return this.headerLength
115
+ }
116
+
117
+ /**
118
+ * Header length
119
+ * @protected
120
+ */
121
+ protected headerLength: number = 0
122
+
123
+ /**
124
+ * Previous Codec module
125
+ * @protected
126
+ */
127
+ protected readonly prevCodecModule: CodecModule
128
+
129
+ /**
130
+ * Codec modules
131
+ * @protected
132
+ */
133
+ protected readonly codecModules: CodecModule[]
134
+
135
+ /**
136
+ * Previous codec modules
137
+ * @protected
138
+ */
139
+ protected readonly prevCodecModules: CodecModule[]
140
+
141
+ /**
142
+ * Current header index in packet headers
143
+ * @protected
144
+ */
145
+ protected readonly headerIndex: number = 0
146
+
147
+ protected get postPacketHandlers(): PostHandlerItem[] {
148
+ if (this.codecData.postHandlers[this.headerIndex] === undefined) this.codecData.postHandlers[this.headerIndex] = []
149
+ return this.codecData.postHandlers[this.headerIndex]
150
+ }
151
+
152
+ /**
153
+ * Registered post encode handlers (CodecModule)
154
+ * @protected
155
+ */
156
+ protected readonly postSelfEncodeHandlers: PostHandlerItem[] = []
157
+
158
+ /**
159
+ * Registered post decode handlers (CodecModule)
160
+ * @protected
161
+ */
162
+ protected readonly postSelfDecodeHandlers: PostHandlerItem[] = []
163
+
164
+ /**
165
+ * Codec data
166
+ * @protected
167
+ */
168
+ protected readonly codecData: CodecData
169
+
170
+ constructor(codecData: CodecData, codecModules: CodecModule[]) {
171
+ this.codecData = codecData
172
+ this.startPos = codecData?.startPos ? codecData.startPos : 0
173
+ codecModules = codecModules ? codecModules : []
174
+ this.codecModules = codecModules
175
+ this.prevCodecModules = [...codecModules]
176
+ const prevCodecModuleIndex: number = this.prevCodecModules.length - 1
177
+ this.prevCodecModule = this.prevCodecModules[prevCodecModuleIndex > -1 ? prevCodecModuleIndex : 0]
178
+ this.headerIndex = this.prevCodecModules.length
179
+ }
180
+
181
+ /**
182
+ * Get packet data offset
183
+ * @param offset
184
+ * @protected
185
+ */
186
+ protected getPacketOffset(offset: number): number {
187
+ return this.startPos + offset
188
+ }
189
+
190
+ /**
191
+ * Is data buffer fits current header codec
192
+ */
193
+ public abstract match(): boolean
194
+
195
+ /**
196
+ * Internal read bytes from buffer
197
+ * @param offset
198
+ * @param length
199
+ * @param expandBufferLength
200
+ * @private
201
+ */
202
+ #readBytes(offset: number, length: number, expandBufferLength: boolean): Buffer {
203
+ const packetOffset: number = this.getPacketOffset(offset)
204
+ const readEndPos: number = packetOffset + length
205
+ if (this.packet.length < readEndPos && expandBufferLength) this.packet = Buffer.concat([this.packet, Buffer.alloc(readEndPos - this.packet.length, 0)])
206
+ const headerLength: number = readEndPos - this.startPos
207
+ this.headerLength = this.headerLength < headerLength ? headerLength : this.headerLength
208
+ return this.packet.subarray(packetOffset, packetOffset + length)
209
+ }
210
+
211
+ /**
212
+ * Read bytes from buffer
213
+ * @param offset
214
+ * @param length
215
+ * @protected
216
+ */
217
+ protected readBytes(offset: number, length: number): Buffer {
218
+ return this.#readBytes(offset, length, false)
219
+ }
220
+
221
+ /**
222
+ * Write bytes to buffer
223
+ * @param offset
224
+ * @param buffer
225
+ * @protected
226
+ */
227
+ protected writeBytes(offset: number, buffer: Buffer): void {
228
+ const packetOffset: number = this.getPacketOffset(offset)
229
+ const writeEndPos: number = packetOffset + buffer.length
230
+ this.#readBytes(offset, buffer.length, true)
231
+ this.packet.fill(buffer, packetOffset, writeEndPos)
232
+ }
233
+
234
+ /**
235
+ * Read bits from buffer
236
+ * @param offset
237
+ * @param length
238
+ * @param bitOffset
239
+ * @param bitLength
240
+ * @protected
241
+ */
242
+ protected readBits(offset: number, length: number, bitOffset: number, bitLength: number): number {
243
+ const buffer: Buffer = this.#readBytes(offset, length, false)
244
+ const bitString: string = parseInt(buffer.toString('hex'), 16).toString(2).padStart(length * 8, '0')
245
+ return parseInt(bitString.substring(bitOffset, bitOffset + bitLength), 2)
246
+ }
247
+
248
+ /**
249
+ * Write bits to buffer
250
+ * @param offset
251
+ * @param length
252
+ * @param bitOffset
253
+ * @param bitLength
254
+ * @param value
255
+ * @protected
256
+ */
257
+ protected writeBits(offset: number, length: number, bitOffset: number, bitLength: number, value: number): void {
258
+ const buffer: Buffer = this.#readBytes(offset, length, true)
259
+ let bitArray: string[] = Array.from(parseInt(buffer.toString('hex'), 16).toString(2).padStart(buffer.length * 8, '0'))
260
+ const valueBitArray: string[] = Array.from(value.toString(2).padStart(bitLength, '0'))
261
+ bitArray = bitArray.map((bit: string, index: number): string => {
262
+ if (index < bitOffset) return bit
263
+ if (index >= (bitOffset + bitLength)) return bit
264
+ return valueBitArray[index - bitOffset]
265
+ })
266
+ this.writeBytes(offset, Buffer.from(parseInt(bitArray.join(''), 2).toString(16).padStart(buffer.length * 2, '0'), 'hex'))
267
+ }
268
+
269
+ /**
270
+ * Get field codecs from schema tree
271
+ * @param schema
272
+ * @param codecName
273
+ * @param execBeforeSubCodecs
274
+ * @param codecs
275
+ * @protected
276
+ */
277
+ protected getFieldCodecs(schema: ProtocolFieldJSONSchema, codecName: string, execBeforeSubCodecs: boolean, codecs: (() => Promise<void>)[] = []): (() => Promise<void>)[] {
278
+ if (!schema.properties) return codecs
279
+ for (const propertyName of Object.keys(schema.properties)) {
280
+ const fieldSchema: ProtocolFieldJSONSchema = schema.properties[propertyName]
281
+ let codec: (() => void | Promise<void>) | undefined = fieldSchema[codecName]
282
+ if (!codec) codec = async (): Promise<void> => (void (0))
283
+ if (execBeforeSubCodecs) codecs.push(async (): Promise<void> => await codec())
284
+ if (fieldSchema.properties) this.getFieldCodecs(fieldSchema, codecName, execBeforeSubCodecs, codecs)
285
+ if (!execBeforeSubCodecs) codecs.push(async (): Promise<void> => await codec())
286
+ }
287
+ return codecs
288
+ }
289
+
290
+ /**
291
+ * Record encode/decode error
292
+ * @param path
293
+ * @param message
294
+ * @protected
295
+ */
296
+ protected recordError(path: string, message: string): void {
297
+ this.errors.push({
298
+ id: this.id,
299
+ path: path,
300
+ message: message
301
+ })
302
+ }
303
+
304
+ /**
305
+ * Register post encode handler for current codec
306
+ * @param handler
307
+ * @param priority
308
+ * @protected
309
+ */
310
+ protected addPostSelfEncodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
311
+ this.postSelfEncodeHandlers.push({
312
+ priority: priority,
313
+ handler: handler
314
+ })
315
+ }
316
+
317
+ /**
318
+ * Register post decode handler for current codec
319
+ * @param handler
320
+ * @param priority
321
+ * @protected
322
+ */
323
+ protected addPostSelfDecodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
324
+ this.postSelfDecodeHandlers.push({
325
+ priority: priority,
326
+ handler: handler
327
+ })
328
+ }
329
+
330
+ /**
331
+ * Register post encode handler for packet
332
+ * @description Registered handler call sequence: LIFO (Last In First Out)
333
+ * @param handler
334
+ * @param priority
335
+ * @protected
336
+ */
337
+ protected addPostPacketEncodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
338
+ this.postPacketHandlers.push({
339
+ priority: priority,
340
+ handler: handler
341
+ })
342
+ }
343
+
344
+ /**
345
+ * Register post decode handler for packet
346
+ * @description Registered handler call sequence: FIFO (First In First Out)
347
+ * @param handler
348
+ * @param priority
349
+ * @protected
350
+ */
351
+ protected addPostPacketDecodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
352
+ this.postPacketHandlers.push({
353
+ priority: priority,
354
+ handler: handler
355
+ })
356
+ }
357
+
358
+ /**
359
+ * Validate input json node is valid
360
+ * @param headerTreeNode
361
+ */
362
+ public validate(headerTreeNode: HeaderTreeNode): HeaderTreeNode {
363
+ let validate: ValidateFunction = this.constructor[CONSTRUCTOR_VALIDATE_KEY]
364
+ if (!validate) {
365
+ validate = new Ajv({
366
+ strict: false,
367
+ useDefaults: true,
368
+ coerceTypes: true
369
+ }).compile(this.SCHEMA)
370
+ this.constructor[CONSTRUCTOR_VALIDATE_KEY] = validate
371
+ }
372
+ const isValid: boolean = validate(headerTreeNode)
373
+ if (!isValid) {
374
+ let errorObject: ErrorObject | undefined | null
375
+ if (validate.errors) errorObject = validate.errors[0]
376
+ const errorMessage: string = errorObject?.message ? errorObject.message : 'Unknown Error'
377
+ throw new CodecSchemaValidateError(errorMessage)
378
+ }
379
+ return headerTreeNode
380
+ }
381
+
382
+ /**
383
+ * Decode packet header field by field
384
+ */
385
+ public async decode(): Promise<void> {
386
+ const decodes: (() => Promise<void>)[] = this.getFieldCodecs(this.SCHEMA as ProtocolFieldJSONSchema, 'decode', true)
387
+ for (const decode of decodes) {
388
+ await decode()
389
+ }
390
+ const postSelfDecodeHandlers: PostHandlerItem[] = SortPostHandlers(this.postSelfDecodeHandlers)
391
+ let postDecodeHandler: PostHandlerItem | undefined = postSelfDecodeHandlers.shift()
392
+ while (postDecodeHandler) {
393
+ await postDecodeHandler.handler()
394
+ postDecodeHandler = postSelfDecodeHandlers.shift()
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Encode packet header field by field
400
+ */
401
+ public async encode(): Promise<void> {
402
+ const encodes: (() => Promise<void>)[] = this.getFieldCodecs(this.SCHEMA as ProtocolFieldJSONSchema, 'encode', false)
403
+ for (const encode of encodes) {
404
+ await encode()
405
+ }
406
+ const postSelfEncodeHandlers: PostHandlerItem[] = SortPostHandlers(this.postSelfEncodeHandlers)
407
+ let postEncodeHandler: PostHandlerItem | undefined = postSelfEncodeHandlers.shift()
408
+ while (postEncodeHandler) {
409
+ await postEncodeHandler.handler()
410
+ postEncodeHandler = postSelfEncodeHandlers.shift()
411
+ }
412
+ }
413
+ }
@@ -0,0 +1,218 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {BaseHeader} from '../abstracts/BaseHeader'
3
+ import {UInt16ToHex, UInt8ToHex} from '../lib/NumberToHex'
4
+ import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
5
+ import {HexToUInt16} from '../lib/HexToNumber'
6
+ import {BufferToInt16, BufferToUInt16, BufferToUInt8} from '../lib/BufferToNumber'
7
+ import {BufferToHex} from '../lib/BufferToHex'
8
+ import {UInt16ToBuffer, UInt8ToBuffer} from '../lib/NumberToBuffer'
9
+ import {BufferToIPv4} from '../lib/BufferToIP'
10
+ import {IPv4ToBuffer} from '../lib/IPToBuffer'
11
+
12
+ export class ARP extends BaseHeader {
13
+
14
+ public SCHEMA: ProtocolJSONSchema = {
15
+ type: 'object',
16
+ properties: {
17
+ hardware: {
18
+ type: 'object',
19
+ label: 'Hardware',
20
+ properties: {
21
+ type: {
22
+ type: 'number',
23
+ label: 'Type',
24
+ minimum: 0,
25
+ maximum: 65535,
26
+ decode: (): void => {
27
+ this.instance.hardware.type.setValue(BufferToInt16(this.readBytes(0, 2)))
28
+ },
29
+ encode: (): void => {
30
+ let hwType: number = this.instance.hardware.type.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
31
+ if (hwType > 65535) {
32
+ this.recordError(this.instance.hardware.type.getPath(), 'Maximum value is 65535')
33
+ hwType = 65535
34
+ }
35
+ if (hwType < 0) {
36
+ this.recordError(this.instance.hardware.type.getPath(), 'Minimum value is 0')
37
+ hwType = 0
38
+ }
39
+ this.instance.hardware.type.setValue(hwType)
40
+ this.writeBytes(0, UInt16ToBuffer(hwType))
41
+ }
42
+ },
43
+ size: {
44
+ type: 'number',
45
+ label: 'Size',
46
+ minimum: 0,
47
+ maximum: 255,
48
+ decode: (): void => {
49
+ this.instance.hardware.size.setValue(BufferToUInt8(this.readBytes(4, 1)))
50
+ },
51
+ encode: (): void => {
52
+ let hwSize: number = this.instance.hardware.size.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
53
+ if (hwSize > 255) {
54
+ this.recordError(this.instance.hardware.size.getPath(), 'Maximum value is 255')
55
+ hwSize = 255
56
+ }
57
+ if (hwSize < 0) {
58
+ this.recordError(this.instance.hardware.size.getPath(), 'Minimum value is 0')
59
+ hwSize = 0
60
+ }
61
+ this.instance.hardware.size.setValue(hwSize)
62
+ this.writeBytes(4, UInt8ToBuffer(hwSize))
63
+ }
64
+ }
65
+ }
66
+ },
67
+ protocol: {
68
+ type: 'object',
69
+ label: 'Protocol',
70
+ properties: {
71
+ type: {
72
+ type: 'string',
73
+ label: 'Type',
74
+ minLength: 4,
75
+ maxLength: 4,
76
+ contentEncoding: StringContentEncodingEnum.HEX,
77
+ decode: (): void => {
78
+ this.instance.protocol.type.setValue(BufferToHex(this.readBytes(2, 2)))
79
+ },
80
+ encode: (): void => {
81
+ let protoTypeHex: string = this.instance.protocol.type.getValue('0000', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
82
+ let protoType: number = HexToUInt16(protoTypeHex)
83
+ if (isNaN(protoType)) {
84
+ this.recordError(this.instance.protocol.type.getPath(), 'Invalid hex value')
85
+ protoType = 0
86
+ }
87
+ this.instance.protocol.type.setValue(protoType)
88
+ this.writeBytes(2, UInt16ToBuffer(protoType))
89
+ }
90
+ },
91
+ size: {
92
+ type: 'number',
93
+ label: 'Size',
94
+ minimum: 0,
95
+ maximum: 255,
96
+ decode: (): void => {
97
+ this.instance.protocol.size.setValue(BufferToUInt8(this.readBytes(5, 1)))
98
+ },
99
+ encode: (): void => {
100
+ let protoSize: number = this.instance.protocol.size.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
101
+ if (protoSize > 255) {
102
+ this.recordError(this.instance.protocol.size.getPath(), 'Maximum value is 255')
103
+ protoSize = 255
104
+ }
105
+ if (protoSize < 0) {
106
+ this.recordError(this.instance.protocol.size.getPath(), 'Minimum value is 0')
107
+ protoSize = 0
108
+ }
109
+ this.instance.protocol.size.setValue(protoSize)
110
+ this.writeBytes(5, UInt8ToBuffer(protoSize))
111
+ }
112
+ }
113
+ }
114
+ },
115
+ opcode: {
116
+ type: 'number',
117
+ label: 'Opcode',
118
+ enum: [1, 2, 3, 4],
119
+ decode: (): void => {
120
+ this.instance.opcode.setValue(BufferToUInt16(this.readBytes(6, 2)))
121
+ if (![1, 2, 3, 4].includes(this.instance.opcode.getValue())) this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4')
122
+ },
123
+ encode: (): void => {
124
+ let opcode: number = this.instance.opcode.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
125
+ if (![1, 2, 3, 4].includes(opcode)) this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4')
126
+ this.instance.opcode.setValue(opcode)
127
+ this.writeBytes(6, UInt16ToBuffer(opcode))
128
+ }
129
+ },
130
+ sender: {
131
+ type: 'object',
132
+ label: 'Sender',
133
+ properties: {
134
+ mac: {
135
+ type: 'string',
136
+ label: 'MAC address',
137
+ minLength: 17,
138
+ maxLength: 17,
139
+ contentEncoding: StringContentEncodingEnum.UTF8,
140
+ decode: (): void => {
141
+ const macAddrBuffer: Buffer = Buffer.alloc(6, this.readBytes(8, 6))
142
+ this.instance.sender.mac.setValue(Array.from(macAddrBuffer).map((value: number): string => UInt8ToHex(value)).join(':'))
143
+ },
144
+ encode: (): void => {
145
+ let macStr: string = this.instance.sender.mac.getValue()
146
+ const rawMacBuffer: Buffer = Buffer.from(macStr.split(':').map((value: string): number => parseInt(value, 16)).map((value: number): number => value ? value : 0))
147
+ if (rawMacBuffer.length !== 6) this.recordError(this.instance.sender.mac.getPath(), 'Invalid MAC address length')
148
+ this.writeBytes(8, Buffer.alloc(6, rawMacBuffer))
149
+ }
150
+ },
151
+ ipv4: {
152
+ type: 'string',
153
+ label: 'IP address',
154
+ minLength: 7,
155
+ maxLength: 15,
156
+ contentEncoding: StringContentEncodingEnum.UTF8,
157
+ decode: (): void => {
158
+ const ipv4Buffer: Buffer = Buffer.alloc(4, this.readBytes(14, 4))
159
+ this.instance.sender.ipv4.setValue(BufferToIPv4(ipv4Buffer))
160
+ },
161
+ encode: (): void => {
162
+ let ipv4Str: string = this.instance.sender.ipv4.getValue()
163
+ this.writeBytes(14, IPv4ToBuffer(ipv4Str))
164
+ }
165
+ }
166
+ }
167
+ },
168
+ target: {
169
+ type: 'object',
170
+ label: 'Target',
171
+ properties: {
172
+ mac: {
173
+ type: 'string',
174
+ label: 'MAC address',
175
+ minLength: 17,
176
+ maxLength: 17,
177
+ contentEncoding: StringContentEncodingEnum.UTF8,
178
+ decode: (): void => {
179
+ const macAddrBuffer: Buffer = Buffer.alloc(6, this.readBytes(18, 6))
180
+ this.instance.target.mac.setValue(Array.from(macAddrBuffer).map((value: number): string => UInt8ToHex(value)).join(':'))
181
+ },
182
+ encode: (): void => {
183
+ let macStr: string = this.instance.target.mac.getValue()
184
+ const rawMacBuffer: Buffer = Buffer.from(macStr.split(':').map((value: string): number => parseInt(value, 16)).map((value: number): number => value ? value : 0))
185
+ if (rawMacBuffer.length !== 6) this.recordError(this.instance.target.mac.getPath(), 'Invalid MAC address length')
186
+ this.writeBytes(18, Buffer.alloc(6, rawMacBuffer))
187
+ }
188
+ },
189
+ ipv4: {
190
+ type: 'string',
191
+ label: 'IP address',
192
+ minLength: 7,
193
+ maxLength: 15,
194
+ contentEncoding: StringContentEncodingEnum.UTF8,
195
+ decode: (): void => {
196
+ const ipv4Buffer: Buffer = Buffer.alloc(4, this.readBytes(24, 4))
197
+ this.instance.target.ipv4.setValue(BufferToIPv4(ipv4Buffer))
198
+ },
199
+ encode: (): void => {
200
+ let ipv4Str: string = this.instance.target.ipv4.getValue()
201
+ this.writeBytes(24, IPv4ToBuffer(ipv4Str))
202
+ }
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ public id: string = 'arp'
210
+
211
+ public name: string = 'Address Resolution Protocol'
212
+
213
+ public match(): boolean {
214
+ if (!this.prevCodecModule) return false
215
+ return this.prevCodecModule.instance.etherType.getValue() === UInt16ToHex(0x0806)
216
+ }
217
+
218
+ }