I am creating a TCP socket without worrying that the port number is bound to [socket.sin_port = 0]. How later, if I want to print the client port number, how do I do this? The C client application (on Linux) creates many clients that connect to the server. To debug problems, I capture traffic on the air. I was thinking of printing the port number in the logs while a problem occurs, so filtering on the air becomes easy.
Any help would be appreciated.
-Prabhu
Use the getsockname () call to get the socket address and port after a successful connection.
: . !
, getsockname(). , , (, connect()). (, bind()), getpeername() .
getsockname()
connect()
bind()
getpeername()
, , , netstat sockstat, . , Linux ( ), man sockstat. , , . grep, , Ethereal. !
man sockstat
grep
lsof -p <process id> | grep TCP