2 * ifstat.c handy utility to read net interface statistics
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
22 #include <sys/socket.h>
32 #include <linux/if_link.h>
34 #include "libnetlink.h"
35 #include "json_writer.h"
55 char info_source
[128];
58 #define MAXS (sizeof(struct rtnl_link_stats)/sizeof(__u32))
59 #define NO_SUB_TYPE 0xffff
62 struct ifstat_ent
*next
;
70 static const char *stats
[MAXS
] = {
90 "tx_heartbeat_errors",
96 struct ifstat_ent
*kern_db
;
97 struct ifstat_ent
*hist_db
;
99 static int match(const char *id
)
106 for (i
= 0; i
< npatterns
; i
++) {
107 if (!fnmatch(patterns
[i
], id
, 0))
113 static int get_nlmsg_extended(const struct sockaddr_nl
*who
,
114 struct nlmsghdr
*m
, void *arg
)
116 struct if_stats_msg
*ifsm
= NLMSG_DATA(m
);
117 struct rtattr
*tb
[IFLA_STATS_MAX
+1];
118 int len
= m
->nlmsg_len
;
119 struct ifstat_ent
*n
;
121 if (m
->nlmsg_type
!= RTM_NEWSTATS
)
124 len
-= NLMSG_LENGTH(sizeof(*ifsm
));
128 parse_rtattr(tb
, IFLA_STATS_MAX
, IFLA_STATS_RTA(ifsm
), len
);
129 if (tb
[filter_type
] == NULL
)
132 n
= malloc(sizeof(*n
));
136 n
->ifindex
= ifsm
->ifindex
;
137 n
->name
= strdup(ll_index_to_name(ifsm
->ifindex
));
139 if (sub_type
== NO_SUB_TYPE
) {
140 memcpy(&n
->val
, RTA_DATA(tb
[filter_type
]), sizeof(n
->val
));
144 attr
= parse_rtattr_one_nested(sub_type
, tb
[filter_type
]);
149 memcpy(&n
->val
, RTA_DATA(attr
), sizeof(n
->val
));
151 memset(&n
->rate
, 0, sizeof(n
->rate
));
157 static int get_nlmsg(const struct sockaddr_nl
*who
,
158 struct nlmsghdr
*m
, void *arg
)
160 struct ifinfomsg
*ifi
= NLMSG_DATA(m
);
161 struct rtattr
*tb
[IFLA_MAX
+1];
162 int len
= m
->nlmsg_len
;
163 struct ifstat_ent
*n
;
166 if (m
->nlmsg_type
!= RTM_NEWLINK
)
169 len
-= NLMSG_LENGTH(sizeof(*ifi
));
173 if (!(ifi
->ifi_flags
&IFF_UP
))
176 parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
177 if (tb
[IFLA_IFNAME
] == NULL
|| tb
[IFLA_STATS
] == NULL
)
180 n
= malloc(sizeof(*n
));
183 n
->ifindex
= ifi
->ifi_index
;
184 n
->name
= strdup(RTA_DATA(tb
[IFLA_IFNAME
]));
185 memcpy(&n
->ival
, RTA_DATA(tb
[IFLA_STATS
]), sizeof(n
->ival
));
186 memset(&n
->rate
, 0, sizeof(n
->rate
));
187 for (i
= 0; i
< MAXS
; i
++)
188 n
->val
[i
] = n
->ival
[i
];
194 static void load_info(void)
196 struct ifstat_ent
*db
, *n
;
197 struct rtnl_handle rth
;
200 if (rtnl_open(&rth
, 0) < 0)
205 filter_mask
= IFLA_STATS_FILTER_BIT(filter_type
);
206 if (rtnl_wilddump_stats_req_filter(&rth
, AF_UNSPEC
, RTM_GETSTATS
,
208 perror("Cannot send dump request");
212 if (rtnl_dump_filter(&rth
, get_nlmsg_extended
, NULL
) < 0) {
213 fprintf(stderr
, "Dump terminated\n");
217 if (rtnl_wilddump_request(&rth
, AF_INET
, RTM_GETLINK
) < 0) {
218 perror("Cannot send dump request");
222 if (rtnl_dump_filter(&rth
, get_nlmsg
, NULL
) < 0) {
223 fprintf(stderr
, "Dump terminated\n");
241 static void load_raw_table(FILE *fp
)
244 struct ifstat_ent
*db
= NULL
;
245 struct ifstat_ent
*n
;
247 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
253 buf
[strlen(buf
)-1] = 0;
254 if (info_source
[0] && strcmp(info_source
, buf
+1))
256 strncpy(info_source
, buf
+1, sizeof(info_source
)-1);
259 if ((n
= malloc(sizeof(*n
))) == NULL
)
262 if (!(p
= strchr(buf
, ' ')))
266 if (sscanf(buf
, "%d", &n
->ifindex
) != 1)
268 if (!(next
= strchr(p
, ' ')))
275 for (i
= 0; i
< MAXS
; i
++) {
278 if (!(next
= strchr(p
, ' ')))
281 if (sscanf(p
, "%llu", n
->val
+i
) != 1)
283 n
->ival
[i
] = (__u32
)n
->val
[i
];
285 if (!(next
= strchr(p
, ' ')))
288 if (sscanf(p
, "%u", &rate
) != 1)
305 static void dump_raw_db(FILE *fp
, int to_hist
)
307 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
308 struct ifstat_ent
*n
, *h
;
312 jsonw_start_object(jw
);
313 jsonw_pretty(jw
, pretty
);
314 jsonw_name(jw
, info_source
);
315 jsonw_start_object(jw
);
317 fprintf(fp
, "#%s\n", info_source
);
319 for (n
= kern_db
; n
; n
= n
->next
) {
321 unsigned long long *vals
= n
->val
;
322 double *rates
= n
->rate
;
324 if (!match(n
->name
)) {
325 struct ifstat_ent
*h1
;
329 for (h1
= h
; h1
; h1
= h1
->next
) {
330 if (h1
->ifindex
== n
->ifindex
) {
340 jsonw_name(jw
, n
->name
);
341 jsonw_start_object(jw
);
343 for (i
= 0; i
< MAXS
&& stats
[i
]; i
++)
344 jsonw_uint_field(jw
, stats
[i
], vals
[i
]);
345 jsonw_end_object(jw
);
347 fprintf(fp
, "%d %s ", n
->ifindex
, n
->name
);
348 for (i
= 0; i
< MAXS
; i
++)
349 fprintf(fp
, "%llu %u ", vals
[i
],
350 (unsigned int)rates
[i
]);
355 jsonw_end_object(jw
);
357 jsonw_end_object(jw
);
362 /* use communication definitions of meg/kilo etc */
363 static const unsigned long long giga
= 1000000000ull;
364 static const unsigned long long mega
= 1000000;
365 static const unsigned long long kilo
= 1000;
367 static void format_rate(FILE *fp
, const unsigned long long *vals
,
368 const double *rates
, int i
)
373 fprintf(fp
, "%7lluM ", vals
[i
]/mega
);
374 else if (vals
[i
] > mega
)
375 fprintf(fp
, "%7lluK ", vals
[i
]/kilo
);
377 fprintf(fp
, "%8llu ", vals
[i
]);
379 if (rates
[i
] > mega
) {
380 sprintf(temp
, "%uM", (unsigned int)(rates
[i
]/mega
));
381 fprintf(fp
, "%-6s ", temp
);
382 } else if (rates
[i
] > kilo
) {
383 sprintf(temp
, "%uK", (unsigned int)(rates
[i
]/kilo
));
384 fprintf(fp
, "%-6s ", temp
);
386 fprintf(fp
, "%-6u ", (unsigned int)rates
[i
]);
389 static void format_pair(FILE *fp
, const unsigned long long *vals
, int i
, int k
)
394 fprintf(fp
, "%7lluM ", vals
[i
]/mega
);
395 else if (vals
[i
] > mega
)
396 fprintf(fp
, "%7lluK ", vals
[i
]/kilo
);
398 fprintf(fp
, "%8llu ", vals
[i
]);
400 if (vals
[k
] > giga
) {
401 sprintf(temp
, "%uM", (unsigned int)(vals
[k
]/mega
));
402 fprintf(fp
, "%-6s ", temp
);
403 } else if (vals
[k
] > mega
) {
404 sprintf(temp
, "%uK", (unsigned int)(vals
[k
]/kilo
));
405 fprintf(fp
, "%-6s ", temp
);
407 fprintf(fp
, "%-6u ", (unsigned int)vals
[k
]);
410 static void print_head(FILE *fp
)
412 fprintf(fp
, "#%s\n", info_source
);
413 fprintf(fp
, "%-15s ", "Interface");
415 fprintf(fp
, "%8s/%-6s ", "RX Pkts", "Rate");
416 fprintf(fp
, "%8s/%-6s ", "TX Pkts", "Rate");
417 fprintf(fp
, "%8s/%-6s ", "RX Data", "Rate");
418 fprintf(fp
, "%8s/%-6s\n", "TX Data", "Rate");
421 fprintf(fp
, "%-15s ", "");
422 fprintf(fp
, "%8s/%-6s ", "RX Errs", "Drop");
423 fprintf(fp
, "%8s/%-6s ", "TX Errs", "Drop");
424 fprintf(fp
, "%8s/%-6s ", "RX Over", "Rate");
425 fprintf(fp
, "%8s/%-6s\n", "TX Coll", "Rate");
427 fprintf(fp
, "%-15s ", "");
428 fprintf(fp
, "%8s/%-6s ", "RX Errs", "Rate");
429 fprintf(fp
, "%8s/%-6s ", "RX Drop", "Rate");
430 fprintf(fp
, "%8s/%-6s ", "RX Over", "Rate");
431 fprintf(fp
, "%8s/%-6s\n", "RX Leng", "Rate");
433 fprintf(fp
, "%-15s ", "");
434 fprintf(fp
, "%8s/%-6s ", "RX Crc", "Rate");
435 fprintf(fp
, "%8s/%-6s ", "RX Frm", "Rate");
436 fprintf(fp
, "%8s/%-6s ", "RX Fifo", "Rate");
437 fprintf(fp
, "%8s/%-6s\n", "RX Miss", "Rate");
439 fprintf(fp
, "%-15s ", "");
440 fprintf(fp
, "%8s/%-6s ", "TX Errs", "Rate");
441 fprintf(fp
, "%8s/%-6s ", "TX Drop", "Rate");
442 fprintf(fp
, "%8s/%-6s ", "TX Coll", "Rate");
443 fprintf(fp
, "%8s/%-6s\n", "TX Carr", "Rate");
445 fprintf(fp
, "%-15s ", "");
446 fprintf(fp
, "%8s/%-6s ", "TX Abrt", "Rate");
447 fprintf(fp
, "%8s/%-6s ", "TX Fifo", "Rate");
448 fprintf(fp
, "%8s/%-6s ", "TX Hear", "Rate");
449 fprintf(fp
, "%8s/%-6s\n", "TX Wind", "Rate");
453 static void print_one_json(json_writer_t
*jw
, const struct ifstat_ent
*n
,
454 const unsigned long long *vals
)
456 int i
, m
= show_errors
? 20 : 10;
458 jsonw_name(jw
, n
->name
);
459 jsonw_start_object(jw
);
461 for (i
= 0; i
< m
&& stats
[i
]; i
++)
462 jsonw_uint_field(jw
, stats
[i
], vals
[i
]);
464 jsonw_end_object(jw
);
467 static void print_one_if(FILE *fp
, const struct ifstat_ent
*n
,
468 const unsigned long long *vals
)
472 fprintf(fp
, "%-15s ", n
->name
);
473 for (i
= 0; i
< 4; i
++)
474 format_rate(fp
, vals
, n
->rate
, i
);
478 fprintf(fp
, "%-15s ", "");
479 format_pair(fp
, vals
, 4, 6);
480 format_pair(fp
, vals
, 5, 7);
481 format_rate(fp
, vals
, n
->rate
, 11);
482 format_rate(fp
, vals
, n
->rate
, 9);
485 fprintf(fp
, "%-15s ", "");
486 format_rate(fp
, vals
, n
->rate
, 4);
487 format_rate(fp
, vals
, n
->rate
, 6);
488 format_rate(fp
, vals
, n
->rate
, 11);
489 format_rate(fp
, vals
, n
->rate
, 10);
492 fprintf(fp
, "%-15s ", "");
493 format_rate(fp
, vals
, n
->rate
, 12);
494 format_rate(fp
, vals
, n
->rate
, 13);
495 format_rate(fp
, vals
, n
->rate
, 14);
496 format_rate(fp
, vals
, n
->rate
, 15);
499 fprintf(fp
, "%-15s ", "");
500 format_rate(fp
, vals
, n
->rate
, 5);
501 format_rate(fp
, vals
, n
->rate
, 7);
502 format_rate(fp
, vals
, n
->rate
, 9);
503 format_rate(fp
, vals
, n
->rate
, 17);
506 fprintf(fp
, "%-15s ", "");
507 format_rate(fp
, vals
, n
->rate
, 16);
508 format_rate(fp
, vals
, n
->rate
, 18);
509 format_rate(fp
, vals
, n
->rate
, 19);
510 format_rate(fp
, vals
, n
->rate
, 20);
515 static void dump_kern_db(FILE *fp
)
517 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
518 struct ifstat_ent
*n
;
521 jsonw_start_object(jw
);
522 jsonw_pretty(jw
, pretty
);
523 jsonw_name(jw
, info_source
);
524 jsonw_start_object(jw
);
528 for (n
= kern_db
; n
; n
= n
->next
) {
533 print_one_json(jw
, n
, n
->val
);
535 print_one_if(fp
, n
, n
->val
);
538 jsonw_end_object(jw
);
540 jsonw_end_object(jw
);
545 static void dump_incr_db(FILE *fp
)
547 struct ifstat_ent
*n
, *h
;
548 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
552 jsonw_start_object(jw
);
553 jsonw_pretty(jw
, pretty
);
554 jsonw_name(jw
, info_source
);
555 jsonw_start_object(jw
);
559 for (n
= kern_db
; n
; n
= n
->next
) {
561 unsigned long long vals
[MAXS
];
562 struct ifstat_ent
*h1
;
564 memcpy(vals
, n
->val
, sizeof(vals
));
566 for (h1
= h
; h1
; h1
= h1
->next
) {
567 if (h1
->ifindex
== n
->ifindex
) {
568 for (i
= 0; i
< MAXS
; i
++)
569 vals
[i
] -= h1
->val
[i
];
578 print_one_json(jw
, n
, n
->val
);
580 print_one_if(fp
, n
, vals
);
584 jsonw_end_object(jw
);
586 jsonw_end_object(jw
);
593 static void sigchild(int signo
)
597 static void update_db(int interval
)
599 struct ifstat_ent
*n
, *h
;
609 for (n
= kern_db
; n
; n
= n
->next
) {
610 struct ifstat_ent
*h1
;
612 for (h1
= h
; h1
; h1
= h1
->next
) {
613 if (h1
->ifindex
== n
->ifindex
) {
616 for (i
= 0; i
< MAXS
; i
++) {
617 if ((long)(h1
->ival
[i
] - n
->ival
[i
]) < 0) {
618 memset(n
->ival
, 0, sizeof(n
->ival
));
622 for (i
= 0; i
< MAXS
; i
++) {
627 incr
= h1
->val
[i
] - n
->val
[i
];
628 n
->val
[i
] = h1
->val
[i
];
630 incr
= (__u32
) (h1
->ival
[i
] - n
->ival
[i
]);
632 n
->ival
[i
] = h1
->ival
[i
];
635 sample
= (double)(incr
*1000)/interval
;
636 if (interval
>= scan_interval
) {
637 n
->rate
[i
] += W
*(sample
-n
->rate
[i
]);
638 } else if (interval
>= 1000) {
639 if (interval
>= time_constant
) {
642 double w
= W
*(double)interval
/scan_interval
;
644 n
->rate
[i
] += w
*(sample
-n
->rate
[i
]);
650 struct ifstat_ent
*tmp
= h
;
665 #define T_DIFF(a, b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
668 static void server_loop(int fd
)
670 struct timeval snaptime
= { 0 };
674 p
.events
= p
.revents
= POLLIN
;
676 sprintf(info_source
, "%d.%lu sampling_interval=%d time_const=%d",
677 getpid(), (unsigned long)random(), scan_interval
/1000, time_constant
/1000);
686 gettimeofday(&now
, NULL
);
687 tdiff
= T_DIFF(now
, snaptime
);
688 if (tdiff
>= scan_interval
) {
694 if (poll(&p
, 1, scan_interval
- tdiff
) > 0
695 && (p
.revents
&POLLIN
)) {
696 int clnt
= accept(fd
, NULL
, NULL
);
703 } else if ((pid
= fork()) != 0) {
708 FILE *fp
= fdopen(clnt
, "w");
716 while (children
&& waitpid(-1, &status
, WNOHANG
) > 0)
721 static int verify_forging(int fd
)
724 socklen_t olen
= sizeof(cred
);
726 if (getsockopt(fd
, SOL_SOCKET
, SO_PEERCRED
, (void *)&cred
, &olen
) ||
729 if (cred
.uid
== getuid() || cred
.uid
== 0)
734 static void xstat_usage(void)
737 "Usage: ifstat supported xstats:\n"
738 " cpu_hits Counts only packets that went via the CPU.\n");
741 struct extended_stats_options_t
{
747 /* Note: if one xstat name is subset of another, it should be before it in this
749 * Name length must be under 64 chars.
751 static const struct extended_stats_options_t extended_stats_options
[] = {
752 {"cpu_hits", IFLA_STATS_LINK_OFFLOAD_XSTATS
, IFLA_OFFLOAD_XSTATS_CPU_HIT
},
755 static const char *get_filter_type(const char *name
)
760 name_len
= strlen(name
);
761 for (i
= 0; i
< ARRAY_SIZE(extended_stats_options
); i
++) {
762 const struct extended_stats_options_t
*xstat
;
764 xstat
= &extended_stats_options
[i
];
765 if (strncmp(name
, xstat
->name
, name_len
) == 0) {
766 filter_type
= xstat
->id
;
767 sub_type
= xstat
->sub_type
;
772 fprintf(stderr
, "invalid ifstat extension %s\n", name
);
777 static void usage(void) __attribute__((noreturn
));
779 static void usage(void)
782 "Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
783 " -h, --help this message\n"
784 " -a, --ignore ignore history\n"
785 " -d, --scan=SECS sample every statistics every SECS\n"
786 " -e, --errors show errors\n"
787 " -j, --json format output in JSON\n"
788 " -n, --nooutput do history only\n"
789 " -p, --pretty pretty print\n"
790 " -r, --reset reset history\n"
791 " -s, --noupdate don't update history\n"
792 " -t, --interval=SECS report average over the last SECS\n"
793 " -V, --version output version information\n"
794 " -z, --zeros show entries with zero activity\n"
795 " -x, --extended=TYPE show extended stats of TYPE\n");
800 static const struct option longopts
[] = {
801 { "help", 0, 0, 'h' },
802 { "ignore", 0, 0, 'a' },
803 { "scan", 1, 0, 'd'},
804 { "errors", 0, 0, 'e' },
805 { "nooutput", 0, 0, 'n' },
806 { "json", 0, 0, 'j' },
807 { "reset", 0, 0, 'r' },
808 { "pretty", 0, 0, 'p' },
809 { "noupdate", 0, 0, 's' },
810 { "interval", 1, 0, 't' },
811 { "version", 0, 0, 'V' },
812 { "zeros", 0, 0, 'z' },
813 { "extended", 1, 0, 'x'},
817 int main(int argc
, char *argv
[])
820 struct sockaddr_un sun
;
821 FILE *hist_fp
= NULL
;
822 const char *stats_type
= NULL
;
827 while ((ch
= getopt_long(argc
, argv
, "hjpvVzrnasd:t:ex:",
828 longopts
, NULL
)) != EOF
) {
855 scan_interval
= atoi(optarg
) * 1000;
856 if (scan_interval
<= 0) {
857 fprintf(stderr
, "ifstat: invalid scan interval\n");
862 time_constant
= atoi(optarg
);
863 if (time_constant
<= 0) {
864 fprintf(stderr
, "ifstat: invalid time constant divisor\n");
874 printf("ifstat utility, iproute2-ss%s\n", SNAPSHOT
);
887 stats_type
= get_filter_type(stats_type
);
892 sun
.sun_family
= AF_UNIX
;
894 sprintf(sun
.sun_path
+1, "ifstat%d", getuid());
896 if (scan_interval
> 0) {
897 if (time_constant
== 0)
899 time_constant
*= 1000;
900 W
= 1 - 1/exp(log(10)*(double)scan_interval
/time_constant
);
901 if ((fd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) < 0) {
902 perror("ifstat: socket");
905 if (bind(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) < 0) {
906 perror("ifstat: bind");
909 if (listen(fd
, 5) < 0) {
910 perror("ifstat: listen");
914 perror("ifstat: daemon");
917 signal(SIGPIPE
, SIG_IGN
);
918 signal(SIGCHLD
, sigchild
);
926 if (getenv("IFSTAT_HISTORY"))
927 snprintf(hist_name
, sizeof(hist_name
),
928 "%s", getenv("IFSTAT_HISTORY"));
931 snprintf(hist_name
, sizeof(hist_name
),
932 "%s/.ifstat.u%d", P_tmpdir
, getuid());
934 snprintf(hist_name
, sizeof(hist_name
),
935 "%s/.%s_ifstat.u%d", P_tmpdir
, stats_type
,
941 if (!ignore_history
|| !no_update
) {
944 fd
= open(hist_name
, O_RDWR
|O_CREAT
|O_NOFOLLOW
, 0600);
946 perror("ifstat: open history file");
949 if ((hist_fp
= fdopen(fd
, "r+")) == NULL
) {
950 perror("ifstat: fdopen history file");
953 if (flock(fileno(hist_fp
), LOCK_EX
)) {
954 perror("ifstat: flock history file");
957 if (fstat(fileno(hist_fp
), &stb
) != 0) {
958 perror("ifstat: fstat history file");
961 if (stb
.st_nlink
!= 1 || stb
.st_uid
!= getuid()) {
962 fprintf(stderr
, "ifstat: something is so wrong with history file, that I prefer not to proceed.\n");
965 if (!ignore_history
) {
969 if ((tfp
= fopen("/proc/uptime", "r")) != NULL
) {
970 if (fscanf(tfp
, "%ld", &uptime
) != 1)
974 if (uptime
>= 0 && time(NULL
) >= stb
.st_mtime
+uptime
) {
975 fprintf(stderr
, "ifstat: history is aged out, resetting\n");
976 if (ftruncate(fileno(hist_fp
), 0))
977 perror("ifstat: ftruncate");
981 load_raw_table(hist_fp
);
987 if ((fd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) >= 0 &&
988 (connect(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) == 0
989 || (strcpy(sun
.sun_path
+1, "ifstat0"),
990 connect(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) == 0))
991 && verify_forging(fd
) == 0) {
992 FILE *sfp
= fdopen(fd
, "r");
995 fprintf(stderr
, "ifstat: fdopen failed: %s\n",
1000 if (hist_db
&& source_mismatch
) {
1001 fprintf(stderr
, "ifstat: history is stale, ignoring it.\n");
1009 if (hist_db
&& info_source
[0] && strcmp(info_source
, "kernel")) {
1010 fprintf(stderr
, "ifstat: history is stale, ignoring it.\n");
1015 if (info_source
[0] == 0)
1016 strcpy(info_source
, "kernel");
1020 if (ignore_history
|| hist_db
== NULL
)
1021 dump_kern_db(stdout
);
1023 dump_incr_db(stdout
);
1027 if (ftruncate(fileno(hist_fp
), 0))
1028 perror("ifstat: ftruncate");
1032 dump_raw_db(hist_fp
, 1);