util: add UTI_IPSockAddrToString()

This function prints an IPSockAddr. IPv6 addresses are printed in
brackets to separate the address from the port.
This commit is contained in:
Miroslav Lichvar
2019-07-18 08:12:33 +02:00
parent ca96946416
commit 3f8c57c8f2
2 changed files with 17 additions and 0 deletions

15
util.c
View File

@@ -604,6 +604,21 @@ UTI_SockaddrFamilyToString(int family)
/* ================================================== */
char *
UTI_IPSockAddrToString(IPSockAddr *sa)
{
char *result;
result = NEXT_BUFFER;
snprintf(result, BUFFER_LENGTH,
sa->ip_addr.family != IPADDR_INET6 ? "%s:%hu" : "[%s]:%hu",
UTI_IPToString(&sa->ip_addr), sa->port);
return result;
}
/* ================================================== */
char *
UTI_TimeToLogForm(time_t t)
{