EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Multi-Port Forwarding

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#23642
Posted: 02/22/2013 10:52:37
by Carlton  (Basic support level)
Joined: 02/21/2013
Posts: 45

"
do I need to remove a tunnel if I want to change to parameters of the tunnel

like the forwarded port, dest Host & port. "

Code
  string[] surl = url.Split(':');
           if (channelNum <= 1)
           {
               tunnelIdx = ForWarding.AddTunnel();
              // ForWarding.get_Tunnels(tunnelIdx).AutoOpen = true;
               ForWarding.get_Tunnels(tunnelIdx).DestHost = surl[1].Remove(0, 2);
               ForWarding.get_Tunnels(tunnelIdx).DestPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(tunnelIdx).ForwardedHost = "127.0.0.1";
               ForWarding.get_Tunnels(tunnelIdx).ForwardedPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(tunnelIdx).Open();
               if (channelNum != 1) channelNum++;
               else
               {
                   ForWarding.get_Tunnels(TunnelIdx3).Close();
                   CusForwarding.RemoveTunnel(TunnelIdx3);
               }
           }
           if (channelNum == 2)
           {
               TunnelIdx2 = ForWarding.AddTunnel();
               //ForWarding.get_Tunnels(TunnelIdx2).AutoOpen = true;
               ForWarding.get_Tunnels(TunnelIdx2).DestHost = surl[1].Remove(0, 2);
               ForWarding.get_Tunnels(TunnelIdx2).DestPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(TunnelIdx2).ForwardedHost = "127.0.0.1";
               ForWarding.get_Tunnels(TunnelIdx2).ForwardedPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(TunnelIdx2).Open();
               ForWarding.get_Tunnels(tunnelIdx).Close();
               CusForwarding.RemoveTunnel(tunnelIdx);
           }
           if (channelNum == 3)
           {
               TunnelIdx3 = ForWarding.AddTunnel();
               //ForWarding.get_Tunnels(TunnelIdx3).AutoOpen = true;
               ForWarding.get_Tunnels(TunnelIdx3).DestHost = surl[1].Remove(0, 2);
               ForWarding.get_Tunnels(TunnelIdx3).DestPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(TunnelIdx3).ForwardedHost = "127.0.0.1";
               ForWarding.get_Tunnels(TunnelIdx3).ForwardedPort = Convert.ToInt32(surl[2]);
               ForWarding.get_Tunnels(TunnelIdx3).Open();
               ForWarding.get_Tunnels(TunnelIdx2).Close();
               CusForwarding.RemoveTunnel(TunnelIdx2);
           }
           channelNum++;
           if (channelNum > 3) channelNum = 1;
#23643
Posted: 02/22/2013 11:00:08
by Ken Ivanov (EldoS Corp.)

Quote
In your demo: I try it last again after click start. I add a second button.
to run the additional tunnels
I have set them to AutoOpen and it did not work.

Please read my replies attentively. AutoOpen won't work if the tunnel is created *after* the SSH connection is established. If you need to add a tunnel to existing SSH connection, you must call the tunnel's Open() method.

Quote
do I need to remove a tunnel if I want to change to parameters of the tunnel

Yes, you have to remove the existing tunnel and create a new one.
#23644
Posted: 02/22/2013 11:00:16
by Carlton  (Basic support level)
Joined: 02/21/2013
Posts: 45

what causes this error;

Exception:Thrown: "An invalid IP address was specified." (System.FormatException)
A System.FormatException was thrown: "An invalid IP address was specified."
#23645
Posted: 02/22/2013 11:09:16
by Ken Ivanov (EldoS Corp.)

It is caused by the misuse of the components. Please do not attempt to set AutoOpen if creating tunnels while the session is active. Configure the properties of the tunnel and then call Open() instead.
#23646
Posted: 02/22/2013 11:26:18
by Eugene Mayevski (EldoS Corp.)

Quote
Carlton wrote:
what causes this error;

Exception:Thrown: "An invalid IP address was specified." (System.FormatException) A System.FormatException was thrown: "An invalid IP address was specified."


This can be an internally handled exception. If you only see it in IDE, then it's handled in the socket class. The address passed is first checked for being an IP address, then resolved as a symbolic name.

On a side note, please use CODE tag or CODE button above the edit box to mark your code blocks for better readability. I've modified one of your previous messages by hand.


Sincerely yours
Eugene Mayevski
#23647
Posted: 02/22/2013 12:00:20
by Carlton  (Basic support level)
Joined: 02/21/2013
Posts: 45

In my application we are not using auto open.
#23648
Posted: 02/22/2013 12:09:38
by Ken Ivanov (EldoS Corp.)

OK, please double check that you pass correct IP addresses to the ForwardedHost and DestHost properties. The following assignment looks particularly suspicious to me:

Code
ForWarding.get_Tunnels(tunnelIdx).DestHost = surl[1].Remove(0, 2);


Please re-check that you have the correct value assigned to DestHost here.
#23649
Posted: 02/22/2013 12:20:37
by Carlton  (Basic support level)
Joined: 02/21/2013
Posts: 45

yes I have
#23650
Posted: 02/22/2013 12:22:32
by Carlton  (Basic support level)
Joined: 02/21/2013
Posts: 45

This is all automatic.

How can I after creating the initial Forwarding verify the connect is succeful
before exiting the routine.
#23651
Posted: 02/22/2013 12:45:31
by Ken Ivanov (EldoS Corp.)

I assume you are talking about the TElSSHLocalPortForwarding.Open() call, aren't you?

Simple forwarding classes are asynchronous, so Open() method returns immediately. If you wish to wait for the connection to be established before exiting the outer routine, you should use some synchronization mechanism (e.g. manual reset events). TElSSHLocalPortForwarding invokes the OnOpen event upon establishing the connection, so it is a good idea to set the event inside the corresponding handler.
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 13833 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!