Esempio n. 1
0
        private void SendRstPacket(EthernetPacket ethernetPacket, IPPacket ipPacket, TcpPacket tcpPacket)
        {
            var sourceHwAddress       = PhysicalAddress.Parse(ethernetPacket.SourceHwAddress.ToString());
            var sourceAddress         = IPAddress.Parse(ipPacket.SourceAddress.ToString());
            var acknowledgementNumber = tcpPacket.AcknowledgmentNumber;
            var sourcePort            = tcpPacket.SourcePort;

            ethernetPacket.SourceHwAddress      = ethernetPacket.DestinationHwAddress;
            ethernetPacket.DestinationHwAddress = sourceHwAddress;

            ipPacket.SourceAddress      = ipPacket.DestinationAddress;
            ipPacket.DestinationAddress = sourceAddress;

            tcpPacket.Syn = false;
            tcpPacket.Ack = false;
            tcpPacket.Rst = true;
            tcpPacket.AcknowledgmentNumber = tcpPacket.SequenceNumber;
            tcpPacket.SequenceNumber       = acknowledgementNumber;
            tcpPacket.SourcePort           = tcpPacket.DestinationPort;
            tcpPacket.DestinationPort      = sourcePort;
            tcpPacket.Checksum             = tcpPacket.CalculateTCPChecksum();

            ethernetPacket.UpdateCalculatedValues();
            ipPacket.UpdateCalculatedValues();
            tcpPacket.UpdateCalculatedValues();

            ipPacket.PayloadPacket       = tcpPacket;
            ethernetPacket.PayloadPacket = ipPacket;

            this.captureDevice.SendPacket(ethernetPacket);
        }