2005-02-05 02:12:01 +08:00
|
|
|
/*
|
2010-12-07 23:46:31 +08:00
|
|
|
* Copyright 2003,2005 Bernhard Walle <bernhard@bwalle.de>
|
2005-02-05 02:12:01 +08:00
|
|
|
* -------------------------------------------------------------------------------------------------
|
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
2005-02-05 02:12:01 +08:00
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2003-08-31 20:45:25 +08:00
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 675 Mass
|
|
|
|
* Ave, Cambridge, MA 02139, USA.
|
2003-08-31 20:45:25 +08:00
|
|
|
*
|
2005-02-05 02:12:01 +08:00
|
|
|
* -------------------------------------------------------------------------------------------------
|
2003-08-31 20:45:25 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This is just a command-line wrapper for the operating-system specific code in wormulon/.
|
|
|
|
* I wrote it because with this I'm able to test on systems with no GUI. Since I'm only running
|
|
|
|
* Linux but develop for other Operating systems this is important!
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
netdata data;
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-31 20:45:25 +08:00
|
|
|
void sig_end_handler (int sig)
|
|
|
|
{
|
|
|
|
close_netload(&data);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
int main(int argc, char* argv[])
|
2003-08-31 20:45:25 +08:00
|
|
|
{
|
|
|
|
unsigned long in, out, tot;
|
|
|
|
char* device;
|
2014-11-16 06:56:33 +08:00
|
|
|
char bufIn[20], bufOut[20], bufTot[20], bufBS[20];
|
2003-08-31 20:45:25 +08:00
|
|
|
struct sigaction sig_struct;
|
|
|
|
|
|
|
|
/* Signal fuer's Beenden */
|
|
|
|
sig_struct.sa_handler = sig_end_handler;
|
|
|
|
sigemptyset(&sig_struct.sa_mask);
|
|
|
|
sig_struct.sa_flags = 0;
|
|
|
|
|
|
|
|
if (sigaction(SIGINT, &sig_struct, NULL) != 0)
|
|
|
|
{
|
|
|
|
perror("Fehler");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "No device given. Exiting ...\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
device = argv[1];
|
|
|
|
init_netload(&data, device);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2022-08-23 11:03:59 +08:00
|
|
|
get_current_speed(&data, &in, &out, &tot);
|
2014-11-16 06:27:36 +08:00
|
|
|
format_byte_humanreadable(bufIn, 20, (double)in, 0, FALSE);
|
|
|
|
format_byte_humanreadable(bufOut, 20, (double)out, 0, FALSE);
|
2014-11-16 06:56:33 +08:00
|
|
|
format_byte_humanreadable(bufTot, 20, (double)tot, 2, TRUE);
|
|
|
|
format_byte_humanreadable(bufBS, 20, 12235345.0, 2, TRUE);
|
|
|
|
printf("Current netload:\nIN : %s\nOUT: %s\nTOT: %s\nBS: %s\nIP: %s\n",
|
|
|
|
bufIn, bufOut, bufTot, bufBS, get_ip_address(&data));
|
2003-08-31 20:45:25 +08:00
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|