11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Net ;
45using System . Net . Sockets ;
56using System . Text ;
67
78namespace RabbitMQ . Client
89{
10+ static class IPAddressExt
11+ {
12+ // TODO: This method should already exist on IPAddress
13+ // but for some reason this does to compile against mono 4.4.1
14+ public static IPAddress MapToIPv6 ( this IPAddress addr )
15+ {
16+ var bytes = addr . GetAddressBytes ( ) ;
17+ var bytes6 = new byte [ ]
18+ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0xFF , 0xFF ,
19+ bytes [ 0 ] , bytes [ 1 ] , bytes [ 2 ] , bytes [ 3 ] } ;
920
21+ return new IPAddress ( bytes6 ) ;
22+ }
23+ }
1024
1125 /// <summary>
12- /// Simple wrapper around TcpClient.
26+ /// Simple wrapper around TcpClient.
1327 /// </summary>
1428 public class TcpClientAdapter : ITcpClient
1529 {
@@ -24,8 +38,13 @@ public TcpClientAdapter(TcpClient tcpClient)
2438 public virtual IAsyncResult BeginConnect ( string host , int port , AsyncCallback requestCallback , object state )
2539 {
2640 assertTcpClient ( ) ;
27-
28- return _tcpClient . BeginConnect ( host , port , requestCallback , state ) ;
41+ var endpoints = Dns . GetHostAddresses ( host ) ;
42+ if ( _tcpClient . Client . AddressFamily == AddressFamily . InterNetworkV6 )
43+ {
44+ endpoints = endpoints . Select ( a => a . MapToIPv6 ( ) ) . ToArray ( ) ;
45+ }
46+
47+ return _tcpClient . BeginConnect ( endpoints , port , requestCallback , state ) ;
2948 }
3049
3150 private void assertTcpClient ( )
0 commit comments