Answers

Question and Answer:

  Home  Linux Socket Programming

⟩ How to get client port number in server socket programming?

After accepting connection on socket of server side. we can

get the client ip address and port by to functions. These

functions are belonging in "/usr/include/arpa/inet.h" header

file.

Here is some scratch from the code.

socket2 = accept(socket1, (struct sockaddr *)&client, &addrlen);

printf("%sn",inet_ntoa(client.sin_addr));

printf("%dn",(int) ntohs(client.sin_port));

 184 views

More Questions for you: