Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/log.c | 70 ---------------------------------------------------------
src/serv.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 70 insertions(+), 73 deletions(-)
diff --git a/src/log.c b/src/log.c
index dfbeb99..0865dce 100644
--- a/src/log.c
+++ b/src/log.c
@@ -237,76 +237,6 @@ void writeothplog(int logging, FILE * fd, char *protname, char
*description,
}
}
-void writeutslog(struct portlistent *list, unsigned long nsecs, int units,
- FILE * fd)
-{
- char atime[TIME_TARGET_MAX];
- struct portlistent *ptmp = list;
- float inrate, outrate, totalrate;
- time_t now = time(NULL);
-
- genatime(time((time_t *) NULL), atime);
-
- fprintf(fd, "\n*** TCP/UDP traffic log, generated %s\n\n", atime);
-
- while (ptmp != NULL) {
- if (now - ptmp->proto_starttime < 5)
- inrate = outrate = totalrate = -1.0;
- else {
- if (units == KBITS) {
- inrate =
- (float) (ptmp->ibcount * 8 / 1000) /
- (float) (now - ptmp->proto_starttime);
- outrate =
- (float) (ptmp->obcount * 8 / 1000) /
- (float) (now - ptmp->proto_starttime);
- totalrate =
- (float) (ptmp->bcount * 8 / 1000) /
- (float) (now - ptmp->proto_starttime);
- } else {
- inrate =
- (float) (ptmp->obcount / 1024) /
- (float) (now - ptmp->proto_starttime);
- outrate =
- (float) (ptmp->obcount / 1024) /
- (float) (now - ptmp->proto_starttime);
- totalrate =
- (float) (ptmp->obcount / 1024) /
- (float) (now - ptmp->proto_starttime);
- }
- }
-
- if (ptmp->protocol == IPPROTO_TCP)
- fprintf(fd, "TCP/%s: ", ptmp->servname);
- else
- fprintf(fd, "UDP/%s: ", ptmp->servname);
-
- fprintf(fd, "%llu packets, %llu bytes total", ptmp->count,
- ptmp->bcount);
-
- if (totalrate >= 0.0)
- fprintf(fd, ", %.2f %s", totalrate, dispmode(units));
-
- fprintf(fd, "; %llu packets, %llu bytes incoming", ptmp->icount,
- ptmp->ibcount);
-
- if (inrate >= 0.0)
- fprintf(fd, ", %.2f %s", inrate, dispmode(units));
-
- fprintf(fd, "; %llu packets, %llu bytes outgoing", ptmp->ocount,
- ptmp->obcount);
-
- if (outrate >= 0.0)
- fprintf(fd, ", %.2f %s", outrate, dispmode(units));
-
- fprintf(fd, "\n\n");
- ptmp = ptmp->next_entry;
- }
-
- fprintf(fd, "\nRunning time: %lu seconds\n", nsecs);
- fflush(fd);
-}
-
void writeethlog(struct ethtabent *list, int unit, unsigned long nsecs,
FILE * fd)
{
diff --git a/src/serv.c b/src/serv.c
index 275c223..e6bb3c4 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -49,9 +49,6 @@ details.
extern int exitloop;
extern int daemonized;
-extern void writeutslog(struct portlistent *list, unsigned long nsecs, int unit,
- FILE * logfile);
-
/*
* SIGUSR1 logfile rotation signal handler
*/
@@ -63,6 +60,76 @@ void rotate_serv_log(int s __unused)
signal(SIGUSR1, rotate_serv_log);
}
+static void writeutslog(struct portlistent *list, unsigned long nsecs,
+ int units, FILE *fd)
+{
+ char atime[TIME_TARGET_MAX];
+ struct portlistent *ptmp = list;
+ float inrate, outrate, totalrate;
+ time_t now = time(NULL);
+
+ genatime(time(NULL), atime);
+
+ fprintf(fd, "\n*** TCP/UDP traffic log, generated %s\n\n", atime);
+
+ while (ptmp != NULL) {
+ if (now - ptmp->proto_starttime < 5)
+ inrate = outrate = totalrate = -1.0;
+ else {
+ if (units == KBITS) {
+ inrate =
+ (float) (ptmp->ibcount * 8 / 1000) /
+ (float) (now - ptmp->proto_starttime);
+ outrate =
+ (float) (ptmp->obcount * 8 / 1000) /
+ (float) (now - ptmp->proto_starttime);
+ totalrate =
+ (float) (ptmp->bcount * 8 / 1000) /
+ (float) (now - ptmp->proto_starttime);
+ } else {
+ inrate =
+ (float) (ptmp->obcount / 1024) /
+ (float) (now - ptmp->proto_starttime);
+ outrate =
+ (float) (ptmp->obcount / 1024) /
+ (float) (now - ptmp->proto_starttime);
+ totalrate =
+ (float) (ptmp->obcount / 1024) /
+ (float) (now - ptmp->proto_starttime);
+ }
+ }
+
+ if (ptmp->protocol == IPPROTO_TCP)
+ fprintf(fd, "TCP/%s: ", ptmp->servname);
+ else
+ fprintf(fd, "UDP/%s: ", ptmp->servname);
+
+ fprintf(fd, "%llu packets, %llu bytes total", ptmp->count,
+ ptmp->bcount);
+
+ if (totalrate >= 0.0)
+ fprintf(fd, ", %.2f %s", totalrate, dispmode(units));
+
+ fprintf(fd, "; %llu packets, %llu bytes incoming", ptmp->icount,
+ ptmp->ibcount);
+
+ if (inrate >= 0.0)
+ fprintf(fd, ", %.2f %s", inrate, dispmode(units));
+
+ fprintf(fd, "; %llu packets, %llu bytes outgoing", ptmp->ocount,
+ ptmp->obcount);
+
+ if (outrate >= 0.0)
+ fprintf(fd, ", %.2f %s", outrate, dispmode(units));
+
+ fprintf(fd, "\n\n");
+ ptmp = ptmp->next_entry;
+ }
+
+ fprintf(fd, "\nRunning time: %lu seconds\n", nsecs);
+ fflush(fd);
+}
+
void initportlist(struct portlist *list)
{
float screen_scale = ((float) COLS / 80 + 1) / 2;
--
1.7.8.4