diff options
author | Paul Stewart <pstew@chromium.org> | 2012-07-20 11:55:40 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-30 08:49:00 -0700 |
commit | ac1328e5143f6ee0054d5cb2f7d17754c16a3814 (patch) | |
tree | cd1d1dfa0aa932b2cc1e1d79013a43ecc9c52b4f /arp_client.h | |
parent | d001205b0afec0841d72d142f2790de347e52a6c (diff) | |
download | shill-ac1328e5143f6ee0054d5cb2f7d17754c16a3814.tar.gz |
shill: LinkMonitor: Add ArpClient code
Add ArpClient class and start hooking it up to LinkMonitor.
BUG=chromium-os:32600
TEST=Unit tests. Some real-world testing using the test harness
to transmit and receive ARP on a real network.
Change-Id: Ic05d8d7eb921878e3776f35b4be285554ef86456
Reviewed-on: https://gerrit.chromium.org/gerrit/28148
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Diffstat (limited to 'arp_client.h')
-rw-r--r-- | arp_client.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/arp_client.h b/arp_client.h new file mode 100644 index 00000000..0ae6b7c2 --- /dev/null +++ b/arp_client.h @@ -0,0 +1,66 @@ +// Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_ARP_CLIENT_H_ +#define SHILL_ARP_CLIENT_H_ + +#include <base/basictypes.h> +#include <base/memory/scoped_ptr.h> + +namespace shill { + +class ArpPacket; +class ByteString; +class Sockets; +class ScopedSocketCloser; + +// ArpClient task of creating ARP-capable sockets, as well as +// transmitting requests on and receiving responses from such +// sockets. +class ArpClient { + public: + explicit ArpClient(int interface_index); + virtual ~ArpClient(); + + // Create a socket for tranmission and reception. Returns true + // if successful, false otherwise. + virtual bool Start(); + + // Destroy the client socket. + virtual void Stop(); + + // Receive an ARP reply and parse its contents into |packet|. Also + // return the sender's MAC address (which may be different from the + // MAC address in the ARP response) in |sender|. Returns true on + // succes, false otherwise. + virtual bool ReceiveReply(ArpPacket *packet, ByteString *sender) const; + + // Send a formatted ARP request from |packet|. Returns true on + // success, false otherwise. + virtual bool TransmitRequest(const ArpPacket &packet) const; + + virtual int socket() const { return socket_; } + + private: + friend class ArpClientTest; + + // Offset of the ARP OpCode within a captured ARP packet. + static const size_t kArpOpOffset; + + // The largest packet we expect to receive as an ARP client. + static const size_t kMaxArpPacketLength; + + bool CreateSocket(); + + const int interface_index_; + scoped_ptr<Sockets> sockets_; + scoped_ptr<ScopedSocketCloser> socket_closer_; + int socket_; + + DISALLOW_COPY_AND_ASSIGN(ArpClient); +}; + +} // namespace shill + +#endif // SHILL_ARP_CLIENT_H_ |