face: don't set SO_BINDTODEVICE on Android
refs: #4761
Change-Id: Ife5c61fbc0d6e1af8148c32de5d89d8a3e7fbfee
diff --git a/daemon/face/multicast-udp-transport.cpp b/daemon/face/multicast-udp-transport.cpp
index a01063b..db12128 100644
--- a/daemon/face/multicast-udp-transport.cpp
+++ b/daemon/face/multicast-udp-transport.cpp
@@ -118,15 +118,17 @@
// receive all packets sent to the other interfaces as well.
// This is needed only on Linux. On macOS, the boost::asio::ip::multicast::join_group
// option is sufficient to obtain the desired behavior.
+ // We dont't set SO_BINDTODEVICE on Android because this operation requires root privilege
+ // which is not allowed on Android, it will cause "Operation not permitted" error.
-#ifdef __linux__
+#if defined(__linux__) && !defined(__ANDROID__)
PrivilegeHelper::runElevated([=] {
if (::setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname.data(), ifname.size() + 1) < 0) {
BOOST_THROW_EXCEPTION(MulticastUdpTransport::Error("Cannot bind multicast rx socket to " +
ifname + ": " + std::strerror(errno)));
}
});
-#endif // __linux__
+#endif
}
void