<div dir="ltr">Hello,<div><br></div><div>Considering that we do not even have a test, I think it would be nice to turn one of the samples on the git discussion into the test.   While not 100% robust, we could check that at least *one* of the interfaces has a gateway, and perhaps make this into a soft failure for those that do not actually have a network with a gateway when running the tests.</div><div><br></div><div>Miguel</div><div><br></div><div>







<p class=""><span class="">using System;</span></p>
<p class=""><span class="">using System.Net;</span></p>
<p class=""><span class="">using System.Net.NetworkInformation;</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">public class Test</span></p>
<p class=""><span class="">{</span></p>
<p class=""><span class="">    public static void Main()</span></p>
<p class=""><span class="">    {</span></p>
<p class=""><span class="">        DisplayGatewayAddresses();</span></p>
<p class=""><span class="">    }</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">    public static void DisplayGatewayAddresses()</span></p>
<p class=""><span class="">    {</span></p>
<p class=""><span class="">        Console.WriteLine("Gateways");</span></p>
<p class=""><span class="">        NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();</span></p>
<p class=""><span class="">        foreach (NetworkInterface adapter in adapters)</span></p>
<p class=""><span class="">        {</span></p>
<p class=""><span class="">            IPInterfaceProperties adapterProperties = adapter.GetIPProperties();</span></p>
<p class=""><span class="">            GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;</span></p>
<p class=""><span class="">            Console.WriteLine(adapter.Description);</span></p>
<p class=""><span class="">            if (addresses.Count >0)</span></p>
<p class=""><span class="">            {</span></p>
<p class=""><span class="">                foreach (GatewayIPAddressInformation address in addresses)</span></p>
<p class=""><span class="">                {</span></p>
<p class=""><span class="">                    Console.WriteLine("  Gateway Address ......................... : {0}", </span></p>
<p class=""><span class="">                        address.Address.ToString());</span></p>
<p class=""><span class="">                }</span></p>
<p class=""><span class="">                Console.WriteLine();</span></p>
<p class=""><span class="">            }</span></p>
<p class=""><span class="">        }</span></p>
<p class=""><span class="">    }</span></p>
<p class=""><span class="">}</span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 15, 2015 at 8:58 AM, Ben Woods <span dir="ltr"><<a href="mailto:woodsb02@gmail.com" target="_blank">woodsb02@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Mono is not able to get the system gateway address on Mac OSX or BSD when performing GetIPProperties on an a NetworkInterface. This is due to the mono class libraries solely utilising the /proc/net/route file, which is only available on Linux.<div><br></div><div>I have submitted a pull request to fix this here:<br><a href="https://github.com/mono/mono/pull/1404" target="_blank">https://github.com/mono/mono/pull/1404</a><br><br>The last comment on the pull request is that the code looks good, but it would be nice to have a test added to the regression test suite. As I understand it, the test code would reside in mcs/class/System/Test/System.Net.NetworkInformation.</div><div><br></div><div>What do you think the test would look like? Seeing as mono does not support setting the routing table, only reading it, it is difficult to assert that the default gateway would be.</div><div><br></div><div>Perhaps simply that the code executes without error, regardless of the result, even if it is empty (it is possible for a system to not have a default route, after all).</div><div><br></div><div>Thoughts?<br><br>--<br>From: Benjamin Woods<br><a href="mailto:woodsb02@gmail.com" target="_blank">woodsb02@gmail.com</a>
</div></div>
<br>_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a><br>
<br></blockquote></div><br></div>