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??

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / supraja aldena

After accepting connection.Just type this, u wil get
client ip address and port number.
printf("\n(%s , %d)\n",inet_ntoa(client.sin_addr),ntohs
(client.sin_port));

Is This Answer Correct ?    8 Yes 0 No

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

Answer / raguraman sify tech

Please elaborate this question.. what is your exact request?..

Is This Answer Correct ?    9 Yes 3 No

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

Answer / ramana

getpeername()

Is This Answer Correct ?    6 Yes 6 No

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

Answer / rps

@Maddy :-)

After the Accept Call in server Program..

ClientFD = accept(SockFD,(struct sockaddr *)&ClientAddr,(int*)&SinSize);

You will get Client IP and Port Number using this --

printf(" Server got a connection from Client (%s : %d)\n",
inet_ntoa(ClientAddr.sin_addr),ntohs(ClientAddr.sin_port));

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More Linux Socket Programming Interview Questions

What is the use of SOCK_STREAM Socket Type?

0 Answers  


How to Form Abstract Local Addresses?

0 Answers  


How to Examin the Generic Socket Address?

0 Answers  


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

0 Answers  


What is the use of endservent(3) Function?

0 Answers  


How to use the PF_LOCAL and AF_LOCAL Macros?

0 Answers  


What is the Use of the inet_netof() Function?

0 Answers  


How to Close Sockets?

0 Answers  


Can a socket have multiple connections?

0 Answers  


What is the use getservent(3)?

0 Answers  


How does socket communication work?

0 Answers  


How to Generate Addresses?

0 Answers  


Categories