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 are the Advantages of TCP/IP?

1577


How to use the PF_LOCAL and AF_LOCAL Macros?

1541


How TCP/IP Handles Sequencing?

1507


What are sockets used for?

805


What is the use getservent(3)?

1519


Can you send and receive on the same socket at the same time?

808


What are Private IP Numbers?

1212


What is the use of SOCK_STREAM Socket Type?

1366


How to Close Sockets?

1451


What is the use of PF_INET and SOCK_DGRAM?

1396


What is the use of PF_LOCAL and SOCK_STREAM?

1569


How to test socket connection in linux?

964


How to Form Abstract Local Addresses?

1363


What is the use of endprotoent(3) Function

1685


What is socket abstraction?

829