Example #1
0
        /// <summary> Convert captured packet data into an object.
        /// </summary>
        public static Packet dataToPacket(int linkType, byte[] bytes, Timeval tv)
        {
            int ethProtocol;

            // record the length of the headers associated with this link layer type.
            // this length is the offset to the header embedded in the packet.
            lLen = LinkLayer.getLinkLayerLength(linkType);

            // extract the protocol code for the type of header embedded in the
            // link-layer of the packet
            int offset = LinkLayer.getProtoOffset(linkType);

            if (offset == -1)
            {
                // if there is no embedded protocol, assume IP?
                ethProtocol = Packets.EthernetProtocols_Fields.IP;
            }
            else
            {
                ethProtocol = ArrayHelper.extractInteger(bytes, offset, Packets.EthernetFields.ETH_CODE_LEN);
            }

            // try to recognize the ethernet type..
            switch (ethProtocol)
            {
            // arp
            case Packets.EthernetProtocols_Fields.ARP:
                return(new ARPPacket(lLen, bytes, tv));

            case Packets.EthernetProtocols_Fields.IP:
                int ipProtocol = IPProtocol.extractProtocol(lLen, bytes);
                switch (ipProtocol)
                {
                // icmp
                case Packets.IPProtocols_Fields.ICMP:  return(new ICMPPacket(lLen, bytes, tv));

                // igmp

                case Packets.IPProtocols_Fields.IGMP:  return(new IGMPPacket(lLen, bytes, tv));

                // tcp

                case Packets.IPProtocols_Fields.TCP:  return(new TCPPacket(lLen, bytes, tv));

                // udp

                case Packets.IPProtocols_Fields.UDP:  return(new UDPPacket(lLen, bytes, tv));

                // unidentified ip..

                default:  return(new IPPacket(lLen, bytes, tv));
                }
            // ethernet level code not recognized, default to anonymous packet..
            //goto default;

            default:  return(new EthernetPacket(lLen, bytes, tv));
            }
        }
		/// <summary> Convert captured packet data into an object.
		/// </summary>
		public static Packet dataToPacket(int linkType, byte[] bytes, Timeval tv)
		{
			int ethProtocol;
			
			// record the length of the headers associated with this link layer type.
			// this length is the offset to the header embedded in the packet.
			lLen = LinkLayer.getLinkLayerLength(linkType);
			
			// extract the protocol code for the type of header embedded in the 
			// link-layer of the packet
			int offset = LinkLayer.getProtoOffset(linkType);
			if (offset == - 1)
			// if there is no embedded protocol, assume IP?
				ethProtocol = Packets.EthernetProtocols_Fields.IP;
			else
				ethProtocol = ArrayHelper.extractInteger(bytes, offset, Packets.EthernetFields.ETH_CODE_LEN);
			
			// try to recognize the ethernet type..
			switch (ethProtocol)
			{
				
				// arp
				case Packets.EthernetProtocols_Fields.ARP: 
					return new ARPPacket(lLen, bytes, tv);
				
				case Packets.EthernetProtocols_Fields.IP: 
					int ipProtocol = IPProtocol.extractProtocol(lLen, bytes);
					switch (ipProtocol)
					{
						
						// icmp
						case Packets.IPProtocols_Fields.ICMP:  return new ICMPPacket(lLen, bytes, tv);
							// igmp
						
						case Packets.IPProtocols_Fields.IGMP:  return new IGMPPacket(lLen, bytes, tv);
							// tcp
						
						case Packets.IPProtocols_Fields.TCP:  return new TCPPacket(lLen, bytes, tv);
							// udp
						
						case Packets.IPProtocols_Fields.UDP:  return new UDPPacket(lLen, bytes, tv);
							// unidentified ip..
						
						default:  return new IPPacket(lLen, bytes, tv);
						
					}
					// ethernet level code not recognized, default to anonymous packet..
					//goto default;
				
				default:  return new EthernetPacket(lLen, bytes, tv);
				
			}
		}
Example #3
0
 /// <summary> Create a new raw packet.
 /// *
 /// </summary>
 /// <param name="timeval">the time the packet arrived on the device where it was
 /// captured.
 /// </param>
 /// <param name="bytes">the raw packet data, including headers.
 /// </param>
 /// <param name="droplen">the number of bytes dropped (if any) when the packet
 /// was captured.
 ///
 /// </param>
 public RawPacket(Timeval timeval, byte[] bytes, int droplen)
 {
     this.timeval = timeval;
     this.bytes   = bytes;
     this.droplen = droplen;
 }
Example #4
0
 /// <summary> Create a new TCP packet.
 /// </summary>
 public TCPPacket(int lLen, byte[] bytes, Timeval tv) : this(lLen, bytes)
 {
     this._timeval = tv;
 }
Example #5
0
		/// <summary> Create a new IP packet.
		/// </summary>
		public IPPacket(int lLen, byte[] bytes, Timeval tv):this(lLen, bytes)
		{
			this._timeval = tv;
		}
Example #6
0
 /// <summary> Construct a new ethernet packet, including the capture time.
 /// </summary>
 public EthernetPacket(int lLen, byte[] bytes, Timeval tv) : this(lLen, bytes)
 {
     this._timeval = tv;
 }
Example #7
0
		/// <summary> Create a new raw packet.
		/// *
		/// </summary>
		/// <param name="timeval">the time the packet arrived on the device where it was 
		/// captured.
		/// </param>
		/// <param name="bytes">the raw packet data, including headers.
		/// </param>
		/// <param name="droplen">the number of bytes dropped (if any) when the packet 
		/// was captured.
		/// 
		/// </param>
		public RawPacket(Timeval timeval, byte[] bytes, int droplen)
		{
			this.timeval = timeval;
			this.bytes = bytes;
			this.droplen = droplen;
		}