LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   find ip address in c programming of server in client server (http://www.linuxquestions.org/questions/programming-9/find-ip-address-in-c-programming-of-server-in-client-server-4175426797/)

batman4 09-12-2012 12:35 AM

find ip address in c programming of server in client server
 
please help
i have to print ip address from sockaddr of server thru c programming :

Celyr 09-12-2012 03:36 AM

Code:

man inet_ntoa

dwhitney67 09-12-2012 04:59 AM

Quote:

Originally Posted by Celyr (Post 4778253)
Code:

man inet_ntoa

That function has been deprecated; one should use inet_ntop() to get support for IPv6 addresses as well.

NevemTeve 09-12-2012 05:02 AM

And before inet_ntoa: getpeername.

dwhitney67 09-12-2012 05:10 AM

Quote:

Originally Posted by NevemTeve (Post 4778304)
And before inet_ntoa: getpeername.

getpeername() is useful if all one has is the socket descriptor. However, if one has a "pre-filled" sockaddr structure that is returned by accept() (when using TCP) or by recvfrom() (when using UDP) then it should be sufficient to go straight to using inet_ntop().

Celyr 09-12-2012 05:21 AM

Quote:

Originally Posted by dwhitney67 (Post 4778301)
That function has been deprecated; one should use inet_ntop() to get support for IPv6 addresses as well.

Oh, nice to know, sorry for the mistake


All times are GMT -5. The time now is 06:55 PM.