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.
- package/.eslintrc.json +53 -0
- package/.idea/codeStyles/Project.xml +18 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/netkitty.iml +13 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/binding.gyp +5 -0
- package/build/NetKitty.d.ts +31 -0
- package/build/NetKitty.d.ts.map +1 -0
- package/build/NetKitty.js +33 -0
- package/build/errors/ActionNotFoundError.d.ts +5 -0
- package/build/errors/ActionNotFoundError.d.ts.map +1 -0
- package/build/errors/ActionNotFoundError.js +12 -0
- package/build/errors/CodecSchemaValidateError.d.ts +5 -0
- package/build/errors/CodecSchemaValidateError.d.ts.map +1 -0
- package/build/errors/CodecSchemaValidateError.js +12 -0
- package/build/errors/DeviceNotFoundError.d.ts +5 -0
- package/build/errors/DeviceNotFoundError.d.ts.map +1 -0
- package/build/errors/DeviceNotFoundError.js +12 -0
- package/build/errors/NoAvailableCodecError.d.ts +5 -0
- package/build/errors/NoAvailableCodecError.d.ts.map +1 -0
- package/build/errors/NoAvailableCodecError.js +12 -0
- package/build/errors/NpcapLoadError.d.ts +5 -0
- package/build/errors/NpcapLoadError.d.ts.map +1 -0
- package/build/errors/NpcapLoadError.js +12 -0
- package/build/errors/SocketDownError.d.ts +5 -0
- package/build/errors/SocketDownError.d.ts.map +1 -0
- package/build/errors/SocketDownError.js +12 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts +5 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts.map +1 -0
- package/build/errors/UnknownPipeMessageTypeError.js +12 -0
- package/build/errors/common/ErrorCode.d.ts +31 -0
- package/build/errors/common/ErrorCode.d.ts.map +1 -0
- package/build/errors/common/ErrorCode.js +33 -0
- package/build/lib/GeneratePipeAddress.d.ts +7 -0
- package/build/lib/GeneratePipeAddress.d.ts.map +1 -0
- package/build/lib/GeneratePipeAddress.js +23 -0
- package/build/lib/GetBinding.d.ts +2 -0
- package/build/lib/GetBinding.d.ts.map +1 -0
- package/build/lib/GetBinding.js +6 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts +7 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts.map +1 -0
- package/build/lib/GetCaptureTemporaryDirectory.js +15 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts +8 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +1 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.js +18 -0
- package/build/lib/codec/Codec.d.ts +33 -0
- package/build/lib/codec/Codec.d.ts.map +1 -0
- package/build/lib/codec/Codec.js +166 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts +204 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts.map +1 -0
- package/build/lib/codec/abstracts/BaseHeader.js +339 -0
- package/build/lib/codec/headers/ARP.d.ts +9 -0
- package/build/lib/codec/headers/ARP.d.ts.map +1 -0
- package/build/lib/codec/headers/ARP.js +223 -0
- package/build/lib/codec/headers/EthernetII.d.ts +9 -0
- package/build/lib/codec/headers/EthernetII.d.ts.map +1 -0
- package/build/lib/codec/headers/EthernetII.js +80 -0
- package/build/lib/codec/headers/Goose.d.ts +12 -0
- package/build/lib/codec/headers/Goose.d.ts.map +1 -0
- package/build/lib/codec/headers/Goose.js +701 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts +12 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts.map +1 -0
- package/build/lib/codec/headers/IEC61850SampledValues.js +369 -0
- package/build/lib/codec/headers/IPv4.d.ts +15 -0
- package/build/lib/codec/headers/IPv4.d.ts.map +1 -0
- package/build/lib/codec/headers/IPv4.js +338 -0
- package/build/lib/codec/headers/RawData.d.ts +9 -0
- package/build/lib/codec/headers/RawData.d.ts.map +1 -0
- package/build/lib/codec/headers/RawData.js +34 -0
- package/build/lib/codec/headers/TCP.d.ts +15 -0
- package/build/lib/codec/headers/TCP.d.ts.map +1 -0
- package/build/lib/codec/headers/TCP.js +897 -0
- package/build/lib/codec/headers/UDP.d.ts +15 -0
- package/build/lib/codec/headers/UDP.d.ts.map +1 -0
- package/build/lib/codec/headers/UDP.js +191 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts +9 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts.map +1 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.js +77 -0
- package/build/lib/codec/lib/BufferToHex.d.ts +2 -0
- package/build/lib/codec/lib/BufferToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToHex.js +6 -0
- package/build/lib/codec/lib/BufferToIP.d.ts +13 -0
- package/build/lib/codec/lib/BufferToIP.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToIP.js +21 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts +10 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToNumber.js +22 -0
- package/build/lib/codec/lib/FixHexString.d.ts +7 -0
- package/build/lib/codec/lib/FixHexString.d.ts.map +1 -0
- package/build/lib/codec/lib/FixHexString.js +11 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts +28 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts.map +1 -0
- package/build/lib/codec/lib/FlexibleObject.js +102 -0
- package/build/lib/codec/lib/HexToNumber.d.ts +10 -0
- package/build/lib/codec/lib/HexToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/HexToNumber.js +39 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts +13 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/IPToBuffer.js +28 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERBuffer.js +20 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERHex.js +23 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts +10 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBuffer.js +22 -0
- package/build/lib/codec/lib/NumberToHex.d.ts +10 -0
- package/build/lib/codec/lib/NumberToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToHex.js +26 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts +14 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.js +53 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts +8 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/SortPostHandlers.js +11 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts +8 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts.map +1 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.js +11 -0
- package/build/lib/codec/types/CodecData.d.ts +7 -0
- package/build/lib/codec/types/CodecData.d.ts.map +1 -0
- package/build/lib/codec/types/CodecData.js +2 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts +9 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecDecodeResult.js +2 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts +5 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeInput.js +2 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts +6 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeResult.js +2 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts +6 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts.map +1 -0
- package/build/lib/codec/types/CodecErrorInfo.js +2 -0
- package/build/lib/codec/types/CodecModule.d.ts +3 -0
- package/build/lib/codec/types/CodecModule.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModule.js +2 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts +3 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModuleConstructor.js +2 -0
- package/build/lib/codec/types/CodecSchema.d.ts +7 -0
- package/build/lib/codec/types/CodecSchema.d.ts.map +1 -0
- package/build/lib/codec/types/CodecSchema.js +2 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts +5 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts.map +1 -0
- package/build/lib/codec/types/HeaderTreeNode.js +2 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts +5 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts.map +1 -0
- package/build/lib/codec/types/PostHandlerItem.js +2 -0
- package/build/lib/nodepcap/Capture.d.ts +75 -0
- package/build/lib/nodepcap/Capture.d.ts.map +1 -0
- package/build/lib/nodepcap/Capture.js +309 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts +7 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts.map +1 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.js +22 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts +16 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.js +2 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts +19 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.js +2 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts +15 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/BindingCapture.js +35 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts +2 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.js +55 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +3 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.js +18 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts +2 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts.map +1 -0
- package/build/lib/nodepcap/workers/CaptureWorker.js +25 -0
- package/build/lib/pcap/PCAPGenerator.d.ts +34 -0
- package/build/lib/pcap/PCAPGenerator.d.ts.map +1 -0
- package/build/lib/pcap/PCAPGenerator.js +95 -0
- package/build/lib/pcap/PcapParser.d.ts +27 -0
- package/build/lib/pcap/PcapParser.d.ts.map +1 -0
- package/build/lib/pcap/PcapParser.js +149 -0
- package/build/lib/pcap/PcapReader.d.ts +87 -0
- package/build/lib/pcap/PcapReader.d.ts.map +1 -0
- package/build/lib/pcap/PcapReader.js +207 -0
- package/build/lib/pcap/PcapWriter.d.ts +29 -0
- package/build/lib/pcap/PcapWriter.d.ts.map +1 -0
- package/build/lib/pcap/PcapWriter.js +80 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts +13 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +1 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.js +2 -0
- package/build/lib/pipe/PipeClient.d.ts +35 -0
- package/build/lib/pipe/PipeClient.d.ts.map +1 -0
- package/build/lib/pipe/PipeClient.js +71 -0
- package/build/lib/pipe/PipeClientSocket.d.ts +39 -0
- package/build/lib/pipe/PipeClientSocket.d.ts.map +1 -0
- package/build/lib/pipe/PipeClientSocket.js +82 -0
- package/build/lib/pipe/PipeMessage.d.ts +27 -0
- package/build/lib/pipe/PipeMessage.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessage.js +61 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts +16 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessageHandler.js +95 -0
- package/build/lib/pipe/PipeServer.d.ts +25 -0
- package/build/lib/pipe/PipeServer.d.ts.map +1 -0
- package/build/lib/pipe/PipeServer.js +59 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts +35 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.js +2 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +3 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts +32 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolJSONSchema.js +2 -0
- package/build/tests/Test.spec.d.ts +2 -0
- package/build/tests/Test.spec.d.ts.map +1 -0
- package/build/tests/Test.spec.js +25 -0
- package/build/tests/units/CaptureTest.spec.d.ts +2 -0
- package/build/tests/units/CaptureTest.spec.d.ts.map +1 -0
- package/build/tests/units/CaptureTest.spec.js +31 -0
- package/build/tests/units/Codec.spec.d.ts +2 -0
- package/build/tests/units/Codec.spec.d.ts.map +1 -0
- package/build/tests/units/Codec.spec.js +70 -0
- package/cpp/nodepcap/deps/include/Packet32.h +429 -0
- package/cpp/nodepcap/deps/include/pcap/bluetooth.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/bpf.h +292 -0
- package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +163 -0
- package/cpp/nodepcap/deps/include/pcap/dlt.h +1514 -0
- package/cpp/nodepcap/deps/include/pcap/funcattrs.h +325 -0
- package/cpp/nodepcap/deps/include/pcap/ipnet.h +43 -0
- package/cpp/nodepcap/deps/include/pcap/namedb.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/nflog.h +94 -0
- package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +101 -0
- package/cpp/nodepcap/deps/include/pcap/pcap.h +1219 -0
- package/cpp/nodepcap/deps/include/pcap/sll.h +149 -0
- package/cpp/nodepcap/deps/include/pcap/socket.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/usb.h +143 -0
- package/cpp/nodepcap/deps/include/pcap/vlan.h +46 -0
- package/cpp/nodepcap/deps/include/pcap-bpf.h +45 -0
- package/cpp/nodepcap/deps/include/pcap-namedb.h +40 -0
- package/cpp/nodepcap/deps/include/pcap.h +43 -0
- package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
- package/cpp/nodepcap/nodepcap.gypi +104 -0
- package/cpp/nodepcap/src/binding.cc +14 -0
- package/cpp/nodepcap/src/capture.cc +400 -0
- package/cpp/nodepcap/src/capture.h +53 -0
- package/cpp/nodepcap/src/utils.cc +218 -0
- package/cpp/nodepcap/src/utils.h +13 -0
- package/package.json +65 -0
- package/src/NetKitty.ts +31 -0
- package/src/errors/ActionNotFoundError.ts +6 -0
- package/src/errors/CodecSchemaValidateError.ts +6 -0
- package/src/errors/DeviceNotFoundError.ts +6 -0
- package/src/errors/NoAvailableCodecError.ts +6 -0
- package/src/errors/NpcapLoadError.ts +6 -0
- package/src/errors/SocketDownError.ts +6 -0
- package/src/errors/UnknownPipeMessageTypeError.ts +6 -0
- package/src/errors/common/ErrorCode.ts +30 -0
- package/src/lib/GeneratePipeAddress.ts +17 -0
- package/src/lib/GetBinding.ts +3 -0
- package/src/lib/GetCaptureTemporaryDirectory.ts +12 -0
- package/src/lib/GetDeviceCaptureTemporaryFilename.ts +13 -0
- package/src/lib/codec/Codec.ts +181 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +413 -0
- package/src/lib/codec/headers/ARP.ts +218 -0
- package/src/lib/codec/headers/EthernetII.ts +77 -0
- package/src/lib/codec/headers/Goose.ts +658 -0
- package/src/lib/codec/headers/IEC61850SampledValues.ts +359 -0
- package/src/lib/codec/headers/IPv4.ts +329 -0
- package/src/lib/codec/headers/RawData.ts +34 -0
- package/src/lib/codec/headers/TCP.ts +931 -0
- package/src/lib/codec/headers/UDP.ts +180 -0
- package/src/lib/codec/headers/VLAN_802dot1Q.ts +74 -0
- package/src/lib/codec/lib/BufferToHex.ts +3 -0
- package/src/lib/codec/lib/BufferToIP.ts +19 -0
- package/src/lib/codec/lib/BufferToNumber.ts +31 -0
- package/src/lib/codec/lib/FixHexString.ts +8 -0
- package/src/lib/codec/lib/FlexibleObject.ts +100 -0
- package/src/lib/codec/lib/HexToNumber.ts +25 -0
- package/src/lib/codec/lib/IPToBuffer.ts +25 -0
- package/src/lib/codec/lib/NumberToBERBuffer.ts +19 -0
- package/src/lib/codec/lib/NumberToBERHex.ts +13 -0
- package/src/lib/codec/lib/NumberToBuffer.ts +21 -0
- package/src/lib/codec/lib/NumberToHex.ts +15 -0
- package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +53 -0
- package/src/lib/codec/lib/SortPostHandlers.ts +10 -0
- package/src/lib/codec/lib/StringContentEncodingEnum.ts +7 -0
- package/src/lib/codec/types/CodecData.ts +7 -0
- package/src/lib/codec/types/CodecDecodeResult.ts +9 -0
- package/src/lib/codec/types/CodecEncodeInput.ts +5 -0
- package/src/lib/codec/types/CodecEncodeResult.ts +6 -0
- package/src/lib/codec/types/CodecErrorInfo.ts +5 -0
- package/src/lib/codec/types/CodecModule.ts +3 -0
- package/src/lib/codec/types/CodecModuleConstructor.ts +3 -0
- package/src/lib/codec/types/CodecSchema.ts +7 -0
- package/src/lib/codec/types/HeaderTreeNode.ts +5 -0
- package/src/lib/codec/types/PostHandlerItem.ts +4 -0
- package/src/lib/nodepcap/Capture.ts +291 -0
- package/src/lib/nodepcap/GetNetworkInterfaces.ts +18 -0
- package/src/lib/nodepcap/interfaces/IBindingCapture.ts +27 -0
- package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +4 -0
- package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +19 -0
- package/src/lib/nodepcap/interfaces/INetworkInterface.ts +4 -0
- package/src/lib/nodepcap/lib/BindingCapture.ts +46 -0
- package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +17 -0
- package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +15 -0
- package/src/lib/nodepcap/workers/CaptureWorker.ts +30 -0
- package/src/lib/pcap/PCAPGenerator.ts +118 -0
- package/src/lib/pcap/PcapParser.ts +170 -0
- package/src/lib/pcap/PcapReader.ts +239 -0
- package/src/lib/pcap/PcapWriter.ts +93 -0
- package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +12 -0
- package/src/lib/pipe/PipeClient.ts +91 -0
- package/src/lib/pipe/PipeClientSocket.ts +99 -0
- package/src/lib/pipe/PipeMessage.ts +74 -0
- package/src/lib/pipe/PipeMessageHandler.ts +91 -0
- package/src/lib/pipe/PipeServer.ts +74 -0
- package/src/lib/schema/ProtocolFieldJSONSchema.ts +45 -0
- package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +3 -0
- package/src/lib/schema/ProtocolJSONSchema.ts +37 -0
- package/src/tests/Test.spec.ts +22 -0
- package/src/tests/units/CaptureTest.spec.ts +30 -0
- package/src/tests/units/Codec.spec.ts +85 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
+
import {BaseHeader} from '../abstracts/BaseHeader'
|
|
3
|
+
import {BufferToUInt16, BufferToUInt32, BufferToUInt64, BufferToUInt8} from '../lib/BufferToNumber'
|
|
4
|
+
import {UInt16ToBuffer, UInt32ToBuffer, UInt64ToBuffer, UInt8ToBuffer} from '../lib/NumberToBuffer'
|
|
5
|
+
import {IPv6ToBuffer} from '../lib/IPToBuffer'
|
|
6
|
+
import {CodecModule} from '../types/CodecModule'
|
|
7
|
+
import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
|
|
8
|
+
import {UInt64ToHex} from '../lib/NumberToHex'
|
|
9
|
+
import {HexToUInt64} from '../lib/HexToNumber'
|
|
10
|
+
|
|
11
|
+
enum TCPOption {
|
|
12
|
+
End_of_Option_List = 'EOL',
|
|
13
|
+
No_Operation = 'NOP',
|
|
14
|
+
Maximum_Segment_Size = 'MSS',
|
|
15
|
+
Window_Scale = 'Window-Scale',
|
|
16
|
+
Selective_Acknowledgment_Permitted = 'SACK-Permitted',
|
|
17
|
+
Selective_Acknowledgment = 'SACK',
|
|
18
|
+
Timestamp = 'TS',
|
|
19
|
+
User_Timeout = 'UTO',
|
|
20
|
+
TCP_Authentication_Option = 'TCP-AO'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type OPTION_EOL = {
|
|
24
|
+
option: TCPOption.End_of_Option_List
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type OPTION_NOP = {
|
|
28
|
+
option: TCPOption.No_Operation
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type OPTION_MSS = {
|
|
32
|
+
option: TCPOption.Maximum_Segment_Size
|
|
33
|
+
mss: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type OPTION_WINDOW_SCALE = {
|
|
37
|
+
option: TCPOption.Window_Scale
|
|
38
|
+
shift: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type OPTION_SACK_PERMITTED = {
|
|
42
|
+
option: TCPOption.Selective_Acknowledgment_Permitted
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type OPTION_SACK = {
|
|
46
|
+
option: TCPOption.Selective_Acknowledgment
|
|
47
|
+
blocks: string[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type OPTION_TS = {
|
|
51
|
+
option: TCPOption.Timestamp
|
|
52
|
+
tsval: number
|
|
53
|
+
tsecr: number
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type OPTION_UTO = {
|
|
57
|
+
option: TCPOption.User_Timeout
|
|
58
|
+
timeout: number
|
|
59
|
+
granularity: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type OPTION_TCP_AO = {
|
|
63
|
+
option: TCPOption.TCP_Authentication_Option
|
|
64
|
+
data: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type OPTION_DEFAULT = {
|
|
68
|
+
kind: number
|
|
69
|
+
data: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type OptionItem =
|
|
73
|
+
OPTION_EOL
|
|
74
|
+
| OPTION_NOP
|
|
75
|
+
| OPTION_MSS
|
|
76
|
+
| OPTION_WINDOW_SCALE
|
|
77
|
+
| OPTION_SACK_PERMITTED
|
|
78
|
+
| OPTION_SACK
|
|
79
|
+
| OPTION_TS
|
|
80
|
+
| OPTION_UTO
|
|
81
|
+
| OPTION_TCP_AO
|
|
82
|
+
| OPTION_DEFAULT
|
|
83
|
+
|
|
84
|
+
export class TCP extends BaseHeader {
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Calculate TCP Checksum
|
|
88
|
+
* @param tcpHeaderBuffer
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
protected calculateTCPChecksum(tcpHeaderBuffer: Buffer): number {
|
|
92
|
+
const tcpHeaderLength: number = tcpHeaderBuffer.length
|
|
93
|
+
const ipVersion: number = this.prevCodecModule.instance.version.getValue()
|
|
94
|
+
let pseudoHeaderBuffer: Buffer = Buffer.from([])
|
|
95
|
+
const sourceIp: string = this.prevCodecModule.instance.sip.getValue()
|
|
96
|
+
const destinationIp: string = this.prevCodecModule.instance.dip.getValue()
|
|
97
|
+
if (ipVersion === 4) {
|
|
98
|
+
//4 Bytes
|
|
99
|
+
const sourceIPv4Buffer: Buffer = Buffer.from(sourceIp.split('.').map((value: string): number => parseInt(value)))
|
|
100
|
+
const destinationIPv4Buffer: Buffer = Buffer.from(destinationIp.split('.').map((value: string): number => parseInt(value)))
|
|
101
|
+
//IPv4 Pseudo header
|
|
102
|
+
pseudoHeaderBuffer = Buffer.concat([
|
|
103
|
+
sourceIPv4Buffer,
|
|
104
|
+
destinationIPv4Buffer,
|
|
105
|
+
UInt8ToBuffer(0), //Reserved field
|
|
106
|
+
UInt8ToBuffer(6), //Protocol type (TCP = 6)
|
|
107
|
+
Buffer.from([(tcpHeaderLength >> 8) & 0xFF]),
|
|
108
|
+
Buffer.from([tcpHeaderLength & 0xFF])
|
|
109
|
+
])
|
|
110
|
+
} else if (ipVersion === 6) {
|
|
111
|
+
//16 Bytes
|
|
112
|
+
const sourceIPv6Buffer: Buffer = IPv6ToBuffer(sourceIp)
|
|
113
|
+
const destinationIPv6Buffer: Buffer = IPv6ToBuffer(destinationIp)
|
|
114
|
+
//IPv6 Pseudo header
|
|
115
|
+
pseudoHeaderBuffer = Buffer.concat([
|
|
116
|
+
sourceIPv6Buffer,
|
|
117
|
+
destinationIPv6Buffer,
|
|
118
|
+
UInt8ToBuffer(0), //Reserved field
|
|
119
|
+
UInt8ToBuffer(0), //Reserved field
|
|
120
|
+
UInt8ToBuffer(0), //Reserved field
|
|
121
|
+
UInt8ToBuffer(6), //Protocol type (TCP = 6)
|
|
122
|
+
Buffer.from([(tcpHeaderLength >> 8) & 0xFF]),
|
|
123
|
+
Buffer.from([tcpHeaderLength & 0xFF])
|
|
124
|
+
])
|
|
125
|
+
} else {
|
|
126
|
+
return 0
|
|
127
|
+
}
|
|
128
|
+
const dataBuffer: Buffer = Buffer.concat([pseudoHeaderBuffer, tcpHeaderBuffer])
|
|
129
|
+
const data: Uint8Array = Uint8Array.from(dataBuffer)
|
|
130
|
+
let sum: number = 0
|
|
131
|
+
for (let i: number = 0; i < data.length; i += 2) sum += (data[i] << 8) + (data[i + 1] || 0)
|
|
132
|
+
while (sum >>> 16) sum = (sum & 0xFFFF) + (sum >>> 16)
|
|
133
|
+
return (~sum) & 0xFFFF
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public SCHEMA: ProtocolJSONSchema = {
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: {
|
|
139
|
+
srcport: {
|
|
140
|
+
type: 'integer',
|
|
141
|
+
label: 'Source Port',
|
|
142
|
+
minimum: 0,
|
|
143
|
+
maximum: 65535,
|
|
144
|
+
decode: (): void => {
|
|
145
|
+
this.instance.srcport.setValue(BufferToUInt16(this.readBytes(0, 2)))
|
|
146
|
+
},
|
|
147
|
+
encode: (): void => {
|
|
148
|
+
let srcport: number = this.instance.srcport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
149
|
+
if (srcport > 65535) {
|
|
150
|
+
this.recordError(this.instance.srcport.getPath(), 'Maximum value is 65535')
|
|
151
|
+
srcport = 65535
|
|
152
|
+
}
|
|
153
|
+
if (srcport < 0) {
|
|
154
|
+
this.recordError(this.instance.srcport.getPath(), 'Minimum value is 0')
|
|
155
|
+
srcport = 0
|
|
156
|
+
}
|
|
157
|
+
this.instance.srcport.setValue(srcport)
|
|
158
|
+
this.writeBytes(0, UInt16ToBuffer(srcport))
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
dstport: {
|
|
162
|
+
type: 'integer',
|
|
163
|
+
label: 'Destination Port',
|
|
164
|
+
minimum: 0,
|
|
165
|
+
maximum: 65535,
|
|
166
|
+
decode: (): void => {
|
|
167
|
+
this.instance.dstport.setValue(BufferToUInt16(this.readBytes(2, 2)))
|
|
168
|
+
},
|
|
169
|
+
encode: (): void => {
|
|
170
|
+
let dstport: number = this.instance.dstport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
171
|
+
if (dstport > 65535) {
|
|
172
|
+
this.recordError(this.instance.dstport.getPath(), 'Maximum value is 65535')
|
|
173
|
+
dstport = 65535
|
|
174
|
+
}
|
|
175
|
+
if (dstport < 0) {
|
|
176
|
+
this.recordError(this.instance.dstport.getPath(), 'Minimum value is 0')
|
|
177
|
+
dstport = 0
|
|
178
|
+
}
|
|
179
|
+
this.instance.dstport.setValue(dstport)
|
|
180
|
+
this.writeBytes(2, UInt16ToBuffer(dstport))
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
seq: {
|
|
184
|
+
type: 'integer',
|
|
185
|
+
label: 'Sequence Number',
|
|
186
|
+
minimum: 0,
|
|
187
|
+
maximum: 4294967295,
|
|
188
|
+
decode: (): void => {
|
|
189
|
+
this.instance.seq.setValue(BufferToUInt32(this.readBytes(4, 4)))
|
|
190
|
+
},
|
|
191
|
+
encode: (): void => {
|
|
192
|
+
let seqNum: number = this.instance.seq.getValue(0)
|
|
193
|
+
if (seqNum > 4294967295) {
|
|
194
|
+
this.recordError(this.instance.seq.getPath(), 'Maximum value is 4294967295')
|
|
195
|
+
seqNum = 4294967295
|
|
196
|
+
}
|
|
197
|
+
if (seqNum < 0) {
|
|
198
|
+
this.recordError(this.instance.seq.getPath(), 'Minimum value is 0')
|
|
199
|
+
seqNum = 0
|
|
200
|
+
}
|
|
201
|
+
this.instance.seq.setValue(seqNum)
|
|
202
|
+
this.writeBytes(4, UInt32ToBuffer(seqNum))
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
ack: {
|
|
206
|
+
type: 'integer',
|
|
207
|
+
label: 'Acknowledgment Number',
|
|
208
|
+
minimum: 0,
|
|
209
|
+
maximum: 4294967295,
|
|
210
|
+
decode: (): void => {
|
|
211
|
+
this.instance.ack.setValue(BufferToUInt32(this.readBytes(8, 4)))
|
|
212
|
+
},
|
|
213
|
+
encode: (): void => {
|
|
214
|
+
let ackNum: number = this.instance.ack.getValue(0)
|
|
215
|
+
if (ackNum > 4294967295) {
|
|
216
|
+
this.recordError(this.instance.ack.getPath(), 'Maximum value is 4294967295')
|
|
217
|
+
ackNum = 4294967295
|
|
218
|
+
}
|
|
219
|
+
if (ackNum < 0) {
|
|
220
|
+
this.recordError(this.instance.ack.getPath(), 'Minimum value is 0')
|
|
221
|
+
ackNum = 0
|
|
222
|
+
}
|
|
223
|
+
this.instance.ack.setValue(ackNum)
|
|
224
|
+
this.writeBytes(8, UInt32ToBuffer(ackNum))
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
hdrLen: {
|
|
228
|
+
type: 'integer',
|
|
229
|
+
label: 'Header Length',
|
|
230
|
+
minimum: 0,
|
|
231
|
+
maximum: 60,
|
|
232
|
+
decode: (): void => {
|
|
233
|
+
this.instance.hdrLen.setValue(this.readBits(12, 1, 0, 4) * 4)
|
|
234
|
+
},
|
|
235
|
+
encode: (): void => {
|
|
236
|
+
let hdrLen: number = this.instance.hdrLen.getValue(0)
|
|
237
|
+
if (hdrLen) {
|
|
238
|
+
this.instance.hdrLen.setValue(hdrLen)
|
|
239
|
+
this.writeBits(12, 1, 0, 4, hdrLen ? Math.floor(hdrLen / 4) : 0)
|
|
240
|
+
} else {
|
|
241
|
+
this.addPostSelfEncodeHandler((): void => {
|
|
242
|
+
this.instance.hdrLen.setValue(Math.floor(this.length / 4) * 4)
|
|
243
|
+
this.writeBits(12, 1, 0, 4, Math.floor(this.length / 4))
|
|
244
|
+
}, 1)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
flags: {
|
|
249
|
+
type: 'object',
|
|
250
|
+
label: 'Flags',
|
|
251
|
+
properties: {
|
|
252
|
+
res: {
|
|
253
|
+
type: 'integer',
|
|
254
|
+
label: 'Reserved',
|
|
255
|
+
minimum: 0,
|
|
256
|
+
maximum: 7,
|
|
257
|
+
decode: (): void => {
|
|
258
|
+
this.instance.flags.res.setValue(this.readBits(12, 1, 4, 3))
|
|
259
|
+
},
|
|
260
|
+
encode: (): void => {
|
|
261
|
+
let reserved: number = this.instance.flags.res.getValue(0)
|
|
262
|
+
if (reserved > 7) {
|
|
263
|
+
this.recordError(this.instance.flags.res.getPath(), 'Maximum value is 7')
|
|
264
|
+
reserved = 7
|
|
265
|
+
}
|
|
266
|
+
if (reserved < 0) {
|
|
267
|
+
this.recordError(this.instance.flags.res.getPath(), 'Minimum value is 0')
|
|
268
|
+
reserved = 0
|
|
269
|
+
}
|
|
270
|
+
this.instance.flags.res.setValue(reserved)
|
|
271
|
+
this.writeBits(12, 1, 4, 3, reserved)
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
ae: {
|
|
275
|
+
type: 'boolean',
|
|
276
|
+
label: 'Accurate ECN',
|
|
277
|
+
decode: (): void => {
|
|
278
|
+
this.instance.flags.ae.setValue(!!this.readBits(12, 1, 7, 1))
|
|
279
|
+
},
|
|
280
|
+
encode: (): void => {
|
|
281
|
+
const accurateECN: boolean = !!this.instance.flags.ae.getValue()
|
|
282
|
+
this.instance.flags.ae.setValue(accurateECN)
|
|
283
|
+
this.writeBits(12, 1, 7, 1, accurateECN ? 1 : 0)
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
cwr: {
|
|
287
|
+
type: 'boolean',
|
|
288
|
+
label: 'Congestion Window Reduced',
|
|
289
|
+
decode: (): void => {
|
|
290
|
+
this.instance.flags.cwr.setValue(!!this.readBits(13, 1, 0, 1))
|
|
291
|
+
},
|
|
292
|
+
encode: (): void => {
|
|
293
|
+
const congestionWindowReduced: boolean = !!this.instance.flags.cwr.getValue()
|
|
294
|
+
this.instance.flags.cwr.setValue(congestionWindowReduced)
|
|
295
|
+
this.writeBits(13, 1, 0, 1, congestionWindowReduced ? 1 : 0)
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
ece: {
|
|
299
|
+
type: 'boolean',
|
|
300
|
+
label: 'ECN-Echo',
|
|
301
|
+
decode: (): void => {
|
|
302
|
+
this.instance.flags.ece.setValue(!!this.readBits(13, 1, 1, 1))
|
|
303
|
+
},
|
|
304
|
+
encode: (): void => {
|
|
305
|
+
const ECNEcho: boolean = !!this.instance.flags.ece.getValue()
|
|
306
|
+
this.instance.flags.ece.setValue(ECNEcho)
|
|
307
|
+
this.writeBits(13, 1, 1, 1, ECNEcho ? 1 : 0)
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
urg: {
|
|
311
|
+
type: 'boolean',
|
|
312
|
+
label: 'Urgent',
|
|
313
|
+
decode: (): void => {
|
|
314
|
+
this.instance.flags.urg.setValue(!!this.readBits(13, 1, 2, 1))
|
|
315
|
+
},
|
|
316
|
+
encode: (): void => {
|
|
317
|
+
const urgent: boolean = !!this.instance.flags.urg.getValue()
|
|
318
|
+
this.instance.flags.urg.setValue(urgent)
|
|
319
|
+
this.writeBits(13, 1, 2, 1, urgent ? 1 : 0)
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
ack: {
|
|
323
|
+
type: 'boolean',
|
|
324
|
+
label: 'Acknowledgment',
|
|
325
|
+
decode: (): void => {
|
|
326
|
+
this.instance.flags.ack.setValue(!!this.readBits(13, 1, 3, 1))
|
|
327
|
+
},
|
|
328
|
+
encode: (): void => {
|
|
329
|
+
const acknowledgment: boolean = !!this.instance.flags.ack.getValue()
|
|
330
|
+
this.instance.flags.ack.setValue(acknowledgment)
|
|
331
|
+
this.writeBits(13, 1, 3, 1, acknowledgment ? 1 : 0)
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
push: {
|
|
335
|
+
type: 'boolean',
|
|
336
|
+
label: 'Push',
|
|
337
|
+
decode: (): void => {
|
|
338
|
+
this.instance.flags.push.setValue(!!this.readBits(13, 1, 4, 1))
|
|
339
|
+
},
|
|
340
|
+
encode: (): void => {
|
|
341
|
+
const push: boolean = !!this.instance.flags.push.getValue()
|
|
342
|
+
this.instance.flags.push.setValue(push)
|
|
343
|
+
this.writeBits(13, 1, 4, 1, push ? 1 : 0)
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
rst: {
|
|
347
|
+
type: 'boolean',
|
|
348
|
+
label: 'Reset',
|
|
349
|
+
decode: (): void => {
|
|
350
|
+
this.instance.flags.rst.setValue(!!this.readBits(13, 1, 5, 1))
|
|
351
|
+
},
|
|
352
|
+
encode: (): void => {
|
|
353
|
+
const reset: boolean = !!this.instance.flags.rst.getValue()
|
|
354
|
+
this.instance.flags.rst.setValue(reset)
|
|
355
|
+
this.writeBits(13, 1, 5, 1, reset ? 1 : 0)
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
syn: {
|
|
359
|
+
type: 'boolean',
|
|
360
|
+
label: 'Syn',
|
|
361
|
+
decode: (): void => {
|
|
362
|
+
this.instance.flags.syn.setValue(!!this.readBits(13, 1, 6, 1))
|
|
363
|
+
},
|
|
364
|
+
encode: (): void => {
|
|
365
|
+
const syn: boolean = !!this.instance.flags.syn.getValue()
|
|
366
|
+
this.instance.flags.syn.setValue(syn)
|
|
367
|
+
this.writeBits(13, 1, 6, 1, syn ? 1 : 0)
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
fin: {
|
|
371
|
+
type: 'boolean',
|
|
372
|
+
label: 'Fin',
|
|
373
|
+
decode: (): void => {
|
|
374
|
+
this.instance.flags.fin.setValue(!!this.readBits(13, 1, 7, 1))
|
|
375
|
+
},
|
|
376
|
+
encode: (): void => {
|
|
377
|
+
const fin: boolean = !!this.instance.flags.fin.getValue()
|
|
378
|
+
this.instance.flags.fin.setValue(fin)
|
|
379
|
+
this.writeBits(13, 1, 7, 1, fin ? 1 : 0)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
window: {
|
|
385
|
+
type: 'integer',
|
|
386
|
+
label: 'Window Size',
|
|
387
|
+
minimum: 0,
|
|
388
|
+
maximum: 65535,
|
|
389
|
+
decode: (): void => {
|
|
390
|
+
this.instance.window.setValue(BufferToUInt16(this.readBytes(14, 2)))
|
|
391
|
+
},
|
|
392
|
+
encode: (): void => {
|
|
393
|
+
let windowSize: number = this.instance.window.getValue(0)
|
|
394
|
+
if (windowSize > 65535) {
|
|
395
|
+
this.recordError(this.instance.window.getPath(), 'Maximum value is 65535')
|
|
396
|
+
windowSize = 65535
|
|
397
|
+
}
|
|
398
|
+
if (windowSize < 0) {
|
|
399
|
+
this.recordError(this.instance.window.getPath(), 'Minimum value is 0')
|
|
400
|
+
windowSize = 0
|
|
401
|
+
}
|
|
402
|
+
this.instance.window.setValue(windowSize)
|
|
403
|
+
this.writeBytes(14, UInt16ToBuffer(windowSize))
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
checksum: {
|
|
407
|
+
type: 'integer',
|
|
408
|
+
label: 'Checksum',
|
|
409
|
+
minimum: 0,
|
|
410
|
+
maximum: 65535,
|
|
411
|
+
decode: (): void => {
|
|
412
|
+
this.instance.checksum.setValue(BufferToUInt16(this.readBytes(16, 2)))
|
|
413
|
+
},
|
|
414
|
+
encode: (): void => {
|
|
415
|
+
let checksum: number = this.instance.checksum.getValue(0)
|
|
416
|
+
if (checksum) {
|
|
417
|
+
this.instance.checksum.setValue(checksum)
|
|
418
|
+
this.writeBytes(16, UInt16ToBuffer(checksum))
|
|
419
|
+
} else {
|
|
420
|
+
this.instance.checksum.setValue(checksum)
|
|
421
|
+
this.writeBytes(16, UInt16ToBuffer(checksum))
|
|
422
|
+
this.addPostPacketEncodeHandler((): void => {
|
|
423
|
+
//Calculate checksum after packet encoded
|
|
424
|
+
let startPos: number = 0
|
|
425
|
+
let endPos: number = 0
|
|
426
|
+
this.codecModules.forEach((codecModule: CodecModule): void => {
|
|
427
|
+
if (codecModule === this) startPos = codecModule.startPos
|
|
428
|
+
endPos = codecModule.endPos > endPos ? codecModule.endPos : endPos
|
|
429
|
+
})
|
|
430
|
+
const calcChecksum: number = this.calculateTCPChecksum(this.packet.subarray(startPos, endPos))
|
|
431
|
+
this.instance.checksum.setValue(calcChecksum)
|
|
432
|
+
this.writeBytes(16, UInt16ToBuffer(calcChecksum))
|
|
433
|
+
}, 100)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
urgPtr: {
|
|
438
|
+
type: 'integer',
|
|
439
|
+
label: 'Urgent Pointer',
|
|
440
|
+
minimum: 0,
|
|
441
|
+
maximum: 65535,
|
|
442
|
+
decode: (): void => {
|
|
443
|
+
this.instance.urgPtr.setValue(BufferToUInt16(this.readBytes(18, 2)))
|
|
444
|
+
},
|
|
445
|
+
encode: (): void => {
|
|
446
|
+
let urgPtr: number = this.instance.urgPtr.getValue(0)
|
|
447
|
+
if (urgPtr > 65535) {
|
|
448
|
+
this.recordError(this.instance.urgPtr.getPath(), 'Maximum value is 65535')
|
|
449
|
+
urgPtr = 65535
|
|
450
|
+
}
|
|
451
|
+
if (urgPtr < 0) {
|
|
452
|
+
this.recordError(this.instance.urgPtr.getPath(), 'Minimum value is 0')
|
|
453
|
+
urgPtr = 0
|
|
454
|
+
}
|
|
455
|
+
this.instance.urgPtr.setValue(urgPtr)
|
|
456
|
+
this.writeBytes(18, UInt16ToBuffer(urgPtr))
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
options: {
|
|
460
|
+
type: 'array',
|
|
461
|
+
label: 'Options',
|
|
462
|
+
items: {
|
|
463
|
+
anyOf: [
|
|
464
|
+
//Kind = 0 (End of Option List, EOL)
|
|
465
|
+
{
|
|
466
|
+
type: 'object',
|
|
467
|
+
label: 'End of Option List',
|
|
468
|
+
properties: {
|
|
469
|
+
option: {
|
|
470
|
+
type: 'string',
|
|
471
|
+
label: 'Option',
|
|
472
|
+
enum: [TCPOption.End_of_Option_List]
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
//Kind = 1 (No-Operation, NOP)
|
|
477
|
+
{
|
|
478
|
+
type: 'object',
|
|
479
|
+
label: 'No-Operation',
|
|
480
|
+
properties: {
|
|
481
|
+
option: {
|
|
482
|
+
type: 'string',
|
|
483
|
+
label: 'Option',
|
|
484
|
+
enum: [TCPOption.No_Operation]
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
//Kind = 2 (Maximum Segment Size, MSS)
|
|
489
|
+
{
|
|
490
|
+
type: 'object',
|
|
491
|
+
label: 'Maximum Segment Size',
|
|
492
|
+
properties: {
|
|
493
|
+
option: {
|
|
494
|
+
type: 'string',
|
|
495
|
+
label: 'Option',
|
|
496
|
+
enum: [TCPOption.Maximum_Segment_Size]
|
|
497
|
+
},
|
|
498
|
+
mss: {
|
|
499
|
+
type: 'integer',
|
|
500
|
+
label: 'MSS',
|
|
501
|
+
maximum: 65535,
|
|
502
|
+
minimum: 0
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
//Kind = 3 (Window Scale)
|
|
507
|
+
{
|
|
508
|
+
type: 'object',
|
|
509
|
+
label: 'Window Scale',
|
|
510
|
+
properties: {
|
|
511
|
+
option: {
|
|
512
|
+
type: 'string',
|
|
513
|
+
label: 'Option',
|
|
514
|
+
enum: [TCPOption.Window_Scale]
|
|
515
|
+
},
|
|
516
|
+
shift: {
|
|
517
|
+
type: 'integer',
|
|
518
|
+
label: 'Shift count',
|
|
519
|
+
minimum: 0,
|
|
520
|
+
maximum: 14
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
//Kind = 4 (Selective Acknowledgment Permitted, SACK-Permitted)
|
|
525
|
+
{
|
|
526
|
+
type: 'object',
|
|
527
|
+
label: 'Selective Acknowledgment Permitted',
|
|
528
|
+
properties: {
|
|
529
|
+
option: {
|
|
530
|
+
type: 'string',
|
|
531
|
+
label: 'Option',
|
|
532
|
+
enum: [TCPOption.Selective_Acknowledgment_Permitted]
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
//Kind = 5 (Selective Acknowledgment, SACK)
|
|
537
|
+
{
|
|
538
|
+
type: 'object',
|
|
539
|
+
label: 'Selective Acknowledgment',
|
|
540
|
+
properties: {
|
|
541
|
+
option: {
|
|
542
|
+
type: 'string',
|
|
543
|
+
label: 'Option',
|
|
544
|
+
enum: [TCPOption.Selective_Acknowledgment]
|
|
545
|
+
},
|
|
546
|
+
blocks: {
|
|
547
|
+
type: 'array',
|
|
548
|
+
label: 'SACK Blocks',
|
|
549
|
+
items: {
|
|
550
|
+
type: 'string',
|
|
551
|
+
maxLength: 16,
|
|
552
|
+
minLength: 16,
|
|
553
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
//Kind = 8 (Timestamp, TS)
|
|
559
|
+
{
|
|
560
|
+
type: 'object',
|
|
561
|
+
label: 'Timestamp',
|
|
562
|
+
properties: {
|
|
563
|
+
option: {
|
|
564
|
+
type: 'string',
|
|
565
|
+
label: 'Option',
|
|
566
|
+
enum: [TCPOption.Timestamp]
|
|
567
|
+
},
|
|
568
|
+
tsval: {
|
|
569
|
+
type: 'integer',
|
|
570
|
+
label: 'TSval',
|
|
571
|
+
minimum: 0,
|
|
572
|
+
maximum: 4294967295
|
|
573
|
+
},
|
|
574
|
+
tsecr: {
|
|
575
|
+
type: 'integer',
|
|
576
|
+
label: 'TSecr',
|
|
577
|
+
minimum: 0,
|
|
578
|
+
maximum: 4294967295
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
//Kind = 28 (User Timeout, UTO)
|
|
583
|
+
{
|
|
584
|
+
type: 'object',
|
|
585
|
+
label: 'User Timeout',
|
|
586
|
+
properties: {
|
|
587
|
+
option: {
|
|
588
|
+
type: 'string',
|
|
589
|
+
label: 'Option',
|
|
590
|
+
enum: [TCPOption.User_Timeout]
|
|
591
|
+
},
|
|
592
|
+
timeout: {
|
|
593
|
+
type: 'integer',
|
|
594
|
+
label: 'Timeout',
|
|
595
|
+
minimum: 0,
|
|
596
|
+
maximum: 65535
|
|
597
|
+
},
|
|
598
|
+
granularity: {
|
|
599
|
+
type: 'integer',
|
|
600
|
+
label: 'Granularity',
|
|
601
|
+
enum: [0, 1]
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
//Kind = 29 (TCP Authentication Option, TCP-AO)
|
|
606
|
+
{
|
|
607
|
+
type: 'object',
|
|
608
|
+
label: 'TCP Authentication Option',
|
|
609
|
+
properties: {
|
|
610
|
+
option: {
|
|
611
|
+
type: 'string',
|
|
612
|
+
label: 'Option',
|
|
613
|
+
enum: [TCPOption.TCP_Authentication_Option]
|
|
614
|
+
},
|
|
615
|
+
data: {
|
|
616
|
+
type: 'string',
|
|
617
|
+
label: 'Data',
|
|
618
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
//Default
|
|
623
|
+
{
|
|
624
|
+
type: 'object',
|
|
625
|
+
properties: {
|
|
626
|
+
kind: {
|
|
627
|
+
type: 'integer',
|
|
628
|
+
label: 'Kind'
|
|
629
|
+
},
|
|
630
|
+
data: {
|
|
631
|
+
type: 'string',
|
|
632
|
+
contentEncoding: StringContentEncodingEnum.HEX,
|
|
633
|
+
label: 'Data'
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
]
|
|
638
|
+
},
|
|
639
|
+
decode: (): void => {
|
|
640
|
+
const hdrLen: number = this.instance.hdrLen.getValue()
|
|
641
|
+
const optionsLength: number = hdrLen - this.length
|
|
642
|
+
if (!optionsLength) return
|
|
643
|
+
let optionOffset: number = this.length
|
|
644
|
+
const options: OptionItem[] = []
|
|
645
|
+
let index: number = 0
|
|
646
|
+
while (optionOffset < hdrLen) {
|
|
647
|
+
const kind: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
648
|
+
optionOffset += 1
|
|
649
|
+
switch (kind) {
|
|
650
|
+
//Kind = 0 (End of Option List, EOL)
|
|
651
|
+
case 0: {
|
|
652
|
+
options.push({
|
|
653
|
+
option: TCPOption.End_of_Option_List
|
|
654
|
+
})
|
|
655
|
+
}
|
|
656
|
+
break
|
|
657
|
+
//Kind = 1 (No-Operation, NOP)
|
|
658
|
+
case 1: {
|
|
659
|
+
options.push({
|
|
660
|
+
option: TCPOption.No_Operation
|
|
661
|
+
})
|
|
662
|
+
}
|
|
663
|
+
break
|
|
664
|
+
//Kind = 2 (Maximum Segment Size, MSS)
|
|
665
|
+
case 2: {
|
|
666
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
667
|
+
if (length !== 4) this.recordError(this.instance.options.getPath(index), 'MSS option TLV length should be 4')
|
|
668
|
+
optionOffset += 1
|
|
669
|
+
let value: number = BufferToUInt16(this.readBytes(optionOffset, 2))
|
|
670
|
+
optionOffset += 2
|
|
671
|
+
options.push({
|
|
672
|
+
option: TCPOption.Maximum_Segment_Size,
|
|
673
|
+
mss: value
|
|
674
|
+
})
|
|
675
|
+
}
|
|
676
|
+
break
|
|
677
|
+
//Kind = 3 (Window Scale)
|
|
678
|
+
case 3: {
|
|
679
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
680
|
+
if (length !== 3) this.recordError(this.instance.options.getPath(index), 'Window Scale option TLV length should be 3')
|
|
681
|
+
optionOffset += 1
|
|
682
|
+
let value: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
683
|
+
optionOffset += 1
|
|
684
|
+
if (value < 0 || value > 14) this.recordError(this.instance.options.getPath(index), 'Window Scale option TLV value should between 0 and 14')
|
|
685
|
+
options.push({
|
|
686
|
+
option: TCPOption.Window_Scale,
|
|
687
|
+
shift: value
|
|
688
|
+
})
|
|
689
|
+
}
|
|
690
|
+
break
|
|
691
|
+
//Kind = 4 (Selective Acknowledgment Permitted, SACK-Permitted)
|
|
692
|
+
case 4: {
|
|
693
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
694
|
+
optionOffset += 1
|
|
695
|
+
if (length !== 2) this.recordError(this.instance.options.getPath(index), 'SACK-Permitted option TLV length should be 2')
|
|
696
|
+
options.push({
|
|
697
|
+
option: TCPOption.Selective_Acknowledgment_Permitted
|
|
698
|
+
})
|
|
699
|
+
}
|
|
700
|
+
break
|
|
701
|
+
//Kind = 5 (Selective Acknowledgment, SACK)
|
|
702
|
+
case 5: {
|
|
703
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
704
|
+
optionOffset += 1
|
|
705
|
+
let sackBlockTotalLength: number = length - 2
|
|
706
|
+
if (sackBlockTotalLength < 0) {
|
|
707
|
+
this.recordError(this.instance.options.getPath(index), 'SACK option block count should not less than 0')
|
|
708
|
+
sackBlockTotalLength = 0
|
|
709
|
+
}
|
|
710
|
+
let sackBlockCount: number = sackBlockTotalLength ? Math.floor(sackBlockTotalLength / 8) : 0
|
|
711
|
+
const sackBlocks: string[] = []
|
|
712
|
+
while (sackBlockCount > 0) {
|
|
713
|
+
sackBlocks.push(UInt64ToHex(BigInt(`0x${BufferToUInt64(this.readBytes(optionOffset, 8)).toString(16)}`)))
|
|
714
|
+
optionOffset += 8
|
|
715
|
+
sackBlockCount -= 1
|
|
716
|
+
}
|
|
717
|
+
options.push({
|
|
718
|
+
option: TCPOption.Selective_Acknowledgment,
|
|
719
|
+
blocks: sackBlocks
|
|
720
|
+
})
|
|
721
|
+
}
|
|
722
|
+
break
|
|
723
|
+
//Kind = 8 (Timestamp, TS)
|
|
724
|
+
case 8: {
|
|
725
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
726
|
+
optionOffset += 1
|
|
727
|
+
if (length !== 10) this.recordError(this.instance.options.getPath(index), 'Timestamp option TLV length should be 10')
|
|
728
|
+
let tsval: number = BufferToUInt32(this.readBytes(optionOffset, 4))
|
|
729
|
+
optionOffset += 4
|
|
730
|
+
let tsecr: number = BufferToUInt32(this.readBytes(optionOffset, 4))
|
|
731
|
+
optionOffset += 4
|
|
732
|
+
options.push({
|
|
733
|
+
option: TCPOption.Timestamp,
|
|
734
|
+
tsval: tsval,
|
|
735
|
+
tsecr: tsecr
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
break
|
|
739
|
+
//Kind = 28 (User Timeout, UTO)
|
|
740
|
+
case 28: {
|
|
741
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
742
|
+
optionOffset += 1
|
|
743
|
+
if (length !== 5) this.recordError(this.instance.options.getPath(index), 'UTO option TLV length should be 5')
|
|
744
|
+
let timeout: number = BufferToUInt16(this.readBytes(optionOffset, 2))
|
|
745
|
+
optionOffset += 2
|
|
746
|
+
let granularity: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
747
|
+
optionOffset += 1
|
|
748
|
+
options.push({
|
|
749
|
+
option: TCPOption.User_Timeout,
|
|
750
|
+
timeout: timeout,
|
|
751
|
+
granularity: granularity
|
|
752
|
+
})
|
|
753
|
+
}
|
|
754
|
+
break
|
|
755
|
+
//Kind = 29 (TCP Authentication Option, TCP-AO)
|
|
756
|
+
case 29: {
|
|
757
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
758
|
+
optionOffset += 1
|
|
759
|
+
let dataLength: number = length - 2
|
|
760
|
+
if (dataLength < 0) {
|
|
761
|
+
this.recordError(this.instance.options.getPath(index), 'TCP Authentication Option TLV length should not less than 2')
|
|
762
|
+
dataLength = 0
|
|
763
|
+
}
|
|
764
|
+
let data: Buffer
|
|
765
|
+
if (dataLength) {
|
|
766
|
+
data = this.readBytes(optionOffset, dataLength)
|
|
767
|
+
optionOffset += dataLength
|
|
768
|
+
} else {
|
|
769
|
+
data = Buffer.from([])
|
|
770
|
+
}
|
|
771
|
+
options.push({
|
|
772
|
+
option: TCPOption.TCP_Authentication_Option,
|
|
773
|
+
data: data.toString('hex')
|
|
774
|
+
})
|
|
775
|
+
}
|
|
776
|
+
break
|
|
777
|
+
default: {
|
|
778
|
+
let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
|
|
779
|
+
let dataLength: number = length - 2
|
|
780
|
+
if (dataLength < 0) {
|
|
781
|
+
this.recordError(this.instance.options.getPath(index), 'Option TLV length should not less than 2')
|
|
782
|
+
dataLength = 0
|
|
783
|
+
}
|
|
784
|
+
let data: Buffer
|
|
785
|
+
if (dataLength) {
|
|
786
|
+
data = this.readBytes(optionOffset, dataLength)
|
|
787
|
+
optionOffset += dataLength
|
|
788
|
+
} else {
|
|
789
|
+
data = Buffer.from([])
|
|
790
|
+
}
|
|
791
|
+
options.push({
|
|
792
|
+
kind: kind,
|
|
793
|
+
data: data.toString('hex')
|
|
794
|
+
})
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
index += 1
|
|
798
|
+
}
|
|
799
|
+
this.instance.options.setValue(options)
|
|
800
|
+
},
|
|
801
|
+
encode: (): void => {
|
|
802
|
+
const options: (OptionItem[]) | undefined = this.instance.options.getValue()
|
|
803
|
+
if (!options) return
|
|
804
|
+
let optionOffset: number = this.length
|
|
805
|
+
options.forEach((optionItem: OptionItem): void => {
|
|
806
|
+
const namedOptionItem: OPTION_EOL | OPTION_NOP | OPTION_MSS | OPTION_WINDOW_SCALE | OPTION_SACK_PERMITTED | OPTION_SACK | OPTION_TS | OPTION_UTO | OPTION_TCP_AO = optionItem as any
|
|
807
|
+
switch (namedOptionItem.option) {
|
|
808
|
+
case TCPOption.End_of_Option_List: {
|
|
809
|
+
const optionEOL: OPTION_EOL = optionItem as OPTION_EOL
|
|
810
|
+
this.writeBytes(optionOffset, UInt8ToBuffer(0))
|
|
811
|
+
optionOffset += 1
|
|
812
|
+
return
|
|
813
|
+
}
|
|
814
|
+
case TCPOption.No_Operation: {
|
|
815
|
+
const optionNOP: OPTION_NOP = optionItem as OPTION_NOP
|
|
816
|
+
this.writeBytes(optionOffset, UInt8ToBuffer(1))
|
|
817
|
+
optionOffset += 1
|
|
818
|
+
return
|
|
819
|
+
}
|
|
820
|
+
case TCPOption.Maximum_Segment_Size: {
|
|
821
|
+
const optionMSS: OPTION_MSS = optionItem as OPTION_MSS
|
|
822
|
+
const mssBuffer: Buffer = Buffer.concat([
|
|
823
|
+
UInt8ToBuffer(2),
|
|
824
|
+
UInt8ToBuffer(4),
|
|
825
|
+
UInt16ToBuffer(optionMSS.mss)
|
|
826
|
+
])
|
|
827
|
+
this.writeBytes(optionOffset, mssBuffer)
|
|
828
|
+
optionOffset += mssBuffer.length
|
|
829
|
+
return
|
|
830
|
+
}
|
|
831
|
+
case TCPOption.Window_Scale: {
|
|
832
|
+
const optionWS: OPTION_WINDOW_SCALE = optionItem as OPTION_WINDOW_SCALE
|
|
833
|
+
const wsBuffer: Buffer = Buffer.concat([
|
|
834
|
+
UInt8ToBuffer(3),
|
|
835
|
+
UInt8ToBuffer(3),
|
|
836
|
+
UInt8ToBuffer(optionWS.shift)
|
|
837
|
+
])
|
|
838
|
+
this.writeBytes(optionOffset, wsBuffer)
|
|
839
|
+
optionOffset += wsBuffer.length
|
|
840
|
+
return
|
|
841
|
+
}
|
|
842
|
+
case TCPOption.Selective_Acknowledgment_Permitted: {
|
|
843
|
+
const optionSackPermitted: OPTION_SACK_PERMITTED = optionItem as OPTION_SACK_PERMITTED
|
|
844
|
+
const sackPermittedBuffer: Buffer = Buffer.concat([
|
|
845
|
+
UInt8ToBuffer(4),
|
|
846
|
+
UInt8ToBuffer(2)
|
|
847
|
+
])
|
|
848
|
+
this.writeBytes(optionOffset, sackPermittedBuffer)
|
|
849
|
+
optionOffset += sackPermittedBuffer.length
|
|
850
|
+
return
|
|
851
|
+
}
|
|
852
|
+
case TCPOption.Selective_Acknowledgment: {
|
|
853
|
+
const optionSack: OPTION_SACK = optionItem as OPTION_SACK
|
|
854
|
+
const kindBuffer: Buffer = UInt8ToBuffer(5)
|
|
855
|
+
let length: number = 2
|
|
856
|
+
let blocksBuffer: Buffer = Buffer.from([])
|
|
857
|
+
optionSack.blocks.forEach((block: string): void => {
|
|
858
|
+
blocksBuffer = Buffer.concat([blocksBuffer, UInt64ToBuffer(HexToUInt64(block))])
|
|
859
|
+
})
|
|
860
|
+
const sackBuffer: Buffer = Buffer.concat([kindBuffer, UInt8ToBuffer(length + blocksBuffer.length), blocksBuffer])
|
|
861
|
+
this.writeBytes(optionOffset, sackBuffer)
|
|
862
|
+
optionOffset += sackBuffer.length
|
|
863
|
+
return
|
|
864
|
+
}
|
|
865
|
+
case TCPOption.Timestamp: {
|
|
866
|
+
const optionTS: OPTION_TS = optionItem as OPTION_TS
|
|
867
|
+
const tsBuffer: Buffer = Buffer.concat([
|
|
868
|
+
UInt8ToBuffer(8),
|
|
869
|
+
UInt8ToBuffer(10),
|
|
870
|
+
UInt32ToBuffer(optionTS.tsval ? optionTS.tsval : 0),
|
|
871
|
+
UInt32ToBuffer(optionTS.tsecr ? optionTS.tsecr : 0)
|
|
872
|
+
])
|
|
873
|
+
this.writeBytes(optionOffset, tsBuffer)
|
|
874
|
+
optionOffset += tsBuffer.length
|
|
875
|
+
return
|
|
876
|
+
}
|
|
877
|
+
case TCPOption.User_Timeout: {
|
|
878
|
+
const optionUTO: OPTION_UTO = optionItem as OPTION_UTO
|
|
879
|
+
const utoBuffer: Buffer = Buffer.concat([
|
|
880
|
+
UInt8ToBuffer(28),
|
|
881
|
+
UInt8ToBuffer(5),
|
|
882
|
+
UInt16ToBuffer(optionUTO.timeout ? optionUTO.timeout : 0),
|
|
883
|
+
UInt8ToBuffer(optionUTO.granularity ? optionUTO.granularity : 0)
|
|
884
|
+
])
|
|
885
|
+
this.writeBytes(optionOffset, utoBuffer)
|
|
886
|
+
optionOffset += utoBuffer.length
|
|
887
|
+
return
|
|
888
|
+
}
|
|
889
|
+
case TCPOption.TCP_Authentication_Option: {
|
|
890
|
+
const optionTcpAo: OPTION_TCP_AO = optionItem as OPTION_TCP_AO
|
|
891
|
+
const kindBuffer: Buffer = UInt8ToBuffer(29)
|
|
892
|
+
const dataBuffer: Buffer = Buffer.from(optionTcpAo.data, 'hex')
|
|
893
|
+
const lengthBuffer: Buffer = UInt8ToBuffer(dataBuffer.length + 2)
|
|
894
|
+
const tcpAoBuffer: Buffer = Buffer.concat([kindBuffer, lengthBuffer, dataBuffer])
|
|
895
|
+
this.writeBytes(optionOffset, tcpAoBuffer)
|
|
896
|
+
optionOffset += tcpAoBuffer.length
|
|
897
|
+
return
|
|
898
|
+
}
|
|
899
|
+
default: {
|
|
900
|
+
const defaultOptionItem: OPTION_DEFAULT = optionItem as OPTION_DEFAULT
|
|
901
|
+
const kind: number = defaultOptionItem.kind
|
|
902
|
+
const hexBuffer: Buffer = Buffer.from(defaultOptionItem.data.toString(), 'hex')
|
|
903
|
+
const length: number = hexBuffer.length + 2
|
|
904
|
+
const defaultOptionBuffer: Buffer = Buffer.concat([UInt8ToBuffer(kind), UInt8ToBuffer(length), hexBuffer])
|
|
905
|
+
this.writeBytes(optionOffset, defaultOptionBuffer)
|
|
906
|
+
optionOffset += defaultOptionBuffer.length
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
})
|
|
910
|
+
if (this.length > 60) return this.recordError(this.instance.options.getPath(), 'Options too large')
|
|
911
|
+
const headerBitLength: number = this.length * 8
|
|
912
|
+
if (headerBitLength % 4) {
|
|
913
|
+
//Add Padding
|
|
914
|
+
this.writeBytes(this.length, Buffer.from([0x00]))
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
public id: string = 'tcp'
|
|
922
|
+
|
|
923
|
+
public name: string = 'Transmission Control Protocol'
|
|
924
|
+
|
|
925
|
+
public match(): boolean {
|
|
926
|
+
if (!this.prevCodecModule) return false
|
|
927
|
+
if (this.prevCodecModule.instance.protocol.getValue() === 0x06) return true
|
|
928
|
+
return false
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
}
|