The developer of the NetDiag+ network diagnostic tool implemented ping, traceroute, and Path MTU functionality on Android using Kotlin without root access or NDK. The solution leverages ping sockets available in Linux since version 3.0, which allow applications to open ICMP sockets via the net.ipv4.ping_group_range sysctl setting.
For ping functionality, the app uses Os.socket with AF_INET and IPPROTO_ICMP. The kernel handles identifier assignment and response filtering, which differs from the iOS implementation where manual filtering is required. The implementation requires API level 29 or higher to utilize setsockoptTimeval for timeout management.
Traceroute is implemented by sending echo requests with increasing TTL values and reading ICMP Time Exceeded errors via recvmsg with MSG_ERRQUEUE. Since some required constants like IP_RECVERR are missing from Android's OsConstants, raw Linux values are used. The app includes a fallback mechanism for devices where specific classes are missing.
Path MTU discovery is performed using a binary search method between 552 and 1500 bytes. By setting the IP_PMTUDISC_DO flag, the kernel adds the 'don't fragment' bit to packets, causing sendto to return EMSGSIZE if the packet exceeds the path's MTU. This allows the tool to determine the maximum packet size without fragmentation.






