[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

RE: [Libevent-users] How do I get the client IP address?



Hi Christian,

	As a question/suggestion, why are you not using the evconnlistener
api, it would give you all the data you desire.  I.e. the callback is of the
form:

void _acceptor( struct evconnlistener* el, evutil_socket_t fd, struct
sockaddr* addr, int addrLen, void* context )

	This api subset makes most things exceptionally easy for server
work.  I guess if you started with an example, it probably did the accept
directly but there are other examples which show the listener api in use
also which could get you started.

KB

> -----Original Message-----
> From: owner-libevent-users@xxxxxxxxxxxxx [mailto:owner-libevent-
> users@xxxxxxxxxxxxx] On Behalf Of Christian Dahlqvist
> Sent: Friday, December 10, 2010 6:11 AM
> To: libevent-users@xxxxxxxxxxxxx
> Subject: Re: [Libevent-users] How do I get the client IP address?
> 
> I am unfortunately not doing HTTP, so that approach will not work for me.
> 
> I am building my code on a bufferevent sample for a custom protocol,
> and I guess I could try to get it based on the raw socket, but am
> reluctant to do so since it would possibly make it more difficult to
> port later on. The portability aspect is one of the reasons I started
> with libevent in the first place.
> 
> Christian
> 
> 
> 
> On Fri, Dec 10, 2010 at 11:30 AM, Dirk-Willem van Gulik
> <dirkx@xxxxxxxxxxxxxx> wrote:
> >
> > Op 10 dec 2010, om 11:51 heeft Christian Dahlqvist het volgende
> geschreven:
> >
> >> 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 are doing HTTP - check
> >
> >        evhttp_connection_get_peer (struct evhttp_connection *evcon, char
> **address, u_short *port)
> >
> > otherwise - if you use libevent raw - then you'll have direct access to
> the socket info. Or just post the code snippet.
> >
> >
> Dw.***********************************************************************
> > To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> > unsubscribe libevent-users    in the body.
> >
> ***********************************************************************
> To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> unsubscribe libevent-users    in the body.

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.