This is available as OS\getsockname in the www repository.
OS\getsockname
Get the name of the local end of a socket
namespace HH\Lib\OS; function getsockname( FileDescriptor $fd, ): sockaddr;
See man 2 getsockname for details.
man 2 getsockname
FileDescriptor $fd
sockaddr