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