Paul Stewart | 91a5aac | 2012-07-20 11:55:40 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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_ARP_PACKET_H_ |
| 6 | #define SHILL_ARP_PACKET_H_ |
| 7 | |
| 8 | #include "shill/byte_string.h" |
| 9 | #include "shill/ip_address.h" |
| 10 | |
| 11 | namespace shill { |
| 12 | |
| 13 | // ArpPacket encapsulates the task of creating and parsing |
| 14 | // Address Resolution Protocol (ARP) packets for IP and |
| 15 | // IPv6 protocols on Ethernet (or Ethernet-like) networks. |
| 16 | class ArpPacket { |
| 17 | public: |
| 18 | ArpPacket(); |
| 19 | ArpPacket(const IPAddress &local_ip, const IPAddress &remote_ip, |
| 20 | const ByteString &local_mac, const ByteString &remote_mac); |
| 21 | virtual ~ArpPacket(); |
| 22 | |
| 23 | // Parse a payload and save to local parameters. |
| 24 | bool ParseReply(const ByteString &packet); |
| 25 | |
| 26 | // Output a payload from local parameters. |
| 27 | bool FormatRequest(ByteString *packet) const; |
| 28 | |
| 29 | // Getters and seters. |
| 30 | const IPAddress &local_ip_address() const { return local_ip_address_; } |
| 31 | void set_local_ip_address(const IPAddress &address) { |
| 32 | local_ip_address_ = address; |
| 33 | } |
| 34 | |
| 35 | const IPAddress &remote_ip_address() const { return remote_ip_address_; } |
| 36 | void set_remote_ip_address(const IPAddress &address) { |
| 37 | remote_ip_address_ = address; |
| 38 | } |
| 39 | |
| 40 | const ByteString &local_mac_address() const { return local_mac_address_; } |
| 41 | void set_local_mac_address(const ByteString &address) { |
| 42 | local_mac_address_ = address; |
| 43 | } |
| 44 | |
| 45 | const ByteString &remote_mac_address() const { return remote_mac_address_; } |
| 46 | void set_remote_mac_address(const ByteString &address) { |
| 47 | remote_mac_address_ = address; |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | friend class ArpPacketTest; |
| 52 | |
Paul Stewart | ac1328e | 2012-07-20 11:55:40 -0700 | [diff] [blame] | 53 | // The minimum number of bytes of ARP payload which will produce the |
| 54 | // smallest valid Ethernet frame. |
| 55 | static const size_t kMinPayloadSize; |
| 56 | |
Paul Stewart | 91a5aac | 2012-07-20 11:55:40 -0700 | [diff] [blame] | 57 | IPAddress local_ip_address_; |
| 58 | IPAddress remote_ip_address_; |
| 59 | ByteString local_mac_address_; |
| 60 | ByteString remote_mac_address_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(ArpPacket); |
| 63 | }; |
| 64 | |
| 65 | } // namespace shill |
| 66 | |
| 67 | #endif // SHILL_ARP_PACKET_H_ |