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

How to use the PF_LOCAL and AF_LOCAL Macros?

1501


HOW TCP/IP Handles Duplicated Packets?

1565


How to open socket file in linux?

942


How to Bind a Specific Interface Address?

1504


How to Test with No Server?

1425


How to Examin the /etc/services File?

1570


How TCP/IP Handles Lost Packets?

1579


What is socket connection?

796


What are Anonymous Calls?

1297


What are sockets used for?

760


How to Allocate IP Addresses?

1472


how to get client port number in server socket programming??

2311


How to Perform Endian Conversions?

1317


How to Form Traditional Local Addresses?

1318


How to Write a UDP Datagram Client?

1301