[Mono-dev] UdpClient & IPv6

lextm support at lextm.com
Mon Feb 13 08:52:22 UTC 2012


This issue also happens on Microsoft .NET. So I consider it a by-design
thing. As a result, you must use two Socket objects, one for IP v4, and the
other IP v6.

http://www.lextm.com/2009/04/crossroad-billboard-how-to-support-ip.html
https://github.com/lextm/sharpsnmplib/blob/51390e125ec3e1028486cbbd68aa3a9854c6c761/Browser/NotificationPanel.cs


Stephen Kou-2 wrote
> 
> 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
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at .ximian
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 


--
View this message in context: http://mono.1490590.n4.nabble.com/UdpClient-IPv6-tp4299027p4383178.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list