diff --git a/CHANGES b/CHANGES index a8eda336d6..e6103e5fe0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ + 174. [func] New public function isc_sockaddr_format(), for + formatting socket addresses in log messages. + 173. [func] Keep a queue of zones waiting for zone transfer quota so that a new transfer can be dispatched immediately whenever quota becomes available. diff --git a/lib/isc/include/isc/sockaddr.h b/lib/isc/include/isc/sockaddr.h index 4c8dae6575..0b9dcef081 100644 --- a/lib/isc/include/isc/sockaddr.h +++ b/lib/isc/include/isc/sockaddr.h @@ -111,6 +111,14 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); * ISC_R_NOSPACE The text or the null termination did not fit. */ +void +isc_sockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size); +/* + * Format a human-readable representation of the socket address '*sa' + * into the character array 'array', which is of size 'size'. + * The resulting string is guaranteed to be null-terminated. + */ + ISC_LANG_ENDDECLS #endif /* ISC_SOCKADDR_H */ diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 54b5bda148..e2e1a12b12 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -155,6 +155,21 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { return (ISC_R_SUCCESS); } +void +isc_sockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size) { + isc_result_t result; + isc_buffer_t buf; + + isc_buffer_init(&buf, array, size); + result = isc_sockaddr_totext(sa, &buf); + if (result != ISC_R_SUCCESS) { + snprintf(array, size, + "", + sa->type.sa.sa_family); + array[size - 1] = '\0'; + } +} + unsigned int isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only) { unsigned int length;