I've got a
You can cast the pointer to
struct sockaddr_in * or
struct sockaddr_in6 * and access the members directly, but that's going to open a can of worms about aliasing violations and miscompilation issues.
A better approach would be to pass the pointer to
getnameinfo with the
NI_NUMERICSERV flags to get a string representation of the address and port. This has the advantage that it supports both IPv4 and IPv6 with no additional code, and in theory supports all future address types too. You might have to cast the pointer to
void * (or
struct sockaddr * explicitly, if you're using C++) to pass it to
getnameinfo, but this should not cause problems.