| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (C) 2014 Named Data Networking Project |
| * See COPYING for copyright and distribution information. |
| */ |
| |
| #ifndef NFD_FACE_ETHERNET_FACE_HPP |
| #define NFD_FACE_ETHERNET_FACE_HPP |
| |
| #include "ethernet.hpp" |
| #include "face.hpp" |
| |
| #ifndef HAVE_PCAP |
| #error "Cannot include this file when pcap is not available" |
| #endif |
| |
| // forward declarations |
| struct pcap; |
| typedef pcap pcap_t; |
| |
| namespace nfd { |
| |
| class NetworkInterfaceInfo; |
| |
| /** |
| * \brief Implementation of Face abstraction that uses raw |
| * Ethernet frames as underlying transport mechanism |
| */ |
| class EthernetFace : public Face |
| { |
| public: |
| /** |
| * \brief EthernetFace-related error |
| */ |
| struct Error : public Face::Error |
| { |
| Error(const std::string& what) : Face::Error(what) {} |
| }; |
| |
| EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket, |
| const shared_ptr<NetworkInterfaceInfo>& interface, |
| const ethernet::Address& address); |
| |
| virtual |
| ~EthernetFace(); |
| |
| /// send an Interest |
| virtual void |
| sendInterest(const Interest& interest); |
| |
| /// send a Data |
| virtual void |
| sendData(const Data& data); |
| |
| /** |
| * \brief Close the face |
| * |
| * This terminates all communication on the face and cause |
| * onFail() method event to be invoked |
| */ |
| virtual void |
| close(); |
| |
| private: |
| void |
| pcapInit(); |
| |
| void |
| setPacketFilter(const char* filterString); |
| |
| void |
| sendPacket(const ndn::Block& block); |
| |
| void |
| handleRead(const boost::system::error_code& error, |
| size_t nBytesRead); |
| |
| void |
| processErrorCode(const boost::system::error_code& error); |
| |
| size_t |
| getInterfaceMtu() const; |
| |
| private: |
| shared_ptr<boost::asio::posix::stream_descriptor> m_socket; |
| std::string m_interfaceName; |
| ethernet::Address m_srcAddress; |
| ethernet::Address m_destAddress; |
| size_t m_interfaceMtu; |
| pcap_t* m_pcap; |
| }; |
| |
| } // namespace nfd |
| |
| #endif // NFD_FACE_ETHERNET_FACE_HPP |