Winsock2: Using connect() to connect to server, but from tcp port < 1024?

80 Views Asked by At

Does Winsock2 have an API to define which TCP port a client uses to connect() to a server?

We need to connect() to a UNIX server, which only responds if the client TCP port is < 1024 (Reserved ports, which are accessible only to UNIX user "root", are in the range 1 to 1023. Non-reserved are in the range 1024 to 65535, read Port Usage).

If we use the plain Winsock2 API, we get a random TCP port number, and if it is above 1023, the server will not respond.

1

There are 1 best solutions below

4
Remy Lebeau On

Simply bind() the client socket to the desired local IP/port before connect()'ing it to the server.