mscorlib(4.0.0.0) API with additions
PingReply.cs
2 
4 {
6  public class PingReply
7  {
8  private IPAddress address;
9 
10  private PingOptions options;
11 
12  private IPStatus ipStatus;
13 
14  private long rtt;
15 
16  private byte[] buffer;
17 
20  public IPStatus Status => ipStatus;
21 
24  public IPAddress Address => address;
25 
28  public long RoundtripTime => rtt;
29 
32  public PingOptions Options => options;
33 
36  public byte[] Buffer => buffer;
37 
38  internal PingReply()
39  {
40  }
41 
42  internal PingReply(IPStatus ipStatus)
43  {
44  this.ipStatus = ipStatus;
45  buffer = new byte[0];
46  }
47 
48  internal PingReply(byte[] data, int dataLength, IPAddress address, int time)
49  {
50  this.address = address;
51  rtt = time;
52  ipStatus = GetIPStatus((IcmpV4Type)data[20], (IcmpV4Code)data[21]);
53  if (ipStatus == IPStatus.Success)
54  {
55  buffer = new byte[dataLength - 28];
56  Array.Copy(data, 28, buffer, 0, dataLength - 28);
57  }
58  else
59  {
60  buffer = new byte[0];
61  }
62  }
63 
64  internal PingReply(IcmpEchoReply reply)
65  {
66  address = new IPAddress(reply.address);
67  ipStatus = (IPStatus)reply.status;
68  if (ipStatus == IPStatus.Success)
69  {
70  rtt = reply.roundTripTime;
71  buffer = new byte[reply.dataSize];
72  Marshal.Copy(reply.data, buffer, 0, reply.dataSize);
73  options = new PingOptions(reply.options);
74  }
75  else
76  {
77  buffer = new byte[0];
78  }
79  }
80 
81  internal PingReply(Icmp6EchoReply reply, IntPtr dataPtr, int sendSize)
82  {
83  address = new IPAddress(reply.Address.Address, reply.Address.ScopeID);
84  ipStatus = (IPStatus)reply.Status;
85  if (ipStatus == IPStatus.Success)
86  {
87  rtt = reply.RoundTripTime;
88  buffer = new byte[sendSize];
89  Marshal.Copy(IntPtrHelper.Add(dataPtr, 36), buffer, 0, sendSize);
90  }
91  else
92  {
93  buffer = new byte[0];
94  }
95  }
96 
97  private IPStatus GetIPStatus(IcmpV4Type type, IcmpV4Code code)
98  {
99  switch (type)
100  {
101  case IcmpV4Type.ICMP4_ECHO_REPLY:
102  return IPStatus.Success;
103  case IcmpV4Type.ICMP4_SOURCE_QUENCH:
104  return IPStatus.SourceQuench;
105  case IcmpV4Type.ICMP4_PARAM_PROB:
106  return IPStatus.ParameterProblem;
107  case IcmpV4Type.ICMP4_TIME_EXCEEDED:
108  return IPStatus.TtlExpired;
109  case IcmpV4Type.ICMP4_DST_UNREACH:
110  switch (code)
111  {
112  case IcmpV4Code.ICMP4_UNREACH_NET:
113  return IPStatus.DestinationNetworkUnreachable;
114  case IcmpV4Code.ICMP4_UNREACH_HOST:
115  return IPStatus.DestinationHostUnreachable;
116  case IcmpV4Code.ICMP4_UNREACH_PROTOCOL:
117  return IPStatus.DestinationProtocolUnreachable;
118  case IcmpV4Code.ICMP4_UNREACH_PORT:
119  return IPStatus.DestinationPortUnreachable;
120  case IcmpV4Code.ICMP4_UNREACH_FRAG_NEEDED:
121  return IPStatus.PacketTooBig;
122  default:
123  return IPStatus.DestinationUnreachable;
124  }
125  default:
126  return IPStatus.Unknown;
127  }
128  }
129  }
130 }
IPStatus Status
Gets the status of an attempt to send an Internet Control Message Protocol (ICMP) echo request and re...
Definition: PingReply.cs:20
Used to control how T:System.Net.NetworkInformation.Ping data packets are transmitted.
Definition: PingOptions.cs:4
Definition: __Canon.cs:3
long RoundtripTime
Gets the number of milliseconds taken to send an Internet Control Message Protocol (ICMP) echo reques...
Definition: PingReply.cs:28
PingOptions Options
Gets the options used to transmit the reply to an Internet Control Message Protocol (ICMP) echo reque...
Definition: PingReply.cs:32
Provides information about the status and data resulting from a Overload:System.Net....
Definition: PingReply.cs:6
Provides an Internet Protocol (IP) address.
Definition: IPAddress.cs:10
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointe...
Definition: Marshal.cs:301
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
Manipulates arrays of primitive types.
Definition: Buffer.cs:11
IPAddress Address
Gets the address of the host that sends the Internet Control Message Protocol (ICMP) echo reply.
Definition: PingReply.cs:24
IPStatus
Reports the status of sending an Internet Control Message Protocol (ICMP) echo message to a computer.
Definition: IPStatus.cs:4