--- projects/libstatgrab/examples/network_traffic.c 2004/03/06 22:37:27 1.9 +++ projects/libstatgrab/examples/network_traffic.c 2004/04/06 14:52:56 1.14 @@ -1,5 +1,5 @@ /* - * i-scream central monitoring system + * i-scream libstatgrab * http://www.i-scream.org * Copyright (C) 2000-2004 i-scream * @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id: network_traffic.c,v 1.9 2004/03/06 22:37:27 tdb Exp $ + * $Id: network_traffic.c,v 1.14 2004/04/06 14:52:56 tdb Exp $ */ /* A very basic example of how to get the network statistics from the system @@ -42,14 +42,13 @@ int main(int argc, char **argv){ extern char *optarg; - extern int optind; int c; /* We default to 1 second updates and displaying in bytes*/ int delay = 1; char units = 'b'; - network_stat_t *network_stats; + sg_network_io_stats *network_stats; int num_network_stats; /* Parse command line options */ @@ -71,10 +70,10 @@ int main(int argc, char **argv){ } /* Initialise statgrab */ - statgrab_init(); + sg_init(); /* Drop setuid/setgid privileges. */ - if (statgrab_drop_privileges() != 0) { + if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); return 1; } @@ -83,7 +82,7 @@ int main(int argc, char **argv){ * Because of this, we do nothing for the very first call. */ - network_stats = get_network_stats_diff(&num_network_stats); + network_stats = sg_get_network_io_stats_diff(&num_network_stats); if (network_stats == NULL){ perror("Error. Failed to get network stats"); return 1; @@ -93,7 +92,7 @@ int main(int argc, char **argv){ printf("\033[2J"); /* Keep getting the network stats */ - while ( (network_stats = get_network_stats_diff(&num_network_stats)) != NULL){ + while ( (network_stats = sg_get_network_io_stats_diff(&num_network_stats)) != NULL){ int x; int line_number = 2; @@ -122,11 +121,11 @@ int main(int argc, char **argv){ printf("\033[%d;2H%-30s : %5.2f m", line_number++, "Network Interface Rx", network_stats->rx / (1024.00*1024.00)); printf("\033[%d;2H%-30s : %5.2f m", line_number++, "Network Interface Tx", network_stats->tx / (1024.00*1024.00)); } - printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface packets in", network_stats->ipackets); - printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface packets out", network_stats->opackets); - printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface errors in", network_stats->ierrors); - printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface errors out", network_stats->oerrors); - printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface collisions", network_stats->collisions); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Interface packets in", network_stats->ipackets); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Interface packets out", network_stats->opackets); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Interface errors in", network_stats->ierrors); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Interface errors out", network_stats->oerrors); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Interface collisions", network_stats->collisions); printf("\033[%d;2H%-30s : %ld ", line_number++, "Network Interface systime", (long) network_stats->systime); /* Add a blank line between interfaces */ @@ -161,11 +160,11 @@ int main(int argc, char **argv){ printf("\033[%d;2H%-30s : %5.2f m", line_number++, "Network Total Tx", (total_tx / (1024.00*1024.00))); break; } - printf("\033[%d;2H%-30s : %8lld b", line_number++, "Network Total packets in", total_ipackets); - printf("\033[%d;2H%-30s : %8lld b", line_number++, "Network Total packets out", total_opackets); - printf("\033[%d;2H%-30s : %8lld b", line_number++, "Network Total errors in", total_ierrors); - printf("\033[%d;2H%-30s : %8lld b", line_number++, "Network Total errors out", total_oerrors); - printf("\033[%d;2H%-30s : %8lld b", line_number++, "Network Total collisions", total_collisions); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Total packets in", total_ipackets); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Total packets out", total_opackets); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Total errors in", total_ierrors); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Total errors out", total_oerrors); + printf("\033[%d;2H%-30s : %lld ", line_number++, "Network Total collisions", total_collisions); fflush(stdout);