I have a server with a incoming socket from a client.
I need the get the IP address of the remote client.
Tried searching google for in_addr
but it's a bit troublesome.
Any suggestions?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Since you say it is an incoming connection from a client, as an alternative to
getpeername
you can just save the address that was returned by theaccept()
call, in the second and third parameters.You need the
getpeername
function:Assuming you're using
accept()
to accept incoming socket connections,getpeername()
isn't needed. The address information is available via the 2nd and 3rd parameters of theaccept()
call.Here is Eli's answer modified to do it without
getpeername()
: