2
votes

I have a tcp connected socket handle, created through an accept. Only the handle, not other structs. How can I retrieve its REMOTE port from the handle? I mean, the tcp source port of the connection Remote Client ---> Me

1
Yes, the other structs. 2nd argument, sockaddr_in.sin_port. - Hans Passant

1 Answers

8
votes

The getpeername function gets information about the remote side, including the port number; getsockname does the same for the local side of the connection.