How to distinguish interface names of Hotspot and WiFi?


I have been working on a 1v1 Android game. In one of the game modes, one phone acts as the server and turns on it's Hotspot, whereas the other phone (the client) connects to the Hotspot of the server via WiFi.

The problem I'm having is that, I don't know the interface name (like wlan0, wlan2, ap0 etc) of the Hotspot and the WiFi (for sure). I can query the names and addresses of all interfaces in my C/C++ code, but that doesn't solve the problem of distinguishing WiFi from Hotspot. Is there anything in the android NDK that could help?

I looked into this matter, but most posts I find either tell that the IP addresses of such interfaces are 192.168.43.x which is absolutely wrong! The interface names also don't follow any proper standards like the one which systemd has. Apart from this, most of the things like netlink sockets and information regarding networking is locked down pretty hard in modern versions on Android (I think 11+?)

From my research so far, Many Android devices usually name the WiFi interface as wlan0 and Hotspot gets some other names like wlan1, wlan2, ap0 etc. Im not a 100% sure if there are any edge cases to this. There could even be potential swapping in the interface names of you're unlucky enough...

0
Apr 1 at 8:45 AM
User AvatarRadon
#android#c#android-ndk#android-networking

Accepted Answer

don’t rely on interface names at all, they’re not stable or guaranteed on Android.

Solution: use Android’s network APIs to detect the transport type instead of guessing (wlan0, ap0, etc.).

From native (NDK), call into Java/Kotlin and use ConnectivityManager:

ConnectivityManager cm =
    (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

Network active = cm.getActiveNetwork();
NetworkCapabilities caps = cm.getNetworkCapabilities(active);

if (caps != null) {
    if (caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
        // This is WiFi (client mode)
    }
}

For hotspot (tethering), there is no reliable public NDK/SDK way to identify it via interface name. Instead:

  • Check if tethering is active via WifiManager / ConnectivityManager (Java side)

  • Or infer via routing/IP (e.g., device acting as gateway)

Key point:
Interface names like wlan0, wlan1, ap0 are device/vendor-dependent and can change, so they are not safe to use.

User Avatarhmu535
Apr 1 at 10:06 AM
1