[20896] | 1 | /* $Id: netload.c,v 1.1.1.2 2004-10-03 04:59:48 ghudson Exp $ */ |
---|
[18271] | 2 | |
---|
| 3 | /* Copyright (C) 1998-99 Martin Baulig |
---|
| 4 | This file is part of LibGTop 1.0. |
---|
| 5 | |
---|
| 6 | Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. |
---|
| 7 | |
---|
| 8 | LibGTop is free software; you can redistribute it and/or modify it |
---|
| 9 | under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2 of the License, |
---|
| 11 | or (at your option) any later version. |
---|
| 12 | |
---|
| 13 | LibGTop is distributed in the hope that it will be useful, but WITHOUT |
---|
| 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 16 | for more details. |
---|
| 17 | |
---|
| 18 | You should have received a copy of the GNU General Public License |
---|
| 19 | along with LibGTop; see the file COPYING. If not, write to the |
---|
| 20 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
| 21 | Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <locale.h> |
---|
[20896] | 25 | #include <libintl.h> |
---|
| 26 | #include <stdio.h> |
---|
[18271] | 27 | |
---|
| 28 | #include <glibtop.h> |
---|
| 29 | #include <glibtop/open.h> |
---|
| 30 | #include <glibtop/close.h> |
---|
| 31 | |
---|
| 32 | #include <glibtop/parameter.h> |
---|
| 33 | |
---|
| 34 | #include <glibtop/netload.h> |
---|
| 35 | |
---|
| 36 | #include <netinet/in.h> |
---|
| 37 | #include <arpa/inet.h> |
---|
| 38 | |
---|
| 39 | #ifndef PROFILE_COUNT |
---|
| 40 | #define PROFILE_COUNT 1 |
---|
| 41 | #endif |
---|
| 42 | |
---|
| 43 | int |
---|
| 44 | main (int argc, char *argv []) |
---|
| 45 | { |
---|
| 46 | glibtop_netload netload; |
---|
| 47 | unsigned method, count, port; |
---|
| 48 | struct in_addr addr, subnet; |
---|
| 49 | char *address_string, *subnet_string; |
---|
| 50 | char buffer [BUFSIZ]; |
---|
| 51 | |
---|
| 52 | count = PROFILE_COUNT; |
---|
| 53 | |
---|
| 54 | setlocale (LC_ALL, ""); |
---|
| 55 | bindtextdomain (GETTEXT_PACKAGE, GTOPLOCALEDIR); |
---|
| 56 | textdomain (GETTEXT_PACKAGE); |
---|
[20896] | 57 | |
---|
[18271] | 58 | glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN); |
---|
| 59 | |
---|
| 60 | glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method)); |
---|
| 61 | |
---|
| 62 | printf ("Method = %d\n", method); |
---|
| 63 | |
---|
| 64 | count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ); |
---|
| 65 | buffer [count] = 0; |
---|
| 66 | |
---|
| 67 | printf ("Command = '%s'\n", buffer); |
---|
| 68 | |
---|
| 69 | count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ); |
---|
| 70 | buffer [count] = 0; |
---|
| 71 | |
---|
| 72 | glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port)); |
---|
| 73 | |
---|
| 74 | printf ("Host = '%s' - %u\n\n", buffer, port); |
---|
| 75 | |
---|
| 76 | glibtop_init_r (&glibtop_global_server, 0, 0); |
---|
| 77 | |
---|
| 78 | if (argc != 2) |
---|
| 79 | glibtop_error ("Usage: %s interface", argv [0]); |
---|
[20896] | 80 | |
---|
[18271] | 81 | glibtop_get_netload (&netload, argv [1]); |
---|
| 82 | |
---|
| 83 | addr.s_addr = netload.address; |
---|
| 84 | subnet.s_addr = netload.subnet; |
---|
| 85 | |
---|
[20896] | 86 | address_string = g_strdup (inet_ntoa (addr)); |
---|
| 87 | subnet_string = g_strdup (inet_ntoa (subnet)); |
---|
[18271] | 88 | |
---|
| 89 | printf ("Network Load (0x%08lx):\n\n" |
---|
| 90 | "\tInterface Flags:\t0x%08lx\n" |
---|
| 91 | "\tAddress:\t\t0x%08lx - %s\n" |
---|
| 92 | "\tSubnet:\t\t\t0x%08lx - %s\n\n" |
---|
| 93 | "\tMTU:\t\t\t%ld\n" |
---|
| 94 | "\tCollisions:\t\t%ld\n\n" |
---|
| 95 | "\tPackets In:\t\t%ld\n" |
---|
| 96 | "\tPackets Out:\t\t%ld\n" |
---|
| 97 | "\tPackets Total:\t\t%ld\n\n" |
---|
| 98 | "\tBytes In:\t\t%ld\n" |
---|
| 99 | "\tBytes Out:\t\t%ld\n" |
---|
| 100 | "\tBytes Total:\t\t%ld\n\n" |
---|
| 101 | "\tErrors In:\t\t%ld\n" |
---|
| 102 | "\tErrors Out:\t\t%ld\n" |
---|
| 103 | "\tErrors Total:\t\t%ld\n\n", |
---|
| 104 | (unsigned long) netload.flags, |
---|
| 105 | (unsigned long) netload.if_flags, |
---|
| 106 | (unsigned long) netload.address, address_string, |
---|
| 107 | (unsigned long) netload.subnet, subnet_string, |
---|
| 108 | (unsigned long) netload.mtu, |
---|
| 109 | (unsigned long) netload.collisions, |
---|
| 110 | (unsigned long) netload.packets_in, |
---|
| 111 | (unsigned long) netload.packets_out, |
---|
| 112 | (unsigned long) netload.packets_total, |
---|
| 113 | (unsigned long) netload.bytes_in, |
---|
| 114 | (unsigned long) netload.bytes_out, |
---|
| 115 | (unsigned long) netload.bytes_total, |
---|
| 116 | (unsigned long) netload.errors_in, |
---|
| 117 | (unsigned long) netload.errors_out, |
---|
| 118 | (unsigned long) netload.errors_total); |
---|
| 119 | |
---|
[20896] | 120 | g_free (address_string); |
---|
| 121 | g_free (subnet_string); |
---|
[18271] | 122 | |
---|
| 123 | glibtop_close (); |
---|
| 124 | |
---|
| 125 | exit (0); |
---|
| 126 | } |
---|