5.10. getpeername () --- who are you?
This function is too simple.
It's so simple that I don't even want to list a single chapter. But I did. The getpeername () function tells you who is on the other side of the connected streaming socket. The number of functions is as follows:
# Include <sys/socket. h>
Intgetpeername (int sockfd, struct sockaddr * addr, int * addrlen );
Sockfd is the descriptor of the connected stream socket. Addr is a pointer to the structure struct sockaddr (or structsockaddr_in), which stores information on the other side of the connection. Addrlen is an int pointer, Which is initialized to sizeof (struct sockaddr ).
When an error occurs, the function returns-1 and sets the corresponding errno.
Once you obtain their addresses, you can use inet_ntoa () or gethostbyaddr () to print or obtain more information. But you cannot get its account. (If it runs a silly daemon, this is possible, but it is beyond the scope of this article, please take a look at the RFC-1413 for more information .)
From the column xiaobin_HLJ80