Connected to IPv6 rather than IPv4

Jan 28, 2013 at 10:26 PM

I was using ForwardedPortRemote to connect to a VNC server behind a NAT, and connecting via

var port1 = new ForwardedPortRemote(remotePort, "", localPort);

connected to the IPv6 address rather than I changed OpenSocket in ChannelForwardedTcpip.NET40.cs to:

 partial void OpenSocket(string connectedHost, uint connectedPort)
            IPEndPoint ep;
            string sPattern = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
            if (System.Text.RegularExpressions.Regex.IsMatch(connectedHost, sPattern)) {
                ep = new IPEndPoint(IPAddress.Parse(connectedHost), (int)connectedPort);
            } else {
                ep = new IPEndPoint(Dns.GetHostEntry(connectedHost).AddressList[0], (int)connectedPort);
            this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);

and got it to work. Could this be changed in the source, or is there a better way to do this?

Jan 29, 2013 at 1:40 AM



Thanks for suggestion.

Never thought about that it would be ever matter, but I am not a network person so I dont really know.

I would look into how to add this kind of support in the future or at least an ability to do it but I would prefer to use something more generic since this method only will use if IP matches pattern but then if its not but someone wants to use IP4 or IP6 then will have to make some changes again.

What I am thinking about is may be to add some flag which could say what IP protocol to use and have one to be by default.

Another idea is add ability instead of connectedHost to let user provide IPAddress object which already can be defined as either IPv4 or IPv6.

Also, from short test that I did, if I provide IP to be parsed in IPv4 format it will produce IPv4 object otherwise IPv6.

Here is example I tried:

 var ipv6 = IPAddress.Parse("::ffff:");
 var ipv4 = IPAddress.Parse("");

Not sure if that could be helpful, but I will try to implement option where yo ucan provide IPAddress instead of string address soon as an alternative.




Jan 31, 2013 at 3:49 AM

I just committed code where I added a new constructor and now you can provide to IPAddress object directly to the port forwarded.
So prior to calling constructor you can create IPAddress object as IPv4 or IPv6 and that object will be used internally to connect.

Hope it helps resolve the issue of IPv6 and IPv4 in port forwarding.

I guess in the future I will extend this ability to use IPAddress instead of string everywhere in application where it makes sense.

Feb 28, 2013 at 1:16 PM
I had a similar issue. Please add IPAddress to the method signature.
Mar 2, 2013 at 2:50 PM
I have it on my list but will take a little time since I dont have much free time recently and to change that I want to maintain backward compatibility with string address as well.

I will try to address this as soon as possible3.