[Mono-dev] UdpClient & IPv6

Stephen Kou skou at cs.ucla.edu
Mon Jan 16 10:06:08 UTC 2012


Looks like there's a problem when trying to use IPv6 with UdpClient:

		public byte [] Receive (ref IPEndPoint remoteEP)
		{
			CheckDisposed ();

			byte [] recBuffer = new byte [65536]; // Max. size
			EndPoint endPoint = new IPEndPoint (IPAddress.Any,
0);
			int dataRead = socket.ReceiveFrom (recBuffer, ref
endPoint);
			if (dataRead < recBuffer.Length)
				recBuffer = CutArray (recBuffer, dataRead);

			remoteEP = (IPEndPoint) endPoint;
			return recBuffer;
		}


The call to ReceiveFrom will throw an address exception if the socket was
created with IPv6, since it's using a IPv4 0.0.0.0 address in the
ReceiveFrom call.   Should instead do what's done in the rest of the file:

If(family == AddressFamily.InterNetworkV6)
  endpoint = new IPEndpoint(IPAddress.IPv6Any, 0);
else
  endpoint = new IPEndPoint(IPAddress.Any, 0);

--stephen



More information about the Mono-devel-list mailing list