From: Arran Cudbard-Bell Date: Thu, 12 May 2016 19:37:22 +0000 (-0400) Subject: Add radlog_hex function X-Git-Tag: branch_3_1_x~387 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0858f3fbc2bcc37be64e04110693ef924ae9b8e2;p=thirdparty%2Ffreeradius-server.git Add radlog_hex function --- diff --git a/src/include/log.h b/src/include/log.h index 7e2d646001c..393fa54be81 100644 --- a/src/include/log.h +++ b/src/include/log.h @@ -118,6 +118,9 @@ void radlog_request_hex(log_type_t type, log_lvl_t lvl, REQUEST *request, uint8_t const *data, size_t data_len) CC_HINT(nonnull); +void radlog_hex(log_type_t type, log_lvl_t lvl, uint8_t const *data, size_t data_len) + CC_HINT(nonnull); + /** Prefix for global log messages * * Should be defined in source file (before including radius.h) to add prefix to diff --git a/src/main/log.c b/src/main/log.c index 1e56f2215c5..81595a5c72d 100644 --- a/src/main/log.c +++ b/src/main/log.c @@ -960,3 +960,19 @@ void radlog_request_hex(log_type_t type, log_lvl_t lvl, REQUEST *request, for (p = buffer, j = i; j < data_len; j++, p += 3) sprintf(p, "%02x ", (uint8_t)data[j]); radlog_request(type, lvl, request, "%04x: %s", (int)i, buffer); } + +void radlog_hex(log_type_t type, log_lvl_t lvl, uint8_t const *data, size_t data_len) +{ + size_t i, j; + char buffer[(0x0f * 3) + 1]; + char *p; + + for (i = 0; (i + 0x0f) <= data_len; i += 0x0f) { + for (p = buffer, j = i; j < (i + 0x0f); j++, p += 3) sprintf(p, "%02x ", (uint8_t)data[j]); + radlog(type, lvl, "%04x: %s", (int)i, buffer); + } + if (i == data_len) return; + + for (p = buffer, j = i; j < data_len; j++, p += 3) sprintf(p, "%02x ", (uint8_t)data[j]); + radlog(type, lvl, "%04x: %s", (int)i, buffer); +}