Bug 40957 - Cannot listen to IPAddress.Any and IPAddress.IPV6Any
Summary: Cannot listen to IPAddress.Any and IPAddress.IPV6Any
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-09 00:56 UTC by Alan McGovern
Modified: 2016-07-31 16:32 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 40957 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Alan McGovern 2016-05-09 00:56:42 UTC
Testcase Create an IPV4 socket bound to IPAddress.Any and IPV6 socket bound to IPAddress.IPV6Any and have them both listen to port 5555. Sample code illustrating the issue: https://gist.github.com/alanmcgovern/8bbf6eb4a8e73539e350f40194bc381b

Expected result: Both sockets function and listen for incoming connections.

Actual result: Everything works fine on Mac, but on Linux i get an error saying the port is in use. The error I get on my raspberry pi is

[09/05/2016 00:50:55] error: Unhandled exception in BeginListeningAsync. InterNetwork
System.Net.Sockets.SocketException: Address already in use
  at System.Net.Sockets.Socket.Listen (Int32 backlog) <0x7363e3d0 + 0x00084> in <filename unknown>:0 
  at Tunez.RequestHandler+<BeginListeningAsync>c__async1.MoveNext () [0x0006e] in /Users/alan/tunez/Server/TunezServer/RequestHandler.cs:43 

Using Mono 4.4.0 (Stable 4.4.0.148/fcf7a6d Thu Apr 28 15:07:33 UTC 2016)
Comment 1 Alan McGovern 2016-05-09 01:06:08 UTC
I just realised that applying this patch makes it work on linux as expected. I'm not sure which behaviour is the correct one, but i presume it's related to dualmode sockets  and the default on Mac is different to Linux.

diff --git a/Server/TunezServer/RequestHandler.cs b/Server/TunezServer/RequestHandler.cs
index 22c5729..d57ea7f 100644
--- a/Server/TunezServer/RequestHandler.cs
+++ b/Server/TunezServer/RequestHandler.cs
@@ -24,6 +24,7 @@ namespace Tunez
                {
                        var tcpListener = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        var tcp6Listener = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+                       tcp6Listener.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, true);
 
                        using (tcpListener)
                        using (tcp6Listener) {