doh
doh

Reputation: 21

C programming - tcp socket remote port retrieving

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

Upvotes: 2

Views: 4060

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308101

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

Upvotes: 8

Related Questions