diff --git a/Tethering/src/android/net/ip/NeighborPacketForwarder.java b/Tethering/src/android/net/ip/NeighborPacketForwarder.java index 723bd63543..8384562762 100644 --- a/Tethering/src/android/net/ip/NeighborPacketForwarder.java +++ b/Tethering/src/android/net/ip/NeighborPacketForwarder.java @@ -23,6 +23,7 @@ import static android.system.OsConstants.IPPROTO_RAW; import static android.system.OsConstants.SOCK_DGRAM; import static android.system.OsConstants.SOCK_NONBLOCK; import static android.system.OsConstants.SOCK_RAW; +import static android.system.OsConstants.ENODEV; import android.net.util.SocketUtils; import android.os.Handler; @@ -131,7 +132,13 @@ public class NeighborPacketForwarder extends PacketReader { ETH_P_IPV6, mListenIfaceParams.index); Os.bind(mFd, bindAddress); } catch (ErrnoException | SocketException e) { - Log.wtf(mTag, "Failed to create socket", e); + // An ENODEV(No such device) will rise if tethering stopped before this function, this + // may happen when enable/disable tethering quickly. + if (e instanceof ErrnoException && ((ErrnoException) e).errno == ENODEV) { + Log.w(mTag, "Failed to create socket because tethered interface is gone", e); + } else { + Log.wtf(mTag, "Failed to create socket", e); + } closeSocketQuietly(mFd); return null; }