Linux (and related, I think Android as well) support the SO_COOKIE getsockopt flag (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5daab9db7b65df87da26fd8cfa695fb9546a1ddb) - this returns a kernel-managed cookie for a given socket, which is guaranteed to be unique per socket.
If there's no objection to add this to socket2 as a get option, it should be simple enough to do.