Example #1
0
 private void WriteData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
 {
     if (direction == TcpDirection.SourceToDestination)
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_fileStreamRequest == null)
             {
                 _fileStreamRequest = new FileStream(_file + "_request_" + _indexRequest++.ToString() + ".data", FileMode.Create, FileAccess.Write, FileShare.Read);
             }
             _fileStreamRequest.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CloseStreamRequest();
         }
     }
     else
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_fileStreamReply == null)
             {
                 _fileStreamReply = new FileStream(_file + "_reply_" + _indexReply++.ToString() + ".data", FileMode.Create, FileAccess.Write, FileShare.Read);
             }
             _fileStreamReply.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CloseStreamReply();
         }
     }
 }
Example #2
0
 private void WriteData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
 {
     if (direction == TcpDirection.SourceToDestination)
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_fileStreamRequest == null)
                 _fileStreamRequest = new FileStream(_file + "_request_" + _indexRequest++.ToString() + ".data", FileMode.Create, FileAccess.Write, FileShare.Read);
             _fileStreamRequest.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CloseStreamRequest();
         }
     }
     else
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_fileStreamReply == null)
                 _fileStreamReply = new FileStream(_file + "_reply_" + _indexReply++.ToString() + ".data", FileMode.Create, FileAccess.Write, FileShare.Read);
             _fileStreamReply.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CloseStreamReply();
         }
     }
 }
Example #3
0
 public TcpStreamPacket(PPacket ppacket)
 {
     _direction = TcpDirection.SourceToDestination;
     //_connection = new TcpConnection(packet.Packet);
     _connection = ppacket.GetTcpConnection();
     _ppacket    = ppacket;
     _packet     = ppacket.Packet;
 }
Example #4
0
        private void TraceData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
        {
            string type;

            if (direction == TcpDirection.SourceToDestination)
            {
                type = "request";
            }
            else
            {
                type = "reply";
            }
            if (operation == TcpStreamOperation.Data)
            {
                _trace.WriteLine("{0,-43}  {1,-7}  {2,-30}  0x{3} 0x{4}  {5,-5}   {6,10:0.000000}",
                                 _connectionName, type, info.Message, info.PPacket.Packet.Ethernet.IpV4.Tcp.SequenceNumber.zToHex(), info.NextSequenceNumber.zToHex(),
                                 info.PPacket.PacketNumber, info.PPacket.RelativeTime.TotalSeconds);
            }
            else if (operation == TcpStreamOperation.EndOfData)
            {
                _trace.WriteLine("{0,-43}  {1,-7}  end of data", _connectionName, type);
            }
        }
Example #5
0
 private void WriteData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
 {
     if (direction == TcpDirection.SourceToDestination)
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_streamRequest == null)
             {
                 _streamRequest    = new MemoryStream();
                 _requestTimestamp = info.PPacket.Packet.Timestamp;
             }
             _streamRequest.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CreateRequestPacket();
             CloseStreamRequest();
         }
     }
     else
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_streamReply == null)
             {
                 _streamReply    = new MemoryStream();
                 _replyTimestamp = info.PPacket.Packet.Timestamp;
             }
             _streamReply.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CreateRequestReply();
             CloseStreamReply();
         }
     }
 }
Example #6
0
 public TcpStreamPacket(PPacket ppacket)
 {
     _direction = TcpDirection.SourceToDestination;
     //_connection = new TcpConnection(packet.Packet);
     _connection = ppacket.GetTcpConnection();
     _ppacket = ppacket;
     _packet = ppacket.Packet;
 }
Example #7
0
 public TcpStreamPacket(Packet packet)
 {
     _direction = TcpDirection.SourceToDestination;
     _connection = new TcpConnection(packet);
     _packet = packet;
 }
