blob: 81a24c4fe08568047fa41de9fb1c6e5c4fbe934d [file] [log] [blame]
Paul Stewart960d4692013-12-09 07:41:59 -08001// 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 Chancd477322014-10-17 14:19:30 -07008#include <memory>
9
10#include <base/macros.h>
Paul Stewart960d4692013-12-09 07:41:59 -080011
12namespace shill {
13
14class IPAddress;
15class ScopedSocketCloser;
16class Sockets;
17
18// The Icmp class encapsulates the task of sending ICMP frames.
19class Icmp {
20 public:
Alex Vakulenko016fa0e2014-08-11 15:59:58 -070021 Icmp();
Paul Stewart960d4692013-12-09 07:41:59 -080022 virtual ~Icmp();
23
Alex Vakulenko016fa0e2014-08-11 15:59:58 -070024 // Create a socket for transmission of ICMP frames.
Paul Stewart960d4692013-12-09 07:41:59 -080025 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 Chancd477322014-10-17 14:19:30 -070039 std::unique_ptr<Sockets> sockets_;
40 std::unique_ptr<ScopedSocketCloser> socket_closer_;
Paul Stewart960d4692013-12-09 07:41:59 -080041 int socket_;
42
43 DISALLOW_COPY_AND_ASSIGN(Icmp);
44};
45
46} // namespace shill
47
48#endif // SHILL_ICMP_H_