return Send (addresses [0], timeout, buffer, options);
}
- static IPAddress GetNonLoopbackIPV4 ()
- {
-#pragma warning disable 618
- foreach (IPAddress addr in Dns.GetHostByName (Dns.GetHostName ()).AddressList)
- if (!IPAddress.IsLoopback (addr) && addr.AddressFamily == AddressFamily.InterNetwork)
- return addr;
-#pragma warning restore 618
-
- throw new InvalidOperationException ("Could not resolve non-loopback IP address for localhost");
- }
-
public PingReply Send (IPAddress address, int timeout, byte [] buffer, PingOptions options)
{
if (address == null)
private PingReply SendPrivileged (IPAddress address, int timeout, byte [] buffer, PingOptions options)
{
IPEndPoint target = new IPEndPoint (address, 0);
- IPEndPoint client = new IPEndPoint (GetNonLoopbackIPV4 (), 0);
-
+
// FIXME: support IPv6
using (Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp)) {
if (options != null) {
// receive
bytes = new byte [100];
do {
- EndPoint endpoint = client;
+ EndPoint endpoint = target;
SocketError error = 0;
int rc = s.ReceiveFrom (bytes, 0, 100, SocketFlags.None,
ref endpoint, out error);