[Mono-bugs] [Bug 643475] New: Socket.ExclusiveAddressUse not working with UDP

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Oct 4 07:02:06 EDT 2010



           Summary: Socket.ExclusiveAddressUse not working with UDP
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: i586
        OS/Version: openSUSE 11.3
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: djechelon at fastwebnet.it
         QAContact: mono-bugs at lists.ximian.com
                CC: vittorioalfieri at gmail.com
          Found By: Community User
           Blocker: Yes

Description of Problem:
I need to open a UDP socket listener in a known range of ports. This eases
firewall configuration for servers.
In order to achieve this, I need to set the ExclusiveAddressUse either on
UdpClient or on its underlying Client member (of type Socket) before binding.

The following code fragment works well on Windows (.NET 3.5), even without
Admin privileges (MSDN states that in certain Windows version you need to be
admin to set that flag), but doesn't work in Mono, root or not

for (int i = START_PORT; i <= END_PORT; i++)
                        Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true };
                        socket.Bind(new IPEndPoint(localIp, i));

                        _client = new UdpClient { Client = socket };
                    catch (SocketException)
                    { }

The code works as follows: it tries to open a socket on the first port, but if
another process (or another class within the process) opened the same port, it
will throw a SocketException and try with the next. The code obviously fails if
all ports are taken by other processes (I allocated 5000 ports).

Steps to reproduce the problem:
1. Instantiate a new socket and set ExclusiveAddressUse to true
2. Try to bind it to a free local port

Actual Results:
System.Net.Sockets.SocketException: Protocol option not supported
  at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel,
SocketOptionName optionName, Int32 optionValue) [0x00046] in
  at System.Net.Sockets.Socket.set_ExclusiveAddressUse (Boolean value)
[0x0003d] in
  at It.Unina.Dis.Logbus.Clients.UdpLogClientImpl.Start () [0x00072] in

Expected Results:
Client should bind to the first available port in the assigned range

How often does this happen? 

Additional Information:
Full source code

line 191 and following

Workaround coming in the next comment

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list