4

If I have a socket file descriptor connected (either by connect or by bind), type SOCK_STREAM, is it possible to get the remote address / IP address?

I need to do this within a function where I don't have any other data than the socket file descriptor.

matsjoyce
  • 5,744
  • 6
  • 31
  • 38
NeDark
  • 1,212
  • 7
  • 23
  • 36

2 Answers2

7

getpeername

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
0

See the getpeername() system call.

user207421
  • 305,947
  • 44
  • 307
  • 483