Example #8
0
        //public static string GetTcpStreamPacketString1(IndexedTcpConnection tcpConnection, PPacket ppacket, TcpDirection direction, bool printData)
        public static string GetTcpStreamPacketString1(PPacket ppacket, TcpDirection direction, bool printData)
        {
            IpV4Datagram ip     = ppacket.Ipv4;
            TcpDatagram  tcp    = ppacket.Tcp;
            string       saddr  = null;
            string       daddr  = null;
            string       mf     = null;
            string       offset = null;
            string       id     = null;

            if (ip != null)
            {
                saddr = ip.Source.ToString();
                daddr = ip.Destination.ToString();
                if (tcp != null)
                {
                    saddr += ":" + tcp.SourcePort.ToString();
                    daddr += ":" + tcp.DestinationPort.ToString();
                }
                //mf = ip.MoreFragment.ToString();
                mf     = (ip.Fragmentation.Options == IpV4FragmentationOptions.MoreFragments).ToString();
                offset = ip.Fragmentation.Offset.zToHex();
                id     = ip.Identification.zToHex();
            }
            StringBuilder sb = new StringBuilder();
            //direction
            string dir = null;

            //if (direction != null)
            //{
            if (direction == TcpDirection.SourceToDestination)
            {
                dir = "-->   ";
            }
            else
            {
                dir = "<--   ";
                string addr = saddr;
                saddr = daddr;
                daddr = addr;
            }
            //}
            //sb.Append(string.Format("{0,5}  {1,5}  {2,10:0.000000}  {3,-21}  {4}{5,-21} {6,-7}", packet.gGroupNumber, packet.PacketNumber, packet.RelativeTime.TotalSeconds, saddr, dir, daddr, packet.ProtocolCode));
            sb.Append(string.Format("{0,5}  {1,5}  {2,10:0.000000}  {3,-21}  {4}{5,-21} {6,-7}",
                                    ppacket.GetTcpConnection().Index, ppacket.PacketNumber, ppacket.RelativeTime.TotalSeconds, saddr, dir, daddr, ppacket.IpProtocolCode));
            string align = "";

            if (tcp != null)
            {
                string next_seq;
                if (tcp.PayloadLength > 0)
                {
                    next_seq = "0x" + (tcp.SequenceNumber + (uint)tcp.PayloadLength).zToHex();
                }
                else if (tcp.IsSynchronize)
                {
                    next_seq = "0x" + (tcp.SequenceNumber + 1).zToHex();
                }
                else
                {
                    next_seq = "          ";
                }
                string dataLength;
                if (tcp.PayloadLength > 0)
                {
                    dataLength = "0x" + ((ushort)tcp.PayloadLength).zToHex();
                }
                else
                {
                    dataLength = "      ";
                }
                string ack_seq;
                if (tcp.AcknowledgmentNumber != 0)
                {
                    ack_seq = "0x" + tcp.AcknowledgmentNumber.zToHex();
                }
                else
                {
                    ack_seq = "          ";
                }
                string urg_ptr = null;
                if (tcp.UrgentPointer != 0)
                {
                    urg_ptr = " 0x" + tcp.UrgentPointer.zToHex();
                }
                else
                {
                    align += "       ";
                }
                //TCPFlags(tcp)
                //tcp.GetFlagsString()
                sb.Append(string.Format("  {0,-20} {1} 0x{2} {3} {4} 0x{5}{6}", ppacket.GetTcpFlagsString(), dataLength, tcp.SequenceNumber.zToHex(), next_seq, ack_seq, tcp.Window.zToHex(), urg_ptr));
            }
            else
            {
                align += "                                                                                    ";
            }
            sb.Append(align + "   ");
            HttpDatagram http = tcp.Http;

            if (http != null)
            {
                sb.Append("http ");
                if (http.IsRequest)
                {
                    sb.Append("request");
                }
                else if (http.IsResponse)
                {
                    sb.Append("reply  ");
                }
                else
                {
                    sb.Append("????   ");
                }
                //sb.Append(http.Version.ToString());
            }
            else
            {
                sb.Append("                      ");
            }
            if (printData && tcp != null && tcp.PayloadLength > 0)
            {
                //sb.Append(align + "   ");
                //byte[] data = tcp.Payload;
                int i = 0;
                //int maxDataChar = 100;
                int maxDataChar = 50;
                foreach (byte b in tcp.Payload)
                {
                    if (++i > maxDataChar)
                    {
                        break;
                    }
                    sb.Append(" ");
                    sb.Append(b.zToHex());
                }
                sb.Append("  ");
                i = 0;
                foreach (byte b in tcp.Payload)
                {
                    if (++i > maxDataChar)
                    {
                        break;
                    }
                    if (b >= 32 && b <= 126)
                    {
                        sb.Append((char)b);
                    }
                    else
                    {
                        sb.Append('.');
                    }
                }
            }
            return(sb.ToString());
        }
Example #9
0
 public TcpStreamPacket(Packet packet)
 {
     _direction  = TcpDirection.SourceToDestination;
     _connection = new TcpConnection(packet);
     _packet     = packet;
 }
