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"
56 char info_source
[128];
59 #define MAXS (sizeof(struct rtnl_link_stats)/sizeof(__u32))
60 #define NO_SUB_TYPE 0xffff
63 struct ifstat_ent
*next
;
71 static const char *stats
[MAXS
] = {
91 "tx_heartbeat_errors",
97 struct ifstat_ent
*kern_db
;
98 struct ifstat_ent
*hist_db
;
100 static int match(const char *id
)
107 for (i
= 0; i
< npatterns
; i
++) {
108 if (!fnmatch(patterns
[i
], id
, 0))
114 static int get_nlmsg_extended(const struct sockaddr_nl
*who
,
115 struct nlmsghdr
*m
, void *arg
)
117 struct if_stats_msg
*ifsm
= NLMSG_DATA(m
);
118 struct rtattr
*tb
[IFLA_STATS_MAX
+1];
119 int len
= m
->nlmsg_len
;
120 struct ifstat_ent
*n
;
122 if (m
->nlmsg_type
!= RTM_NEWSTATS
)
125 len
-= NLMSG_LENGTH(sizeof(*ifsm
));
129 parse_rtattr(tb
, IFLA_STATS_MAX
, IFLA_STATS_RTA(ifsm
), len
);
130 if (tb
[filter_type
] == NULL
)
133 n
= malloc(sizeof(*n
));
137 n
->ifindex
= ifsm
->ifindex
;
138 n
->name
= strdup(ll_index_to_name(ifsm
->ifindex
));
140 if (sub_type
== NO_SUB_TYPE
) {
141 memcpy(&n
->val
, RTA_DATA(tb
[filter_type
]), sizeof(n
->val
));
145 attr
= parse_rtattr_one_nested(sub_type
, tb
[filter_type
]);
150 memcpy(&n
->val
, RTA_DATA(attr
), sizeof(n
->val
));
152 memset(&n
->rate
, 0, sizeof(n
->rate
));
158 static int get_nlmsg(const struct sockaddr_nl
*who
,
159 struct nlmsghdr
*m
, void *arg
)
161 struct ifinfomsg
*ifi
= NLMSG_DATA(m
);
162 struct rtattr
*tb
[IFLA_MAX
+1];
163 int len
= m
->nlmsg_len
;
164 struct ifstat_ent
*n
;
167 if (m
->nlmsg_type
!= RTM_NEWLINK
)
170 len
-= NLMSG_LENGTH(sizeof(*ifi
));
174 if (!(ifi
->ifi_flags
&IFF_UP
))
177 parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
178 if (tb
[IFLA_IFNAME
] == NULL
|| tb
[IFLA_STATS
] == NULL
)
181 n
= malloc(sizeof(*n
));
184 n
->ifindex
= ifi
->ifi_index
;
185 n
->name
= strdup(RTA_DATA(tb
[IFLA_IFNAME
]));
186 memcpy(&n
->ival
, RTA_DATA(tb
[IFLA_STATS
]), sizeof(n
->ival
));
187 memset(&n
->rate
, 0, sizeof(n
->rate
));
188 for (i
= 0; i
< MAXS
; i
++)
189 n
->val
[i
] = n
->ival
[i
];
195 static void load_info(void)
197 struct ifstat_ent
*db
, *n
;
198 struct rtnl_handle rth
;
201 if (rtnl_open(&rth
, 0) < 0)
206 filter_mask
= IFLA_STATS_FILTER_BIT(filter_type
);
207 if (rtnl_wilddump_stats_req_filter(&rth
, AF_UNSPEC
, RTM_GETSTATS
,
209 perror("Cannot send dump request");
213 if (rtnl_dump_filter(&rth
, get_nlmsg_extended
, NULL
) < 0) {
214 fprintf(stderr
, "Dump terminated\n");
218 if (rtnl_wilddump_request(&rth
, AF_INET
, RTM_GETLINK
) < 0) {
219 perror("Cannot send dump request");
223 if (rtnl_dump_filter(&rth
, get_nlmsg
, NULL
) < 0) {
224 fprintf(stderr
, "Dump terminated\n");
242 static void load_raw_table(FILE *fp
)
245 struct ifstat_ent
*db
= NULL
;
246 struct ifstat_ent
*n
;
248 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
254 buf
[strlen(buf
)-1] = 0;
255 if (info_source
[0] && strcmp(info_source
, buf
+1))
257 strncpy(info_source
, buf
+1, sizeof(info_source
)-1);
260 if ((n
= malloc(sizeof(*n
))) == NULL
)
263 if (!(p
= strchr(buf
, ' ')))
267 if (sscanf(buf
, "%d", &n
->ifindex
) != 1)
269 if (!(next
= strchr(p
, ' ')))
276 for (i
= 0; i
< MAXS
; i
++) {
279 if (!(next
= strchr(p
, ' ')))
282 if (sscanf(p
, "%llu", n
->val
+i
) != 1)
284 n
->ival
[i
] = (__u32
)n
->val
[i
];
286 if (!(next
= strchr(p
, ' ')))
289 if (sscanf(p
, "%u", &rate
) != 1)
306 static void dump_raw_db(FILE *fp
, int to_hist
)
308 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
309 struct ifstat_ent
*n
, *h
;
313 jsonw_start_object(jw
);
314 jsonw_pretty(jw
, pretty
);
315 jsonw_name(jw
, info_source
);
316 jsonw_start_object(jw
);
318 fprintf(fp
, "#%s\n", info_source
);
320 for (n
= kern_db
; n
; n
= n
->next
) {
322 unsigned long long *vals
= n
->val
;
323 double *rates
= n
->rate
;
325 if (!match(n
->name
)) {
326 struct ifstat_ent
*h1
;
330 for (h1
= h
; h1
; h1
= h1
->next
) {
331 if (h1
->ifindex
== n
->ifindex
) {
341 jsonw_name(jw
, n
->name
);
342 jsonw_start_object(jw
);
344 for (i
= 0; i
< MAXS
&& stats
[i
]; i
++)
345 jsonw_uint_field(jw
, stats
[i
], vals
[i
]);
346 jsonw_end_object(jw
);
348 fprintf(fp
, "%d %s ", n
->ifindex
, n
->name
);
349 for (i
= 0; i
< MAXS
; i
++)
350 fprintf(fp
, "%llu %u ", vals
[i
],
351 (unsigned int)rates
[i
]);
356 jsonw_end_object(jw
);
358 jsonw_end_object(jw
);
363 /* use communication definitions of meg/kilo etc */
364 static const unsigned long long giga
= 1000000000ull;
365 static const unsigned long long mega
= 1000000;
366 static const unsigned long long kilo
= 1000;
368 static void format_rate(FILE *fp
, const unsigned long long *vals
,
369 const double *rates
, int i
)
374 fprintf(fp
, "%7lluM ", vals
[i
]/mega
);
375 else if (vals
[i
] > mega
)
376 fprintf(fp
, "%7lluK ", vals
[i
]/kilo
);
378 fprintf(fp
, "%8llu ", vals
[i
]);
380 if (rates
[i
] > mega
) {
381 sprintf(temp
, "%uM", (unsigned int)(rates
[i
]/mega
));
382 fprintf(fp
, "%-6s ", temp
);
383 } else if (rates
[i
] > kilo
) {
384 sprintf(temp
, "%uK", (unsigned int)(rates
[i
]/kilo
));
385 fprintf(fp
, "%-6s ", temp
);
387 fprintf(fp
, "%-6u ", (unsigned int)rates
[i
]);
390 static void format_pair(FILE *fp
, const unsigned long long *vals
, int i
, int k
)
395 fprintf(fp
, "%7lluM ", vals
[i
]/mega
);
396 else if (vals
[i
] > mega
)
397 fprintf(fp
, "%7lluK ", vals
[i
]/kilo
);
399 fprintf(fp
, "%8llu ", vals
[i
]);
401 if (vals
[k
] > giga
) {
402 sprintf(temp
, "%uM", (unsigned int)(vals
[k
]/mega
));
403 fprintf(fp
, "%-6s ", temp
);
404 } else if (vals
[k
] > mega
) {
405 sprintf(temp
, "%uK", (unsigned int)(vals
[k
]/kilo
));
406 fprintf(fp
, "%-6s ", temp
);
408 fprintf(fp
, "%-6u ", (unsigned int)vals
[k
]);
411 static void print_head(FILE *fp
)
413 fprintf(fp
, "#%s\n", info_source
);
414 fprintf(fp
, "%-15s ", "Interface");
416 fprintf(fp
, "%8s/%-6s ", "RX Pkts", "Rate");
417 fprintf(fp
, "%8s/%-6s ", "TX Pkts", "Rate");
418 fprintf(fp
, "%8s/%-6s ", "RX Data", "Rate");
419 fprintf(fp
, "%8s/%-6s\n", "TX Data", "Rate");
422 fprintf(fp
, "%-15s ", "");
423 fprintf(fp
, "%8s/%-6s ", "RX Errs", "Drop");
424 fprintf(fp
, "%8s/%-6s ", "TX Errs", "Drop");
425 fprintf(fp
, "%8s/%-6s ", "RX Over", "Rate");
426 fprintf(fp
, "%8s/%-6s\n", "TX Coll", "Rate");
428 fprintf(fp
, "%-15s ", "");
429 fprintf(fp
, "%8s/%-6s ", "RX Errs", "Rate");
430 fprintf(fp
, "%8s/%-6s ", "RX Drop", "Rate");
431 fprintf(fp
, "%8s/%-6s ", "RX Over", "Rate");
432 fprintf(fp
, "%8s/%-6s\n", "RX Leng", "Rate");
434 fprintf(fp
, "%-15s ", "");
435 fprintf(fp
, "%8s/%-6s ", "RX Crc", "Rate");
436 fprintf(fp
, "%8s/%-6s ", "RX Frm", "Rate");
437 fprintf(fp
, "%8s/%-6s ", "RX Fifo", "Rate");
438 fprintf(fp
, "%8s/%-6s\n", "RX Miss", "Rate");
440 fprintf(fp
, "%-15s ", "");
441 fprintf(fp
, "%8s/%-6s ", "TX Errs", "Rate");
442 fprintf(fp
, "%8s/%-6s ", "TX Drop", "Rate");
443 fprintf(fp
, "%8s/%-6s ", "TX Coll", "Rate");
444 fprintf(fp
, "%8s/%-6s\n", "TX Carr", "Rate");
446 fprintf(fp
, "%-15s ", "");
447 fprintf(fp
, "%8s/%-6s ", "TX Abrt", "Rate");
448 fprintf(fp
, "%8s/%-6s ", "TX Fifo", "Rate");
449 fprintf(fp
, "%8s/%-6s ", "TX Hear", "Rate");
450 fprintf(fp
, "%8s/%-6s\n", "TX Wind", "Rate");
454 static void print_one_json(json_writer_t
*jw
, const struct ifstat_ent
*n
,
455 const unsigned long long *vals
)
457 int i
, m
= show_errors
? 20 : 10;
459 jsonw_name(jw
, n
->name
);
460 jsonw_start_object(jw
);
462 for (i
= 0; i
< m
&& stats
[i
]; i
++)
463 jsonw_uint_field(jw
, stats
[i
], vals
[i
]);
465 jsonw_end_object(jw
);
468 static void print_one_if(FILE *fp
, const struct ifstat_ent
*n
,
469 const unsigned long long *vals
)
473 fprintf(fp
, "%-15s ", n
->name
);
474 for (i
= 0; i
< 4; i
++)
475 format_rate(fp
, vals
, n
->rate
, i
);
479 fprintf(fp
, "%-15s ", "");
480 format_pair(fp
, vals
, 4, 6);
481 format_pair(fp
, vals
, 5, 7);
482 format_rate(fp
, vals
, n
->rate
, 11);
483 format_rate(fp
, vals
, n
->rate
, 9);
486 fprintf(fp
, "%-15s ", "");
487 format_rate(fp
, vals
, n
->rate
, 4);
488 format_rate(fp
, vals
, n
->rate
, 6);
489 format_rate(fp
, vals
, n
->rate
, 11);
490 format_rate(fp
, vals
, n
->rate
, 10);
493 fprintf(fp
, "%-15s ", "");
494 format_rate(fp
, vals
, n
->rate
, 12);
495 format_rate(fp
, vals
, n
->rate
, 13);
496 format_rate(fp
, vals
, n
->rate
, 14);
497 format_rate(fp
, vals
, n
->rate
, 15);
500 fprintf(fp
, "%-15s ", "");
501 format_rate(fp
, vals
, n
->rate
, 5);
502 format_rate(fp
, vals
, n
->rate
, 7);
503 format_rate(fp
, vals
, n
->rate
, 9);
504 format_rate(fp
, vals
, n
->rate
, 17);
507 fprintf(fp
, "%-15s ", "");
508 format_rate(fp
, vals
, n
->rate
, 16);
509 format_rate(fp
, vals
, n
->rate
, 18);
510 format_rate(fp
, vals
, n
->rate
, 19);
511 format_rate(fp
, vals
, n
->rate
, 20);
516 static void dump_kern_db(FILE *fp
)
518 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
519 struct ifstat_ent
*n
;
522 jsonw_start_object(jw
);
523 jsonw_pretty(jw
, pretty
);
524 jsonw_name(jw
, info_source
);
525 jsonw_start_object(jw
);
529 for (n
= kern_db
; n
; n
= n
->next
) {
534 print_one_json(jw
, n
, n
->val
);
536 print_one_if(fp
, n
, n
->val
);
539 jsonw_end_object(jw
);
541 jsonw_end_object(jw
);
546 static void dump_incr_db(FILE *fp
)
548 struct ifstat_ent
*n
, *h
;
549 json_writer_t
*jw
= json_output
? jsonw_new(fp
) : NULL
;
553 jsonw_start_object(jw
);
554 jsonw_pretty(jw
, pretty
);
555 jsonw_name(jw
, info_source
);
556 jsonw_start_object(jw
);
560 for (n
= kern_db
; n
; n
= n
->next
) {
562 unsigned long long vals
[MAXS
];
563 struct ifstat_ent
*h1
;
565 memcpy(vals
, n
->val
, sizeof(vals
));
567 for (h1
= h
; h1
; h1
= h1
->next
) {
568 if (h1
->ifindex
== n
->ifindex
) {
569 for (i
= 0; i
< MAXS
; i
++)
570 vals
[i
] -= h1
->val
[i
];
579 print_one_json(jw
, n
, n
->val
);
581 print_one_if(fp
, n
, vals
);
585 jsonw_end_object(jw
);
587 jsonw_end_object(jw
);
594 static void sigchild(int signo
)
598 static void update_db(int interval
)
600 struct ifstat_ent
*n
, *h
;
610 for (n
= kern_db
; n
; n
= n
->next
) {
611 struct ifstat_ent
*h1
;
613 for (h1
= h
; h1
; h1
= h1
->next
) {
614 if (h1
->ifindex
== n
->ifindex
) {
617 for (i
= 0; i
< MAXS
; i
++) {
618 if ((long)(h1
->ival
[i
] - n
->ival
[i
]) < 0) {
619 memset(n
->ival
, 0, sizeof(n
->ival
));
623 for (i
= 0; i
< MAXS
; i
++) {
628 incr
= h1
->val
[i
] - n
->val
[i
];
629 n
->val
[i
] = h1
->val
[i
];
631 incr
= (__u32
) (h1
->ival
[i
] - n
->ival
[i
]);
633 n
->ival
[i
] = h1
->ival
[i
];
636 sample
= (double)(incr
*1000)/interval
;
637 if (interval
>= scan_interval
) {
638 n
->rate
[i
] += W
*(sample
-n
->rate
[i
]);
639 } else if (interval
>= 1000) {
640 if (interval
>= time_constant
) {
643 double w
= W
*(double)interval
/scan_interval
;
645 n
->rate
[i
] += w
*(sample
-n
->rate
[i
]);
651 struct ifstat_ent
*tmp
= h
;
666 #define T_DIFF(a, b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
669 static void server_loop(int fd
)
671 struct timeval snaptime
= { 0 };
675 p
.events
= p
.revents
= POLLIN
;
677 sprintf(info_source
, "%d.%lu sampling_interval=%d time_const=%d",
678 getpid(), (unsigned long)random(), scan_interval
/1000, time_constant
/1000);
687 gettimeofday(&now
, NULL
);
688 tdiff
= T_DIFF(now
, snaptime
);
689 if (tdiff
>= scan_interval
) {
695 if (poll(&p
, 1, scan_interval
- tdiff
) > 0
696 && (p
.revents
&POLLIN
)) {
697 int clnt
= accept(fd
, NULL
, NULL
);
704 } else if ((pid
= fork()) != 0) {
709 FILE *fp
= fdopen(clnt
, "w");
717 while (children
&& waitpid(-1, &status
, WNOHANG
) > 0)
722 static int verify_forging(int fd
)
725 socklen_t olen
= sizeof(cred
);
727 if (getsockopt(fd
, SOL_SOCKET
, SO_PEERCRED
, (void *)&cred
, &olen
) ||
730 if (cred
.uid
== getuid() || cred
.uid
== 0)
735 static void xstat_usage(void)
738 "Usage: ifstat supported xstats:\n"
739 " cpu_hits Counts only packets that went via the CPU.\n");
742 struct extended_stats_options_t
{
748 /* Note: if one xstat name is subset of another, it should be before it in this
750 * Name length must be under 64 chars.
752 static const struct extended_stats_options_t extended_stats_options
[] = {
753 {"cpu_hits", IFLA_STATS_LINK_OFFLOAD_XSTATS
, IFLA_OFFLOAD_XSTATS_CPU_HIT
},
756 static const char *get_filter_type(const char *name
)
761 name_len
= strlen(name
);
762 for (i
= 0; i
< ARRAY_SIZE(extended_stats_options
); i
++) {
763 const struct extended_stats_options_t
*xstat
;
765 xstat
= &extended_stats_options
[i
];
766 if (strncmp(name
, xstat
->name
, name_len
) == 0) {
767 filter_type
= xstat
->id
;
768 sub_type
= xstat
->sub_type
;
773 fprintf(stderr
, "invalid ifstat extension %s\n", name
);
778 static void usage(void) __attribute__((noreturn
));
780 static void usage(void)
783 "Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
784 " -h, --help this message\n"
785 " -a, --ignore ignore history\n"
786 " -d, --scan=SECS sample every statistics every SECS\n"
787 " -e, --errors show errors\n"
788 " -j, --json format output in JSON\n"
789 " -n, --nooutput do history only\n"
790 " -p, --pretty pretty print\n"
791 " -r, --reset reset history\n"
792 " -s, --noupdate don't update history\n"
793 " -t, --interval=SECS report average over the last SECS\n"
794 " -V, --version output version information\n"
795 " -z, --zeros show entries with zero activity\n"
796 " -x, --extended=TYPE show extended stats of TYPE\n");
801 static const struct option longopts
[] = {
802 { "help", 0, 0, 'h' },
803 { "ignore", 0, 0, 'a' },
804 { "scan", 1, 0, 'd'},
805 { "errors", 0, 0, 'e' },
806 { "nooutput", 0, 0, 'n' },
807 { "json", 0, 0, 'j' },
808 { "reset", 0, 0, 'r' },
809 { "pretty", 0, 0, 'p' },
810 { "noupdate", 0, 0, 's' },
811 { "interval", 1, 0, 't' },
812 { "version", 0, 0, 'V' },
813 { "zeros", 0, 0, 'z' },
814 { "extended", 1, 0, 'x'},
818 int main(int argc
, char *argv
[])
821 struct sockaddr_un sun
;
822 FILE *hist_fp
= NULL
;
823 const char *stats_type
= NULL
;
828 while ((ch
= getopt_long(argc
, argv
, "hjpvVzrnasd:t:ex:",
829 longopts
, NULL
)) != EOF
) {
856 scan_interval
= atoi(optarg
) * 1000;
857 if (scan_interval
<= 0) {
858 fprintf(stderr
, "ifstat: invalid scan interval\n");
863 time_constant
= atoi(optarg
);
864 if (time_constant
<= 0) {
865 fprintf(stderr
, "ifstat: invalid time constant divisor\n");
875 printf("ifstat utility, iproute2-ss%s\n", SNAPSHOT
);
888 stats_type
= get_filter_type(stats_type
);
893 sun
.sun_family
= AF_UNIX
;
895 sprintf(sun
.sun_path
+1, "ifstat%d", getuid());
897 if (scan_interval
> 0) {
898 if (time_constant
== 0)
900 time_constant
*= 1000;
901 W
= 1 - 1/exp(log(10)*(double)scan_interval
/time_constant
);
902 if ((fd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) < 0) {
903 perror("ifstat: socket");
906 if (bind(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) < 0) {
907 perror("ifstat: bind");
910 if (listen(fd
, 5) < 0) {
911 perror("ifstat: listen");
915 perror("ifstat: daemon");
918 signal(SIGPIPE
, SIG_IGN
);
919 signal(SIGCHLD
, sigchild
);
927 if (getenv("IFSTAT_HISTORY"))
928 snprintf(hist_name
, sizeof(hist_name
),
929 "%s", getenv("IFSTAT_HISTORY"));
932 snprintf(hist_name
, sizeof(hist_name
),
933 "%s/.ifstat.u%d", P_tmpdir
, getuid());
935 snprintf(hist_name
, sizeof(hist_name
),
936 "%s/.%s_ifstat.u%d", P_tmpdir
, stats_type
,
942 if (!ignore_history
|| !no_update
) {
945 fd
= open(hist_name
, O_RDWR
|O_CREAT
|O_NOFOLLOW
, 0600);
947 perror("ifstat: open history file");
950 if ((hist_fp
= fdopen(fd
, "r+")) == NULL
) {
951 perror("ifstat: fdopen history file");
954 if (flock(fileno(hist_fp
), LOCK_EX
)) {
955 perror("ifstat: flock history file");
958 if (fstat(fileno(hist_fp
), &stb
) != 0) {
959 perror("ifstat: fstat history file");
962 if (stb
.st_nlink
!= 1 || stb
.st_uid
!= getuid()) {
963 fprintf(stderr
, "ifstat: something is so wrong with history file, that I prefer not to proceed.\n");
966 if (!ignore_history
) {
970 if ((tfp
= fopen("/proc/uptime", "r")) != NULL
) {
971 if (fscanf(tfp
, "%ld", &uptime
) != 1)
975 if (uptime
>= 0 && time(NULL
) >= stb
.st_mtime
+uptime
) {
976 fprintf(stderr
, "ifstat: history is aged out, resetting\n");
977 if (ftruncate(fileno(hist_fp
), 0))
978 perror("ifstat: ftruncate");
982 load_raw_table(hist_fp
);
988 if ((fd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) >= 0 &&
989 (connect(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) == 0
990 || (strcpy(sun
.sun_path
+1, "ifstat0"),
991 connect(fd
, (struct sockaddr
*)&sun
, 2+1+strlen(sun
.sun_path
+1)) == 0))
992 && verify_forging(fd
) == 0) {
993 FILE *sfp
= fdopen(fd
, "r");
996 fprintf(stderr
, "ifstat: fdopen failed: %s\n",
1000 load_raw_table(sfp
);
1001 if (hist_db
&& source_mismatch
) {
1002 fprintf(stderr
, "ifstat: history is stale, ignoring it.\n");
1010 if (hist_db
&& info_source
[0] && strcmp(info_source
, "kernel")) {
1011 fprintf(stderr
, "ifstat: history is stale, ignoring it.\n");
1016 if (info_source
[0] == 0)
1017 strcpy(info_source
, "kernel");
1021 if (ignore_history
|| hist_db
== NULL
)
1022 dump_kern_db(stdout
);
1024 dump_incr_db(stdout
);
1028 if (ftruncate(fileno(hist_fp
), 0))
1029 perror("ifstat: ftruncate");
1033 dump_raw_db(hist_fp
, 1);