(05-10-2018, 07:16 PM)BartKindt Wrote: I was hoping I could bypass the Android system and use Indy's way of selecting the interface.
That would be nice. But Android is a managed platform, Google doesn't really want users going down to the Linux level unless they really need to. But, since Delphi Android apps operate inside the Java native NDK, Indy operates at the Linux POSIX level, not at the Android Java level.
(05-10-2018, 07:16 PM)BartKindt Wrote: I will try the Android-based ideas you gave me and see what I can and cannot do with that.
See Connecting your App to a Wi-Fi Device on the Android Developers Blog.
However, despite what is documented, I see from Android's source code that:
- Network.bindSocket() ultimately calls the undocumented NetworkUtils.bindSocketToNetwork() method, which is implemented in native code, not in Java code.
- bindSocketToNetwork() calls setNetworkForSocket()
- setNetworkForSocket() calls FwmarkClient().send() with a SELECT_NETWORK command.
- FWMARK is an external AF_UNIX socket server running locally on the Android device. When it receives a SELECT_NETWORK command, it calls setsockopt(SOL_SOCKET, SO_MARK) on the original Java Socket descriptor, specifying the network ID number that belongs to the Java Network class. That ID number is passed by Network.bindSocket() to NetworkUtils.bindSocketToNetwork() (it might be the same ID number returned by WifiConfiguration.networkId when connected to a WiFi network, I'm not sure).
And according to Linux's documentation:
Quote:SO_MARK (since Linux 2.6.25)
Set the mark for each packet sent through this socket (similar
to the netfilter MARK target but socket-based). Changing the
mark can be used for mark-based routing without netfilter or
for packet filtering. Setting this option requires the
CAP_NET_ADMIN capability.
So again, you might need root/sudo access to bind a socket to a specific network. Unless Android's INTERNET or NET_ADMIN permissions enable CAP_NET_ADMIN, but I don't think they do. So, I'm still at a loss of how to proceed here. You could try what the blog says, or you could try using SO_MARK directly, and hope it somehow works out OK in your app without messing around with permissions too much.
(05-10-2018, 07:16 PM)BartKindt Wrote: The biggest problem is that I cannot find anywhere a forum where I can actually ask Delphi-Android based questions, and get actually a real answer.
In the absence of the Embarcadero forums, you can ask Delphi-related questions in the Delphi section of this same forum server, or in the Delphi section of StackOverflow, or any number of other Delphi forums scattered online (though I only frequent the ones I have mentioned).