33 #include <sys/ioctl.h> 35 #if defined(__linux__) 36 #include <netpacket/packet.h> 37 #include <sys/socket.h> 41 #if defined(__APPLE__) || defined(__FreeBSD__) 42 #include <net/if_dl.h> 52 const ethernet::Address& mcastAddress,
53 ndn::nfd::LinkType linkType)
55 #if defined(__linux__)
56 , m_interfaceIndex(localEndpoint.getIndex())
61 this->
setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
64 this->
setMtu(localEndpoint.getMtu());
73 snprintf(filter,
sizeof(filter),
74 "(ether proto 0x%x) && (ether dst %s) && (not ether src %s) && (not vlan)",
75 ethernet::ETHERTYPE_NDN,
86 MulticastEthernetTransport::joinMulticastGroup()
88 #if defined(__linux__) 90 mr.mr_ifindex = m_interfaceIndex;
91 mr.mr_type = PACKET_MR_MULTICAST;
95 if (::setsockopt(
m_socket.native_handle(), SOL_PACKET,
96 PACKET_ADD_MEMBERSHIP, &mr,
sizeof(mr)) == 0)
99 NFD_LOG_FACE_WARN(
"setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
102 #if defined(SIOCADDMULTI) 104 std::strncpy(ifr.ifr_name,
m_interfaceName.data(),
sizeof(ifr.ifr_name) - 1);
106 #if defined(__APPLE__) || defined(__FreeBSD__) 108 using boost::asio::ip::udp;
110 int fd = sock.native_handle();
123 sockaddr_dl* sdl =
reinterpret_cast<sockaddr_dl*
>(&ifr.ifr_addr);
124 sdl->sdl_len =
sizeof(ifr.ifr_addr);
125 sdl->sdl_family = AF_LINK;
129 static_assert(
sizeof(ifr.ifr_addr) >= offsetof(sockaddr_dl, sdl_data) + ethernet::ADDR_LEN,
130 "ifr_addr in struct ifreq is too small on this platform");
134 ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
137 static_assert(
sizeof(ifr.ifr_hwaddr.sa_data) >= ethernet::ADDR_LEN,
138 "ifr_hwaddr in struct ifreq is too small on this platform");
141 if (::ioctl(fd, SIOCADDMULTI, &ifr) == 0)
147 NDN_THROW(
Error(
"Failed to join multicast group"));
ethernet::Address m_srcAddress
void setLocalUri(const FaceUri &uri)
ethernet::Address m_destAddress
void setScope(ndn::nfd::FaceScope scope)
boost::asio::posix::stream_descriptor m_socket
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
void setPacketFilter(const char *filter) const
Install a BPF filter on the receiving socket.
std::string m_interfaceName
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
Base class for Ethernet-based Transports.
MulticastEthernetTransport(const ndn::net::NetworkInterface &localEndpoint, const ethernet::Address &mcastAddress, ndn::nfd::LinkType linkType)
Creates an Ethernet-based transport for multicast communication.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void setLinkType(ndn::nfd::LinkType linkType)
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
#define NFD_LOG_INIT(name)
void setRemoteUri(const FaceUri &uri)
boost::asio::io_service & getGlobalIoService()
Returns the global io_service instance for the calling thread.