Example #1
0
 public static string GetStreamPacketString1(Pib.Pcap.Test.TcpStreamPacket streamPacket, TcpDirection? direction, bool printData)
 {
     IpV4Datagram ip = streamPacket.PPacket.Ipv4;
     TcpDatagram tcp = streamPacket.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 ((TcpDirection)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}",
         streamPacket.StreamNumber, streamPacket.PPacket.PacketNumber, streamPacket.PPacket.RelativeTime.TotalSeconds, saddr, dir, daddr, streamPacket.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}", streamPacket.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 #2
0
 /// <summary>
 /// Create a ValidationPolicyFromPib to use the given PIB.
 /// </summary>
 ///
 /// <param name="pib">The PIB with certificates.</param>
 public ValidationPolicyFromPib(Pib pib)
 {
     pib_ = pib;
 }
Example #3
0
        private static void PrintStreamPacket(Pib.Pcap.Test.TcpStreamPacket streamPacket)
        {
            if (streamPacket.StreamNumber != _LastStreamNumber)
            {
                Trace.WriteLine();
                Trace.WriteLine("group packet    time      source                 dir   destination           protocol flags                data   seq        next seq   ack        window urg       data");
                _LastStreamNumber = streamPacket.StreamNumber;
            }
            string s = GetStreamPacketString1(streamPacket, streamPacket.Direction, true);
            string s2 = null;
            foreach (Pib.Pcap.Test.TcpPacketError error in streamPacket.Errors)
                s2 = s2.zAddValue(streamPacket.GetErrorMessage(error));

            if (s2 != null)
                s2 = " " + s2;
            Trace.WriteLine("{0,-162}{1}{2}", s, streamPacket.PacketDescription, s2);
        }