Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the use of recvfrom(2) Function?

1579


How to perform I/O on Sockets?

1503


Can a socket have multiple connections?

868


How to Define a Socket?

1418


How to Examin the Generic Socket Address?

1450


How to Test the Datagram Client and Server?

1496


What is socket linux?

875


What are sockets in linux?

969


What is socket and how it works?

939


How to Understand Netmask Values?

1373


How to Examin the /etc/services File?

1703


How to Generate Addresses?

1370


How TCP/IP Handles Sequencing?

1562


How TCP/IP Handles Flow Control?

1637


What are Private IP Numbers?

1272