Esempio n. 1
0
        /// <summary>
        /// Received reply.
        /// </summary>

        /// <summary>
        /// Create new instance of the <see cref="ICMPPacket"/> class.
        /// </summary>
        /// <param name="packetData">Packet data.</param>
        /// <exception cref="ArgumentException">Thrown if packetData is invalid.</exception>
        internal static void ICMPHandler(byte[] packetData)
        {
            Global.mDebugger.Send("ICMP Handler called");
            var icmp_packet = new ICMPPacket(packetData);

            switch (icmp_packet.ICMPType)
            {
            case 0:
                var receiver = ICMPClient.GetClient(icmp_packet.SourceIP.Hash);
                if (receiver != null)
                {
                    receiver.ReceiveData(icmp_packet);
                }
                Global.mDebugger.Send("Received ICMP Echo reply from " + icmp_packet.SourceIP.ToString());
                break;

            case 8:
                var request = new ICMPEchoRequest(packetData);
                var reply   = new ICMPEchoReply(request);
                Global.mDebugger.Send("Sending ICMP Echo reply to " + reply.DestinationIP.ToString());
                OutgoingBuffer.AddPacket(reply);
                NetworkStack.Update();
                break;
            }
        }
Esempio n. 2
0
 internal static void ICMPHandler(byte[] packetData)
 {
     ICMPPacket icmp_packet = new ICMPPacket(packetData);
     switch (icmp_packet.ICMP_Type)
     {
         case 0:
             ICMPEchoReply recvd_reply = new ICMPEchoReply(packetData);
             Sys.Console.WriteLine("Received ICMP Echo reply from " + recvd_reply.SourceIP.ToString());
             break;
         case 8:
             ICMPEchoRequest request = new ICMPEchoRequest(packetData);
             Sys.Console.WriteLine("Received " + request.ToString());
             ICMPEchoReply reply = new ICMPEchoReply(request);
             Sys.Console.WriteLine("Sending ICMP Echo reply to " + reply.DestinationIP.ToString());
             OutgoingBuffer.AddPacket(reply);
             break;
     }
 }
Esempio n. 3
0
        internal static void ICMPHandler(byte[] packetData)
        {
            ICMPPacket icmp_packet = new ICMPPacket(packetData);

            switch (icmp_packet.ICMP_Type)
            {
            case 0:
                ICMPEchoReply recvd_reply = new ICMPEchoReply(packetData);
                Sys.Console.WriteLine("Received ICMP Echo reply from " + recvd_reply.SourceIP.ToString());
                break;

            case 8:
                ICMPEchoRequest request = new ICMPEchoRequest(packetData);
                Sys.Console.WriteLine("Received " + request.ToString());
                ICMPEchoReply reply = new ICMPEchoReply(request);
                Sys.Console.WriteLine("Sending ICMP Echo reply to " + reply.DestinationIP.ToString());
                OutgoingBuffer.AddPacket(reply);
                break;
            }
        }
Esempio n. 4
0
        internal static void ICMPHandler(byte[] packetData)
        {
            NetworkStack.debugger.Send("ICMP Handler called");
            ICMPPacket icmp_packet = new ICMPPacket(packetData);

            switch (icmp_packet.ICMP_Type)
            {
            case 0:
                recvd_reply = new ICMPEchoReply(packetData);
                NetworkStack.debugger.Send("Received ICMP Echo reply from " + recvd_reply.SourceIP.ToString());
                break;

            case 8:
                ICMPEchoRequest request = new ICMPEchoRequest(packetData);
                NetworkStack.debugger.Send("Received " + request.ToString());
                ICMPEchoReply reply = new ICMPEchoReply(request);
                NetworkStack.debugger.Send("Sending ICMP Echo reply to " + reply.DestinationIP.ToString());
                OutgoingBuffer.AddPacket(reply);
                NetworkStack.Update();
                break;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Receive data
        /// </summary>
        /// <param name="source">Source end point.</param>
        /// <param name="timeout">timeout value, default 5000ms
        /// <returns>Address from Domain Name</returns>
        /// <exception cref="InvalidOperationException">Thrown on fatal error (contact support).</exception>
        public int Receive(ref EndPoint source, int timeout = 5000)
        {
            int second  = 0;
            int _deltaT = 0;

            while (rxBuffer.Count < 1)
            {
                if (second > (timeout / 1000))
                {
                    return(-1);
                }
                if (_deltaT != RTC.Second)
                {
                    second++;
                    _deltaT = RTC.Second;
                }
            }

            ICMPEchoReply packet = new ICMPEchoReply(rxBuffer.Dequeue().RawData);

            source.Address = packet.SourceIP;

            return(second);
        }