17#include <netinet/in.h>
18#include <sys/socket.h>
32 explicit ICMPSocket(
const ICMPSocket&);
33 ICMPSocket& operator=(
const ICMPSocket&);
45 explicit ICMPSocket(boost::asio::ip::icmp::socket& socket);
62#if BOOST_VERSION < 106600
63 return (socket_.native());
65 return (socket_.native_handle());
73 return (IPPROTO_ICMP);
144 size_t& cumulative,
size_t& offset,
160 static uint16_t
calcChecksum(
const uint8_t* buf,
const uint32_t buf_size);
171 std::unique_ptr<boost::asio::ip::icmp::socket> socket_ptr_;
174 boost::asio::ip::icmp::socket& socket_;
183ICMPSocket<C>::ICMPSocket(boost::asio::ip::icmp::socket& socket) :
184 socket_ptr_(), socket_(socket), isopen_(true) {
191 io_service_(io_service),
192 socket_ptr_(new boost::asio::ip::icmp::socket(io_service_->getInternalIOService())),
193 socket_(*socket_ptr_), isopen_(false) {
204template <
typename C>
void
214 socket_.open(boost::asio::ip::icmp::v4());
216 socket_.open(boost::asio::ip::icmp::v6());
221 boost::asio::ip::icmp::socket::send_buffer_size snd_size;
222 socket_.get_option(snd_size);
225 socket_.set_option(snd_size);
228 boost::asio::ip::icmp::socket::receive_buffer_size rcv_size;
229 socket_.get_option(rcv_size);
232 socket_.set_option(rcv_size);
235 boost::asio::socket_base::do_not_route option(
false);
236 socket_.set_option(option);
243template <
typename C>
void
258 socket_.async_send_to(boost::asio::buffer(
data, length),
262 "attempt to send on a ICMP socket that is not open");
269template <
typename C>
void
279 if (offset >= length) {
281 "ICMP receive buffer");
283 void* buffer_start =
static_cast<void*
>(
static_cast<uint8_t*
>(
data) + offset);
286 socket_.async_receive_from(boost::asio::buffer(buffer_start, length - offset),
290 "attempt to receive from a ICMP socket that is not open");
297template <
typename C>
bool
299 size_t& cumulative,
size_t& offset,
308 outbuff->writeData(staging, length);
316template <
typename C>
void
326template <
typename C>
void
328 if (isopen_ && socket_ptr_) {
334template <
typename C> uint16_t
338 for (i = 0; i < (buf_size & ~1U); i += 2) {
339 uint16_t chunk = buf[i] << 8 | buf[i + 1];
I/O Socket with asynchronous operations.
The IOEndpoint class is an abstract base class to represent a communication endpoint.
virtual short getFamily() const =0
Returns the address family of the endpoint.
virtual short getProtocol() const =0
Returns the protocol number of the endpoint (TCP, UDP...).
The ICMPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a ICM...
const boost::asio::ip::icmp::endpoint & getASIOEndpoint() const
Fetches the underlying ASIO endpoint implementation.
virtual void close()
Close socket.
virtual void cancel()
Cancel I/O On Socket.
ICMPSocket(const asiolink::IOServicePtr &service)
Constructor.
virtual void open(const asiolink::IOEndpoint *endpoint, C &callback)
Open Socket.
virtual bool processReceivedData(const void *staging, size_t length, size_t &cumulative, size_t &offset, size_t &expected, isc::util::OutputBufferPtr &outbuff)
Process received data.
virtual int getProtocol() const
Return protocol of socket.
static uint16_t calcChecksum(const uint8_t *buf, const uint32_t buf_size)
Calculates the checksum for the given buffer of data.
virtual void asyncReceive(void *data, size_t length, size_t offset, asiolink::IOEndpoint *endpoint, C &callback)
Receive Asynchronously.
virtual bool isOpenSynchronous() const
Is "open()" synchronous?
ICMPSocket(boost::asio::ip::icmp::socket &socket)
Constructor from an ASIO ICMP socket.
virtual ~ICMPSocket()
Destructor.
virtual bool isOpen() const
Indicates if the socket is currently open.
virtual void asyncSend(const void *data, size_t length, const asiolink::IOEndpoint *endpoint, C &callback)
Send Asynchronously.
virtual int getNative() const
Return file descriptor of underlying socket.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Defines the logger used by the top-level component of kea-lfc.