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> 55 #if defined(__linux__)
56 , m_interfaceIndex(localEndpoint.getIndex())
73 snprintf(filter,
sizeof(filter),
74 "(ether proto 0x%x) && (ether dst %s) && (not ether src %s) && (not vlan)",
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;
138 "ifr_hwaddr in struct ifreq is too small on this platform");
141 if (::ioctl(fd, SIOCADDMULTI, &ifr) == 0)
147 BOOST_THROW_EXCEPTION(Error(
"Failed to join multicast group"));
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
void setRemoteUri(const FaceUri &uri)
const size_t ADDR_LEN
Octets in one Ethernet address.
bool isBroadcast() const
True if this is a broadcast address (ff:ff:ff:ff:ff:ff)
detail::SimulatorIo & getGlobalIoService()
void setLinkType(ndn::nfd::LinkType linkType)
std::string toString(char sep=':') const
Converts the address to a human-readable string.
void setPacketFilter(const char *filter) const
Install a BPF filter on the receiving socket.
void setScope(ndn::nfd::FaceScope scope)
Represents one network interface attached to the host.
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Copyright (c) 2011-2015 Regents of the University of California.
MulticastEthernetTransport(const ndn::net::NetworkInterface &localEndpoint, const ethernet::Address &mcastAddress, ndn::nfd::LinkType linkType)
Creates an Ethernet-based transport for multicast communication.
boost::asio::posix::stream_descriptor m_socket
ethernet::Address m_destAddress
void setLocalUri(const FaceUri &uri)
const uint16_t ETHERTYPE_NDN
represents the underlying protocol and address used by a Face
uint32_t getMtu() const
Returns the MTU (maximum transmission unit) of the interface.
bool isMulticast() const
True if this is a multicast address.
represents an Ethernet hardware address
Base class for Ethernet-based Transports.
#define NFD_LOG_INIT(name)
std::string m_interfaceName
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
ethernet::Address m_srcAddress
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.