Example #10
0
 //public static string GetTcpStreamPacketString1(IndexedTcpConnection tcpConnection, PPacket ppacket, TcpDirection direction, bool printData)
 public static string GetTcpStreamPacketString1(PPacket ppacket, TcpDirection direction, bool printData)
 {
     IpV4Datagram ip = ppacket.Ipv4;
     TcpDatagram tcp = ppacket.Tcp;
     string saddr = null;
     string daddr = null;
     string mf = null;
     string offset = null;
     string id = null;
     if (ip != null)
     {
         saddr = ip.Source.ToString();
         daddr = ip.Destination.ToString();
         if (tcp != null)
         {
             saddr += ":" + tcp.SourcePort.ToString();
             daddr += ":" + tcp.DestinationPort.ToString();
         }
         //mf = ip.MoreFragment.ToString();
         mf = (ip.Fragmentation.Options == IpV4FragmentationOptions.MoreFragments).ToString();
         offset = ip.Fragmentation.Offset.zToHex();
         id = ip.Identification.zToHex();
     }
     StringBuilder sb = new StringBuilder();
     //direction
     string dir = null;
     //if (direction != null)
     //{
         if (direction == TcpDirection.SourceToDestination)
             dir = "-->   ";
         else
         {
             dir = "<--   ";
             string addr = saddr;
             saddr = daddr;
             daddr = addr;
         }
     //}
     //sb.Append(string.Format("{0,5}  {1,5}  {2,10:0.000000}  {3,-21}  {4}{5,-21} {6,-7}", packet.gGroupNumber, packet.PacketNumber, packet.RelativeTime.TotalSeconds, saddr, dir, daddr, packet.ProtocolCode));
     sb.Append(string.Format("{0,5}  {1,5}  {2,10:0.000000}  {3,-21}  {4}{5,-21} {6,-7}",
         ppacket.GetTcpConnection().Index, ppacket.PacketNumber, ppacket.RelativeTime.TotalSeconds, saddr, dir, daddr, ppacket.IpProtocolCode));
     string align = "";
     if (tcp != null)
     {
         string next_seq;
         if (tcp.PayloadLength > 0)
             next_seq = "0x" + (tcp.SequenceNumber + (uint)tcp.PayloadLength).zToHex();
         else if (tcp.IsSynchronize)
             next_seq = "0x" + (tcp.SequenceNumber + 1).zToHex();
         else
             next_seq = "          ";
         string dataLength;
         if (tcp.PayloadLength > 0)
             dataLength = "0x" + ((ushort)tcp.PayloadLength).zToHex();
         else
             dataLength = "      ";
         string ack_seq;
         if (tcp.AcknowledgmentNumber != 0)
             ack_seq = "0x" + tcp.AcknowledgmentNumber.zToHex();
         else
             ack_seq = "          ";
         string urg_ptr = null;
         if (tcp.UrgentPointer != 0)
             urg_ptr = " 0x" + tcp.UrgentPointer.zToHex();
         else
             align += "       ";
         //TCPFlags(tcp)
         //tcp.GetFlagsString()
         sb.Append(string.Format("  {0,-20} {1} 0x{2} {3} {4} 0x{5}{6}", ppacket.GetTcpFlagsString(), dataLength, tcp.SequenceNumber.zToHex(), next_seq, ack_seq, tcp.Window.zToHex(), urg_ptr));
     }
     else
         align += "                                                                                    ";
     sb.Append(align + "   ");
     HttpDatagram http = tcp.Http;
     if (http != null)
     {
         sb.Append("http ");
         if (http.IsRequest)
             sb.Append("request");
         else if (http.IsResponse)
             sb.Append("reply  ");
         else
             sb.Append("????   ");
         //sb.Append(http.Version.ToString());
     }
     else
         sb.Append("                      ");
     if (printData && tcp != null && tcp.PayloadLength > 0)
     {
         //sb.Append(align + "   ");
         //byte[] data = tcp.Payload;
         int i = 0;
         //int maxDataChar = 100;
         int maxDataChar = 50;
         foreach (byte b in tcp.Payload)
         {
             if (++i > maxDataChar)
                 break;
             sb.Append(" ");
             sb.Append(b.zToHex());
         }
         sb.Append("  ");
         i = 0;
         foreach (byte b in tcp.Payload)
         {
             if (++i > maxDataChar)
                 break;
             if (b >= 32 && b <= 126)
                 sb.Append((char)b);
             else
                 sb.Append('.');
         }
     }
     return sb.ToString();
 }
Example #11
0
 private void WriteData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
 {
     if (direction == TcpDirection.SourceToDestination)
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_streamRequest == null)
             {
                 _streamRequest = new MemoryStream();
                 _requestTimestamp = info.PPacket.Packet.Timestamp;
             }
             _streamRequest.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CreateRequestPacket();
             CloseStreamRequest();
         }
     }
     else
     {
         if (operation == TcpStreamOperation.Data)
         {
             if (_streamReply == null)
             {
                 _streamReply = new MemoryStream();
                 _replyTimestamp = info.PPacket.Packet.Timestamp;
             }
             _streamReply.Write(data, 0, data.Length);
         }
         else if (operation == TcpStreamOperation.EndOfData)
         {
             CreateRequestReply();
             CloseStreamReply();
         }
     }
 }
Example #12
0
 private void TraceData(TcpDirection direction, TcpStreamOperation operation, byte[] data, TcpStreamWriteDataInfo info)
 {
     string type;
     if (direction == TcpDirection.SourceToDestination)
         type = "request";
     else
         type = "reply";
     if (operation == TcpStreamOperation.Data)
         _trace.WriteLine("{0,-43}  {1,-7}  {2,-30}  0x{3} 0x{4}  {5,-5}   {6,10:0.000000}",
             _connectionName, type, info.Message, info.PPacket.Packet.Ethernet.IpV4.Tcp.SequenceNumber.zToHex(), info.NextSequenceNumber.zToHex(),
             info.PPacket.PacketNumber, info.PPacket.RelativeTime.TotalSeconds);
     else if (operation == TcpStreamOperation.EndOfData)
         _trace.WriteLine("{0,-43}  {1,-7}  end of data", _connectionName, type);
 }