From 0f9892fe7a85833a89959a687ff4dc31da5125e7 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 30 Nov 2009 17:18:28 +0100 Subject: [PATCH] Fix printing refclocks and IPv6 sources in statistics log --- sources.c | 2 +- sourcestats.c | 8 +++++--- sourcestats.h | 2 +- util.c | 16 ---------------- util.h | 1 - 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/sources.c b/sources.c index 5abc5a2..d898b89 100644 --- a/sources.c +++ b/sources.c @@ -170,7 +170,7 @@ SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, IPAddr * } result = MallocNew(struct SRC_Instance_Record); - result->stats = SST_CreateInstance(ref_id); + result->stats = SST_CreateInstance(ref_id, addr); if (n_sources == max_n_sources) { /* Reallocate memory */ diff --git a/sourcestats.c b/sourcestats.c index 7260fde..c3ed1ea 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -66,8 +66,9 @@ static unsigned long logwrites = 0; struct SST_Stats_Record { - /* Reference ID of source, used for logging to statistics log */ + /* Reference ID and IP address of source, used for logging to statistics log */ unsigned long refid; + IPAddr *ip_addr; /* Number of samples currently stored. sample[n_samples-1] is the newest. The samples are expected to be sorted in order, but that @@ -187,11 +188,12 @@ SST_Finalise(void) /* This function creates a new instance of the statistics handler */ SST_Stats -SST_CreateInstance(unsigned long refid) +SST_CreateInstance(unsigned long refid, IPAddr *addr) { SST_Stats inst; inst = MallocNew(struct SST_Stats_Record); inst->refid = refid; + inst->ip_addr = addr; inst->n_samples = 0; inst->estimated_frequency = 0; inst->skew = 2000.0e-6; @@ -473,7 +475,7 @@ SST_DoNewRegression(SST_Stats inst) fprintf(logfile, "%s %-15s %10.3e %10.3e %10.3e %10.3e %10.3e %7.1e %3d %3d %3d\n", UTI_TimeToLogForm(inst->offset_time.tv_sec), - UTI_IPToDottedQuad(inst->refid), + inst->ip_addr ? UTI_IPToString(inst->ip_addr) : UTI_RefidToString(inst->refid), sqrt(inst->variance), inst->estimated_offset, inst->estimated_offset_sd, diff --git a/sourcestats.h b/sourcestats.h index fd19c0b..6baf5b6 100644 --- a/sourcestats.h +++ b/sourcestats.h @@ -42,7 +42,7 @@ extern void SST_Initialise(void); extern void SST_Finalise(void); /* This function creates a new instance of the statistics handler */ -extern SST_Stats SST_CreateInstance(unsigned long refid); +extern SST_Stats SST_CreateInstance(unsigned long refid, IPAddr *addr); /* This function deletes an instance of the statistics handler. */ extern void SST_DeleteInstance(SST_Stats inst); diff --git a/util.c b/util.c index 2acf7e7..199733b 100644 --- a/util.c +++ b/util.c @@ -257,22 +257,6 @@ UTI_RefidToString(unsigned long ref_id) /* ================================================== */ -char * -UTI_IPToDottedQuad(unsigned long ip) -{ - unsigned long a, b, c, d; - char *result; - a = (ip>>24) & 0xff; - b = (ip>>16) & 0xff; - c = (ip>> 8) & 0xff; - d = (ip>> 0) & 0xff; - result = NEXT_BUFFER; - snprintf(result, BUFFER_LENGTH, "%ld.%ld.%ld.%ld", a, b, c, d); - return result; -} - -/* ================================================== */ - char * UTI_IPToString(IPAddr *addr) { diff --git a/util.h b/util.h index 6427686..31e790c 100644 --- a/util.h +++ b/util.h @@ -78,7 +78,6 @@ extern char *UTI_TimestampToString(NTP_int64 *ts); extern char *UTI_RefidToString(unsigned long ref_id); /* Convert an IP address to string, for diagnostics */ -extern char *UTI_IPToDottedQuad(unsigned long ip); extern char *UTI_IPToString(IPAddr *ip); extern int UTI_StringToIP(const char *addr, IPAddr *ip);