1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Net ;
4
5
using System . Net . Sockets ;
5
6
using System . Text ;
6
7
7
8
namespace RabbitMQ . Client
8
9
{
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 ] } ;
9
20
21
+ return new IPAddress ( bytes6 ) ;
22
+ }
23
+ }
10
24
11
25
/// <summary>
12
- /// Simple wrapper around TcpClient.
26
+ /// Simple wrapper around TcpClient.
13
27
/// </summary>
14
28
public class TcpClientAdapter : ITcpClient
15
29
{
@@ -24,8 +38,13 @@ public TcpClientAdapter(TcpClient tcpClient)
24
38
public virtual IAsyncResult BeginConnect ( string host , int port , AsyncCallback requestCallback , object state )
25
39
{
26
40
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 ) ;
29
48
}
30
49
31
50
private void assertTcpClient ( )
0 commit comments