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:
parent
ca96946416
commit
3f8c57c8f2
2 changed files with 17 additions and 0 deletions
15
util.c
15
util.c
|
@ -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)
|
||||
{
|
||||
|
|
2
util.h
2
util.h
|
@ -115,6 +115,8 @@ extern int UTI_IPAndPortToSockaddr(IPAddr *ip, unsigned short port, struct socka
|
|||
extern char *UTI_SockaddrToString(struct sockaddr *sa);
|
||||
extern const char *UTI_SockaddrFamilyToString(int family);
|
||||
|
||||
extern char *UTI_IPSockAddrToString(IPSockAddr *sa);
|
||||
|
||||
extern char *UTI_TimeToLogForm(time_t t);
|
||||
|
||||
/* Adjust time following a frequency/offset change */
|
||||
|
|
Loading…
Reference in a new issue