Boost logo

Boost Users :

Subject: Re: [Boost-users] Get IP address of a client
From: Casimiro, Daniel C CIV NUWC NWPT (daniel.casimiro_at_[hidden])
Date: 2010-05-19 09:54:05


 

> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> Rouven Walter
> Sent: Wednesday, May 19, 2010 8:26
> To: boost-users_at_[hidden]
> Subject: [Boost-users] Get IP address of a client
>
>
> Hello,
>
> I use the asio boost library for network traffic. Is there a
> way to get the IP address of a client directly if the server
> receives data over a socket object, so that the IP address
> has not to be sent within the data.
> Normally this should be possible, since TCP pakets holds the
> ip address of receiver and sender in the header information.
> But how can I get these header information with the asio library?

There is an overload of the async_accept member function that provides this information:

template<
    typename SocketService,
    typename AcceptHandler>
void async_accept(
    basic_socket< protocol_type, SocketService > & peer,
    endpoint_type & peer_endpoint,
    AcceptHandler handler);

More information:
http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/reference/basic_socket_acceptor/async_accept/overload2.html

There is an equivalent in the synchronous API.

~Dan




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net