[Mono-dev] Ping throwing exception

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Tue Sep 29 02:07:27 EDT 2009

On Mon, 2009-09-28 at 12:22 -0400, Gladish, Jacob wrote:
> I'm getting an exception from an application that is repeatedly running pings. The Ping class looks like it'll switch between invoking /bin/ping and sending an ICMP directly depending on the user. I'm running as a non-privileged user, therefore, its exec'ing ping. Every once in a while I get an "unknown" response, and have tracked it back to Ping.cs -- the code snippet below. The only way I can see this failing is if WaitForSingleObjectEx is broken for processes. The timeout being used is 4000, which is the default.

> Does anyone know if there are any outstanding issues with WaitForSingleObjectEx and processes.
> System.InvalidOperationException: The process must exit before getting the requested information.
>   at System.Diagnostics.Process.get_ExitCode () [0x00000]
>   at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ExitCode ()
>   at MassPinger.Ping.SendUnprivileged (System.Net.IPAddress address, Int32 timeout, System.Byte[] buffer, MassPinger.PingOptions options) [0x00000]
> Ping.cs:273
> if (!ping.WaitForExit (timeout) || ping.ExitCode == 2) {
>                return new PingReply (address, buffer, options, trip_time, System.Net.NetworkInformation.IPStatus.TimedOut);
>             }

That code was wrong. I have just fixed this in svn in the mono-2-4,
mono-2-6 branches and trunk.

If you are a regular user and are going to do a lot of pings, I'd
recommend setting the 'cap_net_raw' capability for the mono exeutable.
You might want to set it for a copy of 'mono' that only your user can

	sudo setcap cap_net_raw=+ep /opt/mono/bin/mono

That will use ICMP packets instead of shelling out and running 'ping'.


More information about the Mono-devel-list mailing list