ethernet-transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
28 
29 #include "core/common.hpp"
30 #include "transport.hpp"
32 
33 #ifndef HAVE_LIBPCAP
34 #error "Cannot include this file when libpcap is not available"
35 #endif
36 
37 // forward declarations
38 struct pcap;
39 typedef pcap pcap_t;
40 struct pcap_pkthdr;
41 
42 namespace nfd {
43 namespace face {
44 
48 class EthernetTransport final : public Transport
49 {
50 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58  }
59  };
60 
64  EthernetTransport(const NetworkInterfaceInfo& interface,
65  const ethernet::Address& mcastAddress);
66 
67 protected:
68  void
69  doClose() final;
70 
71 private:
72  void
73  doSend(Transport::Packet&& packet) final;
74 
78  void
79  pcapInit();
80 
86  void
87  setPacketFilter(const char* filterString);
88 
94  bool
95  joinMulticastGroup();
96 
100  void
101  sendPacket(const ndn::Block& block);
102 
106  void
107  handleRead(const boost::system::error_code& error, size_t nBytesRead);
108 
116  void
117  processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet);
118 
119 private:
123  void
124  processErrorCode(const boost::system::error_code& error);
125 
129  size_t
130  getInterfaceMtu();
131 
132 private:
133  unique_ptr<pcap_t, void(*)(pcap_t*)> m_pcap;
134  boost::asio::posix::stream_descriptor m_socket;
135 
136  ethernet::Address m_srcAddress;
137  ethernet::Address m_destAddress;
138  std::string m_interfaceName;
139 #if defined(__linux__)
140  int m_interfaceIndex;
141 #endif
142 
143 #ifdef _DEBUG
144  unsigned int m_nDropped;
146 #endif
147 };
148 
149 } // namespace face
150 } // namespace nfd
151 
152 #endif // NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: nfd.hpp:35
contains information about a network interface
EthernetTransport(const NetworkInterfaceInfo &interface, const ethernet::Address &mcastAddress)
Creates an Ethernet-based transport for multicast communication.
STL namespace.
the lower part of a Face
Definition: transport.hpp:104
void doClose() final
performs Transport specific operations to close the transport
A multicast Transport that uses raw Ethernet II frames.
pcap pcap_t
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40