[Mono-list] UdpClient broadcast bug?

Chris Bacon chris.bacon@docobo.co.uk
Wed, 23 Feb 2005 11:56:42 -0000


This is a multi-part message in MIME format.


------=_NextPart_000_0715_01C5199E.BD9BAAF0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi,

On MS.NET it appears that when the UdpClient class is used the socket it
creates has broadcasting enabled. On Mono it is disabled. I have attached a
(totally trivial) patch to UdpClient.cs that resolves this.

Here is a test case that demonstrates the problem (works on MS, fails on
Mono):

[Test]
public void UdpClientBroadcastTest() {
    bool exThrown = false;
    UdpClient client = new UdpClient(new
IPEndPoint(IPAddress.Loopback,1234));
    byte[] bytes = new byte[] {10,11,12,13};
    try {
        client.Send(bytes,bytes.Length,new
IPEndPoint(IPAddress.Broadcast,1235));
    } catch (SocketException) {
        exThrown = true;
    }
    Assert.IsFalse(exThrown,"UdpClient Broadcast #1");
}

Chris

------=_NextPart_000_0715_01C5199E.BD9BAAF0
Content-Type: application/octet-stream;
	name="UdpClientBroadcast.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="UdpClientBroadcast.diff"

Index: UdpClient.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- UdpClient.cs	(revision 41083)=0A=
+++ UdpClient.cs	(working copy)=0A=
@@ -119,7 +119,9 @@=0A=
 			socket =3D new Socket (family, SocketType.Dgram, ProtocolType.Udp);
=20
 			if (localEP !=3D null)
-				socket.Bind (localEP);
+				socket.Bind (localEP);=0A=
+				=0A=
+				=0D			socket.SetSocketOption(SocketOptionLevel.Socket, =
SocketOptionName.Broadcast, true);
 		}
=20
 #endregion // Constructors

------=_NextPart_000_0715_01C5199E.BD9BAAF0--