https://bugzilla.novell.com/show_bug.cgi?id=643475

https://bugzilla.novell.com/show_bug.cgi?id=643475#c0


           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: [email protected]
        ReportedBy: [email protected]
         QAContact: [email protected]
                CC: [email protected]
          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++)
                {
                    try
                    {
                        Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true };
                        socket.Bind(new IPEndPoint(localIp, i));

                        _client = new UdpClient { Client = socket };
                        break;
                    }
                    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
/usr/src/packages/BUILD/mono-2.6.7/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:719
 
  at System.Net.Sockets.Socket.set_ExclusiveAddressUse (Boolean value)
[0x0003d] in
/usr/src/packages/BUILD/mono-2.6.7/mcs/class/System/System.Net.Sockets/Socket.cs:861
 
  at It.Unina.Dis.Logbus.Clients.UdpLogClientImpl.Start () [0x00072] in
/home/sviluppo/logbus-benchmark/It.Unina.Dis.Logbus/Clients/UdpLogClientImpl.cs:195
 

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

How often does this happen? 
Always

Additional Information:
Full source code
http://logbus-ng.svn.sourceforge.net/viewvc/logbus-ng/trunk/logbus-core/It.Unina.Dis.Logbus/Clients/UdpLogClientImpl.cs?view=log&pathrev=393

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.
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to