Get remote address/IP - C Berkeley Sockets

2019-06-28 05:50发布

问题:

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.

回答1:

getpeername



回答2:

See the getsockname() system call.