Cling和cybergarage报错java.io.IOException: sendto failed: EPERM (Operation not permitted)

Android 11以上的版本对网络有限制,必须要支持multicast的NetworkInterface才可以进行网络相关操作,所以需要在获取HostAddresses的地方进行判断NetworkInterface:

Enumeration nis = NetworkInterface.getNetworkInterfaces();
while (nis.hasMoreElements()) {
    NetworkInterface ni = (NetworkInterface) nis.nextElement();

    if( !ni.supportsMulticast() ) { // added due to Android security requirements
        Log.w("TAG", "NetworkInterface " + ni + " not supportsMulticast");
        continue;
    } // end of fix

    Enumeration addrs = ni.getInetAddresses();
    while (addrs.hasMoreElements()) {
        InetAddress addr = (InetAddress) addrs.nextElement();
        if (!isUsableAddress(addr))
            continue;
        nHostAddrs++;
    }
}

你可能感兴趣的:(Cling和cybergarage报错java.io.IOException: sendto failed: EPERM (Operation not permitted))