private void AddPingResult(HavokNet.Protocols.ICMP.PingResult result) { this.Dispatcher.Invoke(() => { echoReplies.Items.Add(result.ToString()); }); }
public override void OnReceivePacket(Common.PacketData pdata) { var packet = pdata.Packet; var fromIP = new Common.IPv4Address(packet.Ethernet.IpV4.Source.ToString()); var toIP = new Common.IPv4Address(packet.Ethernet.IpV4.Destination.ToString()); var ipv4 = packet.Ethernet.IpV4; var icmp = ipv4.Icmp; // Is this an echo request to our IP? if (icmp.MessageType == PcapDotNet.Packets.Icmp.IcmpMessageType.Echo && toIP.AsString == _client.Configuration.IpAddress.AsString) { SendIcmpReplyPacket(packet); } else if (icmp.MessageType == IcmpMessageType.EchoReply && CurrentPings.ContainsKey((packet.Ethernet.IpV4.Icmp as IcmpEchoReplyDatagram).Identifier)) { var reply = packet.Ethernet.IpV4.Icmp as IcmpEchoReplyDatagram; var request = CurrentPings[reply.Identifier]; PingResult result = new PingResult(packet, pdata.TimeStamp, request); result.Bytes = request.Bytes; request.Callback(result); } else if (icmp.MessageType == IcmpMessageType.TimeExceeded) { var reply = packet.Ethernet.IpV4.Icmp as IcmpTimeExceededDatagram; var replyEcho = reply.IpV4.Icmp as IcmpEchoDatagram; var request = CurrentPings[replyEcho.Identifier]; PingResult result = new PingResult(PingResultType.TtlExpired); result.RespondingHost = fromIP; result.Response = (int)(DateTime.Now - request.TimeStamp).TotalMilliseconds; request.Callback(result); } else if (icmp.MessageType == IcmpMessageType.DestinationUnreachable) { var reply = packet.Ethernet.IpV4.Icmp as IcmpDestinationUnreachableDatagram; var replyEcho = reply.IpV4.Icmp as IcmpDestinationUnreachableDatagram; //var request = CurrentPings[replyEcho.Identifier]; //PingResult result = new PingResult(PingResultType.DestinationHostUnreachable); //result.RespondingHost = fromIP; //result.Response = (int)(DateTime.Now - request.TimeStamp).TotalMilliseconds; //request.Callback(result); } }