private void WritePackets() { Packet packet = null; int countOfPacketCaptures = 0; while ((packet = _device.GetNextPacket()) != null) { packet = _device.GetNextPacket(); MyPacket tempPacket = null; if (packet is TCPPacket) { TCPPacket tcp = (TCPPacket)packet; tempPacket = MyPacket.GetInstance(); tempPacket.PacketType = "TCP"; tempPacket.SourceAddress = Convert.ToString(tcp.SourceAddress); tempPacket.DestinationAddress = Convert.ToString(tcp.DestinationAddress); tempPacket.SourcePort = Convert.ToString(tcp.SourcePort); tempPacket.DestinationPort = Convert.ToString(tcp.DestinationPort); tempPacket.PacketMessage = Convert.ToString(tcp.Data); } else if (packet is UDPPacket) { UDPPacket udp = (UDPPacket)packet; tempPacket = MyPacket.GetInstance(); tempPacket.PacketType = "UDP"; tempPacket.SourceAddress = Convert.ToString(udp.SourceAddress); tempPacket.DestinationAddress = Convert.ToString(udp.DestinationAddress); tempPacket.SourcePort = Convert.ToString(udp.SourcePort); tempPacket.DestinationPort = Convert.ToString(udp.DestinationPort); tempPacket.PacketMessage = Convert.ToString(udp.Data); } if (tempPacket != null) { _packetBinder.AddPacketToView(tempPacket); } } }