1826562 Members
3767 Online
109695 Solutions
New Discussion

How to bind client ports

 
Sumanth N
Occasional Advisor

How to bind client ports

I have a client and a server processes which makes use of the TCP socket. I want to fix the client ports to a specifc port so that i can check when a new connection comes to the server , whether it is from the client port or not. thus validating the port.

Another small question,
inside the sockaddr_in sin_zero, is it possible to fill in some data(say a key) and send it through to the server during the connect() call.

is is possible that the data sent through connect using sin_zero is obtained at the other end of the server.
1 REPLY 1
Matti_Kurkela
Honored Contributor

Re: How to bind client ports

How to bind client ports:

What programming language are you using?
In C, just add a bind() system call with appropriate arguments before the connect() call. It is very rare for the client programs to do this, but it is certainly possible.

By the way, please learn why the rsh/rlogin/rexec protocols are considered obsolete and bad for security today: the client port number does not prove anything if the connection comes from any non-Unix host, or any untrusted host at all. Besides, several many-to-one NAT schemes (but not all of them) will cause the client port number to change and so they will break your "validation".



About sin_zero in struct sockaddr_in:

Looks like the sin_zero is just padding, or perhaps it reserves some space for OS internal things. I don't see anything that would suggest that the content of sin_zero would ever be sent anywhere.

Furthermore, even if it was sent somehow, the content of sin_zero would have to be transmitted somewhere outside the TCP/UDP packet's payload area. This would make it a non-standard extension to the protocol, and there is no guarantee that any firewall, NAT box or even a router would allow such an odd packet to go through.

MK