Paul Stewart | 960d469 | 2013-12-09 07:41:59 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_ICMP_H_ |
| 6 | #define SHILL_ICMP_H_ |
| 7 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
| 10 | #include <base/macros.h> |
Paul Stewart | 960d469 | 2013-12-09 07:41:59 -0800 | [diff] [blame] | 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | class IPAddress; |
| 15 | class ScopedSocketCloser; |
| 16 | class Sockets; |
| 17 | |
| 18 | // The Icmp class encapsulates the task of sending ICMP frames. |
| 19 | class Icmp { |
| 20 | public: |
Alex Vakulenko | 016fa0e | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 21 | Icmp(); |
Paul Stewart | 960d469 | 2013-12-09 07:41:59 -0800 | [diff] [blame] | 22 | virtual ~Icmp(); |
| 23 | |
Alex Vakulenko | 016fa0e | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 24 | // Create a socket for transmission of ICMP frames. |
Paul Stewart | 960d469 | 2013-12-09 07:41:59 -0800 | [diff] [blame] | 25 | virtual bool Start(); |
| 26 | |
| 27 | // Destroy the transmit socket. |
| 28 | virtual void Stop(); |
| 29 | |
| 30 | // Returns whether an ICMP socket is open. |
| 31 | virtual bool IsStarted() const; |
| 32 | |
| 33 | // Send an ICMP Echo Request (Ping) packet to |destination|. |
| 34 | virtual bool TransmitEchoRequest(const IPAddress &destinaton); |
| 35 | |
| 36 | private: |
| 37 | friend class IcmpTest; |
| 38 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 39 | std::unique_ptr<Sockets> sockets_; |
| 40 | std::unique_ptr<ScopedSocketCloser> socket_closer_; |
Paul Stewart | 960d469 | 2013-12-09 07:41:59 -0800 | [diff] [blame] | 41 | int socket_; |
| 42 | |
| 43 | DISALLOW_COPY_AND_ASSIGN(Icmp); |
| 44 | }; |
| 45 | |
| 46 | } // namespace shill |
| 47 | |
| 48 | #endif // SHILL_ICMP_H_ |