// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
+// Copyright 2015 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
[MonoTODO ("IPv6 support is missing")]
public class Ping : Component, IDisposable
{
+#if !MONOTOUCH
[StructLayout(LayoutKind.Sequential)]
struct cap_user_header_t
{
#endif
};
static readonly string PingBinPath;
+#endif
const int default_timeout = 4000; // 4 sec.
ushort identifier;
CancellationTokenSource cts;
public event PingCompletedEventHandler PingCompleted;
-
+
+#if !MONOTOUCH
static Ping ()
{
if (Environment.OSVersion.Platform == PlatformID.Unix) {
if (PingBinPath == null)
PingBinPath = "/bin/ping"; // default, fallback value
}
+#endif
public Ping ()
{
rng.GetBytes (randomIdentifier);
identifier = (ushort)(randomIdentifier [0] + (randomIdentifier [1] << 8));
}
-
+
+#if !MONOTOUCH
[DllImport ("libc", EntryPoint="capget")]
static extern int capget (ref cap_user_header_t header, ref cap_user_data_t data);
canSendPrivileged = false;
}
}
+#endif
void IDisposable.Dispose ()
{
throw new ArgumentException ("buffer");
// options can be null.
+#if MONOTOUCH
+ throw new InvalidOperationException ();
+#else
if (canSendPrivileged)
return SendPrivileged (address, timeout, buffer, options);
return SendUnprivileged (address, timeout, buffer, options);
+#endif
}
+#if !MONOTOUCH
private PingReply SendPrivileged (IPAddress address, int timeout, byte [] buffer, PingOptions options)
{
IPEndPoint target = new IPEndPoint (address, 0);
throw new NotSupportedException ("Ping is not supported on this platform.");
#endif // MONO_FEATURE_PROCESS_START
}
+#endif // !MONOTOUCH
// Async
worker.CancelAsync ();
}
+#if !MONOTOUCH
// ICMP message
class IcmpMessage
return args.ToString ();
}
+#endif // !MONOTOUCH
public Task<PingReply> SendPingAsync (IPAddress address, int timeout, byte [] buffer)
{