예제 #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 = EthernetProtocols_Fields.IP;
            }
            else
            {
                ethProtocol = ArrayHelper.extractInteger(bytes, offset, EthernetFields_Fields.ETH_CODE_LEN);
            }

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

            case EthernetProtocols_Fields.IP:
                // ethernet level code is recognized as IP, figure out what kind..
                int ipProtocol = IPProtocol.extractProtocol(lLen, bytes);
                switch (ipProtocol)
                {
                // icmp
                case IPProtocols_Fields.ICMP: return(new ICMPPacket(lLen, bytes, tv));

                // igmp

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

                // tcp

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

                // udp

                case 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));
            }
        }
예제 #2
0
 /// <summary> Fetch the urgent pointer.</summary>
 public virtual int getUrgentPointer()
 {
     if (!_urgentPointerSet)
     {
         _urgentPointer    = ArrayHelper.extractInteger(_bytes, _ipOffset + TCPFields_Fields.TCP_URG_POS, TCPFields_Fields.TCP_URG_LEN);
         _urgentPointerSet = true;
     }
     return(_urgentPointer);
 }
예제 #3
0
        /// <summary> Extract a string describing an IP address from an array of bytes.
        ///
        /// </summary>
        /// <param name="offset">the offset of the address data.
        /// </param>
        /// <param name="bytes">an array of bytes containing the IP address.
        /// </param>
        /// <returns> a string of the form "255.255.255.255"
        /// </returns>
        public static System.String extract(int offset, byte[] bytes)
        {
            return(toString(ArrayHelper.extractInteger(bytes, offset, WIDTH)));

            /*
             * StringBuffer sa = new StringBuffer();
             * for(int i=offset; i<offset + WIDTH; i++) {
             * sa.append(0xff & bytes[i]);
             * if(i != offset + WIDTH - 1)
             * sa.append('.');
             * }
             * return sa.toString();
             */
        }