First of all, you should use the ntohs function instead of ntohl. ntohs () returns a 16-bit port number and ntohl returns a 32-bit IP address
Now you can get client details using getpeername ()
Syntax:
#include <sys/socket.h> struct sockaddr_in client_address; int getpeername(int sockfd, struct sockaddr *client, socklen_t *addrlen);
You can find more information using the man command.
source share