[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] How do I get the client IP address?
On Fri, Dec 10, 2010 at 5:51 AM, Christian Dahlqvist
<acdahlqvist@xxxxxxxxx> wrote:
> Hi,
>
> I am new to libevent, and am currently writing my first server using
> libevent 2.0.x. I have been trying to find an example of how to get
> the clients IP address when a new client connects, but have so far not
> found any support for it in the libevent API. Can somepone please help
> point me in the right direction?
If you're using the evconnlistener code to accept client connections,
you get that information passed to you in the callback when a client
connects.
If you're using accept(), then as other people have noted, you can
pass it a sockaddr_in (or sockaddr_storage, or whatever) to accept()
to find out the address.
If you just have an fd, you can call getpeername() on that fd to find
out the address on the other side.
hth,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.