drizzle_con_connect does not connect to the 0 port on localhost

Asked by Yuriy on 2013-03-07

Before connecting I made the port forwarding of the MySQL server (using ssh tunnel), from remote server to local machine .

When the local socket is ready and waits for connection, I try to connect on

127.0.0.1:0

but get error, that libdrizzle couldn't connetct.

If to use some else local socket 127.0.0.1:3307 - All works fine.

But I need to use the 0 port, to let the system decide - what port to provide for connection.

Question information

Language:
English Edit question
Status:
Solved
For:
Drizzle Client & Protocol Library Edit question
Assignee:
No assignee Edit question
Solved by:
Yuriy
Solved:
2013-03-11
Last query:
2013-03-11
Last reply:
2013-03-07
Wim Lewis (wiml) said : #1

I don't think it's possible to connect *to* port 0. If the server (or the ssh forwarder) has bound to port 0, then the system will assign the server socket a real port number, but the server needs to ask the system what port it was assigned and then tell the client (or the user) so that the client knows what port to connect to.

How did you specify the port forwarding when starting ssh? If you're doing something like "ssh -R 0:host:port ..." then ssh will print a line like "Allocated port 10556 for remote forward to host:port" to tell you that it was assigned port 10556.

Yuriy (velichko-yuriy) said : #2

I will try to explain how I do forwarding and why I use the '0' port.

1 To make port forwarding I use libssh2.
2 I use code from example:

3 In this code I should reserve the socket, on which will be forwarded the port.
Then the process is waiting until some app will connect to this port on local machine. And after - the port forwarding will will be performed.

I reserve the 127.0.0.1:0 socket for this purposes.
And trying to connect on this socket with libdrizzle.
Of course, after establishing connection, the system will reassign this port to any free in the system. And the libdrizzle will use it.

I want to use the :0 port to give the responsibility of the port assignment to the OS, instead to choose it up manually.

PS: I made this trick with postgresql (libpq) - and it connects to 0 port with no problem.

Yuriy (velichko-yuriy) said : #3

Sorry, I forgot the link to the example code (port forwarding with libssh2):

http://www.libssh2.org/examples/direct_tcpip.html

Yuriy (velichko-yuriy) said : #4

Thanks for help.
I fix problems in my code to connect to custom port.