public TcpStreamPacket(PPacket ppacket) { _direction = TcpDirection.SourceToDestination; //_connection = new TcpConnection(packet.Packet); _connection = ppacket.GetTcpConnection(); _ppacket = ppacket; _packet = ppacket.Packet; }
//private static void PrintSortedTcpStreamPacket(IndexedTcpConnection tcpConnection, PPacket ppacket) private static void PrintSortedTcpStreamPacket(PPacket ppacket) { TcpConnection tcpConnection = ppacket.GetTcpConnection(); if (_currentTcpConnection == null || tcpConnection.Index != _currentTcpConnection.Index) { Trace.WriteLine(); Trace.WriteLine("group packet time source dir destination protocol flags data seq next seq ack window urg data"); //_LastStreamNumber = tcpConnection.Index; _currentTcpConnection = tcpConnection; } //TcpDirection direction = TcpDirection.SourceToDestination; //string s = GetTcpStreamPacketString1(tcpConnection, ppacket, _currentTcpConnection.GetTcpDirection(tcpConnection), true); string s = GetTcpStreamPacketString1(ppacket, _currentTcpConnection.GetTcpDirection(tcpConnection), 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, ppacket.GetTcpDescription(), s2); Trace.WriteLine(s); }
public TcpStreamPacket(PPacket ppacket) { _direction = TcpDirection.SourceToDestination; //_connection = new TcpConnection(packet.Packet); _connection = ppacket.GetTcpConnection(); _ppacket = ppacket; _packet = ppacket.Packet; }
//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()); }