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 Define a Socket?

1377


How to Generate Addresses?

1324


How to Write a UDP Datagram Client?

1392


What is the use of inet_addr() Function?

1435


What is socket file in linux?

953


What is the difference between socket & port?

899


How to Manipulate IP Numbers?

1336


What are Nameless Sockets?

1550


What is socket connection?

851


What is the use of SOCK_STREAM Socket Type?

1382


What are the different types of sockets?

905


What is the use of PF_INET and SOCK_DGRAM?

1404


What are the best linux system programming interview questions you've ever asked or been asked?

795


What is the use of PF_LOCAL and SOCK_STREAM?

1574


How to Understand Network Byte Order?

1362