/// <summary> /// Can be used to test pinging to a network address from Cosmos /// </summary> /// <param name="dest">IP Address of destination</param> public static void Ping(IPv4Address dest) { IPv4Address source = FindNetwork(dest); if (source == null) { Console.WriteLine("Destination Network Unreachable!!"); return; } ICMP.ICMPEchoRequest request = new ICMP.ICMPEchoRequest(source, dest, 0x10, 1); TCPIP.IPv4OutgoingBuffer.AddPacket(request); }
internal ICMPEchoReply(ICMPEchoRequest request) : base(request.DestinationIP, request.SourceIP, 0, 0, request.ICMP_ID, request.ICMP_Sequence, (UInt16)(request.ICMP_DataLength + 8)) { for (int b = 0; b < this.ICMP_DataLength; b++) { mRawData[this.dataOffset + 8 + b] = request.RawData[this.dataOffset + 8 + b]; } mRawData[this.dataOffset + 2] = 0x00; mRawData[this.dataOffset + 3] = 0x00; icmpCRC = CalcICMPCRC((UInt16)(this.ICMP_DataLength + 8)); mRawData[this.dataOffset + 2] = (byte)((icmpCRC >> 8) & 0xFF); mRawData[this.dataOffset + 3] = (byte)((icmpCRC >> 0) & 0xFF); }
internal ICMPEchoReply(ICMPEchoRequest request) : base(request.DestinationIP, request.SourceIP, 0, 0, request.ICMP_ID, request.ICMP_Sequence, (UInt16)(request.ICMP_DataLength + 8)) { for (int b = 0; b < this.ICMP_DataLength; b++) { mRawData[this.dataOffset + 8 + b] = request.RawData[this.dataOffset + 8 + b]; } mRawData[this.dataOffset + 2] = 0x00; mRawData[this.dataOffset + 3] = 0x00; icmpCRC = CalcICMPCRC((UInt16)(this.ICMP_DataLength + 8)); mRawData[this.dataOffset + 2] = (byte)((icmpCRC >> 8) & 0xFF); mRawData[this.dataOffset + 3] = (byte)((icmpCRC >> 0) & 0xFF); }
private static void IPv4_ICMPHandler(byte[] packetData) { ICMP.ICMPPacket icmp_packet = new ICMP.ICMPPacket(packetData); switch (icmp_packet.ICMP_Type) { case 0: ICMP.ICMPEchoReply recvd_reply = new ICMP.ICMPEchoReply(packetData); Console.WriteLine("Received ICMP Echo reply from " + recvd_reply.SourceIP.ToString()); break; case 8: ICMP.ICMPEchoRequest request = new ICMP.ICMPEchoRequest(packetData); ICMP.ICMPEchoReply reply = new ICMP.ICMPEchoReply(request); Console.WriteLine("Sending ICMP Echo reply to " + reply.DestinationIP.ToString()); TCPIP.IPv4OutgoingBuffer.AddPacket(reply); break; } }
/// <summary> /// Can be used to test pinging to a network address from Cosmos /// </summary> /// <param name="dest">IP Address of destination</param> public static void Ping(IPv4Address dest) { IPv4Address source = FindNetwork(dest); if (source == null) { Console.WriteLine("Destination Network Unreachable!!"); return; } ICMP.ICMPEchoRequest request = new ICMP.ICMPEchoRequest(source, dest, 0x10, 1); TCPIP.IPv4OutgoingBuffer.AddPacket(request); }
private static void IPv4_ICMPHandler(byte[] packetData) { ICMP.ICMPPacket icmp_packet = new ICMP.ICMPPacket(packetData); switch (icmp_packet.ICMP_Type) { case 0: ICMP.ICMPEchoReply recvd_reply = new ICMP.ICMPEchoReply(packetData); Console.WriteLine("Received ICMP Echo reply from " + recvd_reply.SourceIP.ToString()); break; case 8: ICMP.ICMPEchoRequest request = new ICMP.ICMPEchoRequest(packetData); ICMP.ICMPEchoReply reply = new ICMP.ICMPEchoReply(request); Console.WriteLine("Sending ICMP Echo reply to " + reply.DestinationIP.ToString()); TCPIP.IPv4OutgoingBuffer.AddPacket(reply); break; } }