From e56f7f1d9efd62230c3e56a0f86127f913ffe3d3 Mon Sep 17 00:00:00 2001 From: Peter Haag Date: Mon, 24 Jun 2024 20:21:15 +0200 Subject: [PATCH] Fix compiler warnings on some Linux systems --- src/libnffile/nffile.c | 3 ++- src/nfdump/nflowcache.c | 13 +++++++++++-- src/nfdump/nfstat.c | 7 +++++-- src/output/output_csv.c | 2 +- src/output/output_fmt.c | 3 ++- src/output/output_json.c | 3 ++- src/output/output_raw.c | 3 ++- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/libnffile/nffile.c b/src/libnffile/nffile.c index 9fb024a3..515375a4 100644 --- a/src/libnffile/nffile.c +++ b/src/libnffile/nffile.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -1672,7 +1673,7 @@ int QueryFile(char *filename, int verbose) { } printf("File : %s\n", filename); - printf("Size : %lld\n", stat_buf.st_size); + printf("Size : %" PRIi64 "\n", (int64_t)stat_buf.st_size); if (fileHeader.version == LAYOUT_VERSION_1) { if (lseek(fd, 0, SEEK_SET) < 0) { LogError("lseek() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno)); diff --git a/src/nfdump/nflowcache.c b/src/nfdump/nflowcache.c index 87857b26..933b7179 100755 --- a/src/nfdump/nflowcache.c +++ b/src/nfdump/nflowcache.c @@ -1099,6 +1099,12 @@ char *ParseAggregateMask(char *arg) { return NULL; } + int modeCSV = 0; + char *sep = " "; + if (modeCSV) { + sep = ","; + } + uint32_t elementCount = 0; aggregateInfo[0] = -1; @@ -1124,7 +1130,10 @@ char *ParseAggregateMask(char *arg) { return 0; } aggr_fmt[0] = '\0'; - fmt_len -= snprintf(aggr_fmt, fmt_len, "fmt:%s ", AggrPrependFmt); + if (modeCSV) + fmt_len -= snprintf(aggr_fmt, fmt_len, "csv:%s ", AggrPrependFmt); + else + fmt_len -= snprintf(aggr_fmt, fmt_len, "fmt:%s ", AggrPrependFmt); uint32_t v4Mask = 0xffffffff; uint64_t v6Mask[2] = {0xffffffffffffffffLL, 0xffffffffffffffffLL}; @@ -1195,7 +1204,7 @@ char *ParseAggregateMask(char *arg) { if (aggregationTable[index].fmt != NULL) { strncat(aggr_fmt, aggregationTable[index].fmt, fmt_len); fmt_len -= strlen(aggregationTable[index].fmt); - strncat(aggr_fmt, " ", fmt_len); + strncat(aggr_fmt, sep, fmt_len); fmt_len -= 1; } diff --git a/src/nfdump/nfstat.c b/src/nfdump/nfstat.c index d8b34cc3..24470e4b 100644 --- a/src/nfdump/nfstat.c +++ b/src/nfdump/nfstat.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -1232,13 +1233,15 @@ static void PrintJsonStatLine(char *statName, stat_record_t *stat, outputParams_ if (outputParams->hasGeoDB && type == IS_IPADDR) { printf( "{ \"first\" : \"%s.%03u\", \"last\" : \"%s.%03u\", \"proto\" : %u, \"%s\" : \"%s\", \"geo\" : \"%s\"," - "\"flows\" : %llu, \"packets\" : %llu, \"bytes\" : %llu, \"pps\" : %llu, \"bps\" : %llu, \"bpp\" : %u}\n", + "\"flows\" : %" PRIu64 ", \"packets\" : %" PRIu64 ", \"bytes\" : %" PRIu64 ", \"pps\" : %" PRIu64 ", \"bps\" : %" PRIu64 + ", \"bpp\" : %u}\n", datestrFirst, (unsigned)(statRecord->msecFirst % 1000), datestrLast, (unsigned)(statRecord->msecLast % 1000), hashKey->proto, statName, valstr, geo, count_flows, count_packets, count_bytes, pps, bps, bpp); } else { printf( "{ \"first\" : \"%s.%03u\", \"last\" : \"%s.%03u\", \"proto\" : %u, \"%s\" : \"%s\", " - "\"flows\" : %llu, \"packets\" : %llu, \"bytes\" : %llu, \"pps\" : %llu, \"bps\" : %llu, \"bpp\" : %u}\n", + "\"flows\" : %" PRIu64 ", \"packets\" : %" PRIu64 ", \"bytes\" : %" PRIu64 ", \"pps\" : %" PRIu64 ", \"bps\" : %" PRIu64 + ", \"bpp\" : %u}\n", datestrFirst, (unsigned)(statRecord->msecFirst % 1000), datestrLast, (unsigned)(statRecord->msecLast % 1000), hashKey->proto, statName, valstr, count_flows, count_packets, count_bytes, pps, bps, bpp); } diff --git a/src/output/output_csv.c b/src/output/output_csv.c index 8bd3d4dd..f5daf4bc 100644 --- a/src/output/output_csv.c +++ b/src/output/output_csv.c @@ -2051,7 +2051,7 @@ static void String_PortBlockSize(FILE *stream, recordHandle_t *recordHandle) { static void String_flowId(FILE *stream, recordHandle_t *recordHandle) { EXflowId_t *flowId = (EXflowId_t *)recordHandle->extensionList[EXflowIdID]; - fprintf(stream, "0x%llu", flowId ? flowId->flowId : 0); + fprintf(stream, "0x%" PRIu64, flowId ? flowId->flowId : 0); } // End of String_flowId static void String_inServiceID(FILE *stream, recordHandle_t *recordHandle) { diff --git a/src/output/output_fmt.c b/src/output/output_fmt.c index 44b3fefb..a4970b6b 100755 --- a/src/output/output_fmt.c +++ b/src/output/output_fmt.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2547,7 +2548,7 @@ static void String_PortBlockSize(FILE *stream, recordHandle_t *recordHandle) { static void String_flowId(FILE *stream, recordHandle_t *recordHandle) { EXflowId_t *flowId = (EXflowId_t *)recordHandle->extensionList[EXflowIdID]; - fprintf(stream, "0x%13llu", flowId ? flowId->flowId : 0); + fprintf(stream, "0x%13" PRIu64, flowId ? flowId->flowId : 0); } // End of String_flowId static void String_inServiceID(FILE *stream, recordHandle_t *recordHandle) { diff --git a/src/output/output_json.c b/src/output/output_json.c index a89dc077..b27acc79 100755 --- a/src/output/output_json.c +++ b/src/output/output_json.c @@ -34,6 +34,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -662,7 +663,7 @@ static void stringEXnatPortBlock(FILE *stream, void *extensionRecord, const char static void stringEXflowId(FILE *stream, void *extensionRecord, const char *indent, const char *fs) { EXflowId_t *flowId = (EXflowId_t *)extensionRecord; - fprintf(stream, "%s\"flowID\" : %llu%s", indent, flowId->flowId, fs); + fprintf(stream, "%s\"flowID\" : %" PRIu64 "%s", indent, flowId->flowId, fs); } // End of stringEXflowId static void stringEXnokiaNat(FILE *stream, void *extensionRecord, const char *indent, const char *fs) { diff --git a/src/output/output_raw.c b/src/output/output_raw.c index 56a6fac4..b0a1979c 100755 --- a/src/output/output_raw.c +++ b/src/output/output_raw.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -821,7 +822,7 @@ static void stringsEXinmon(FILE *stream, void *extensionRecord) { static void stringsEXflowId(FILE *stream, void *extensionRecord) { EXflowId_t *flowId = (EXflowId_t *)extensionRecord; - fprintf(stream, " flow ID = 0x%13llx\n", flowId->flowId); + fprintf(stream, " flow ID = 0x%13" PRIx64 "\n", flowId->flowId); } // End of stringsEXflowId static void stringsEXnokiaNat(FILE *stream, void *extensionRecord) {