You can acquire that information using getpeername...
# general
a
You can acquire that information using getpeername() and getsockname(), but that would be racy