Ejemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Login.Length != 0)
            {
                hash ^= Login.GetHashCode();
            }
            if (SourceIP.Length != 0)
            {
                hash ^= SourceIP.GetHashCode();
            }
            if (logonDate_ != null)
            {
                hash ^= LogonDate.GetHashCode();
            }
            if (IsSuccesful != false)
            {
                hash ^= IsSuccesful.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            string p_SourceIP      = SourceIP.ToString();
            string p_DestinationIP = DestinationIP.ToString();
            string Data            = Regex.Replace(Encoding.ASCII.GetString(PacketDataGet()), @"[^a-zA-Z_0-9\.\@\- ]", "");

            return("UDP " + p_SourceIP + ":" + UDP_SourcePort + " --> " + p_DestinationIP + " : " + UDP_DestinationPort + "-->" + Data);
        }
Ejemplo n.º 3
0
        // adaptation from http://www.netfor2.com/udpsum.htm
        private ushort GetUDPChecksum()
        {
            UInt32 sum = 0;

            for (uint i = this.start; i < this.start + 6; i += 2)
            {
                sum += (UInt32)(data->m_IBuffer[i] << 8) | data->m_IBuffer[i + 1];
            }
            for (uint i = this.start + 8; i < TotalLength + base.LayerStart() - 1; i += 2)
            {
                sum += (UInt32)(data->m_IBuffer[i] << 8) | data->m_IBuffer[i + 1];
            }
            if (((TotalLength + base.LayerStart()) % 2) == 1)
            {
                sum += (UInt32)(data->m_IBuffer[TotalLength + base.LayerStart() - 1] << 8);
            }

            // src addr
            byte[] srcB = SourceIP.GetAddressBytes();
            for (int i = 0; i < 4; i += 2)
            {
                sum += (UInt32)(((srcB[i] << 8) & 0xFF00) | (srcB[i + 1] & 0xFF));
            }

            // dst addr
            byte[] destB = DestIP.GetAddressBytes();
            for (int i = 0; i < 4; i += 2)
            {
                sum += (UInt32)(((destB[i] << 8) & 0xFF00) | (destB[i + 1] & 0xFF));
            }

            // proto
            sum += 0x00011;

            // length
            sum += ((UInt16)(TotalLength - (base.LayerLength())));

            // 1's compliment
            while ((sum >> 16) != 0)
            {
                sum = ((sum & 0xFFFF) + (sum >> 16));
            }

            sum = ~sum;

            return((ushort)sum);
        }
Ejemplo n.º 4
0
        public byte[] ToBytes()
        {
            Checksum = 0;
            byte[] header = new byte[IHL * 4];
            header[0]  = (byte)((Version << 4) | IHL);
            header[1]  = (byte)((DSCP << 2) | ECN);
            header[2]  = (byte)(TotalLength >> 8);
            header[3]  = (byte)(TotalLength & 0xFF);
            header[4]  = (byte)(Id >> 8);
            header[5]  = (byte)(Id & 0xFF);
            header[6]  = (byte)((Flags << 5) | (FragmentOffset >> 8));
            header[7]  = (byte)(FragmentOffset & 0xFF);
            header[8]  = (byte)TTL;
            header[9]  = (byte)Protocol;
            header[10] = (byte)(Checksum >> 8);
            header[11] = (byte)(Checksum & 0xFF);
            int[] ip = SourceIP.Split('.').Select(int.Parse).ToArray();
            header[12] = (byte)ip[0];
            header[13] = (byte)ip[1];
            header[14] = (byte)ip[2];
            header[15] = (byte)ip[3];
            ip         = DestIP.Split('.').Select(int.Parse).ToArray();
            header[16] = (byte)ip[0];
            header[17] = (byte)ip[1];
            header[18] = (byte)ip[2];
            header[19] = (byte)ip[3];
            long sum = 0;

            for (int i = 0; i < IHL * 4; i += 2)
            {
                sum += ((header[i] << 8) & 0xFF00) + (header[i + 1] & 0xFF);
            }
            while ((sum >> 16) != 0)
            {
                sum = (sum & 0xFFFF) + (sum >> 16);
            }
            Checksum   = (ushort)(~sum);
            header[10] = (byte)(Checksum >> 8);
            header[11] = (byte)(Checksum & 0xFF);
            return(header);
        }
 public void ToBinary(BinaryWriter writer)
 {
     SourceIP.WriteBinary(writer);
     DestinationIP.WriteBinary(writer);
     writer.Write(Timestamp.Ticks);
 }