how to get client port number in server socket programming??
Answer Posted / nainesh
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("%s\n",inet_ntoa(client.sin_addr));
printf("%d\n",(int) ntohs(client.sin_port));
| Is This Answer Correct ? | 14 Yes | 3 No |
Post New Answer View All Answers
How to Define a Socket?
How to Generate Addresses?
How to Write a UDP Datagram Client?
What is the use of inet_addr() Function?
What is socket file in linux?
What is the difference between socket & port?
How to Manipulate IP Numbers?
What are Nameless Sockets?
What is socket connection?
What is the use of SOCK_STREAM Socket Type?
What are the different types of sockets?
What is the use of PF_INET and SOCK_DGRAM?
What are the best linux system programming interview questions you've ever asked or been asked?
What is the use of PF_LOCAL and SOCK_STREAM?
How to Understand Network Byte Order?