Split netload into netload and netinfo.
1999-11-28 Martin Baulig <martin@home-of-linux.org> Split netload into netload and netinfo. * include/glibtop/netinfo.h: New file. * include/glibtop/netload.h (glibtop_netload): Moved `if_flags', `mtu', `subnet' and `address' into the new `glibtop_netinfo'. * include/glibtop/sysdeps.h (GLIBTOP_SYSDEPS_NETINFO): Added. (glibtop_sysdeps): Added `netinfo. * include/glibtop/union.h (glibtop_union): Added `netinfo. * include/glibtop/command.h (GLIBTOP_CMND_NETINFO): Added.
This commit is contained in:
committed by
Martin Baulig
parent
53f9d03e30
commit
4a01752467
14
ChangeLog
14
ChangeLog
@@ -1,3 +1,17 @@
|
||||
1999-11-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Split netload into netload and netinfo.
|
||||
|
||||
* include/glibtop/netinfo.h: New file.
|
||||
|
||||
* include/glibtop/netload.h (glibtop_netload): Moved `if_flags',
|
||||
`mtu', `subnet' and `address' into the new `glibtop_netinfo'.
|
||||
|
||||
* include/glibtop/sysdeps.h (GLIBTOP_SYSDEPS_NETINFO): Added.
|
||||
(glibtop_sysdeps): Added `netinfo.
|
||||
* include/glibtop/union.h (glibtop_union): Added `netinfo.
|
||||
* include/glibtop/command.h (GLIBTOP_CMND_NETINFO): Added.
|
||||
|
||||
1999-11-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* include/glibtop/interfaces.h (glibtop_get_interface_names):
|
||||
|
@@ -18,6 +18,7 @@ char *|proc_args|ulong(size)|pid_t(pid):unsigned(max_len)
|
||||
glibtop_map_entry *|proc_map|ulong(number,size,total)|pid_t(pid)
|
||||
glibtop_mountentry *|@mountlist|ulong(number,size,total)|int(all_fs)
|
||||
retval|@fsusage|ulong(blocks,bfree,bavail,files,ffree)|string(mount_dir)
|
||||
retval|netload|ulong(if_flags,mtu,subnet,address,packets_in,packets_out,packets_total,bytes_in,bytes_out,bytes_total,errors_in,errors_out,errors_total,collisions)|string(interface)
|
||||
char *|interface_names|ulong(size)|unsigned(interface,number,instance,strategy)
|
||||
retval|netinfo|ulong(if_flags,mtu,subnet,address)|string(interface)
|
||||
retval|netload|ulong(packets_in,packets_out,packets_total,bytes_in,bytes_out,bytes_total,errors_in,errors_out,errors_total,collisions)|string(interface)
|
||||
retval|ppp|ulong(state,bytes_in,bytes_out)|ushort(device)
|
||||
|
@@ -8,4 +8,4 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \
|
||||
procsignal.h read_data.h union.h types.h gnuserv.h \
|
||||
parameter.h mountlist.h fsusage.h procmap.h signal.h \
|
||||
inodedb.h sysinfo.h ppp.h procargs.h netload.h \
|
||||
interfaces.h limits.h
|
||||
netinfo.h interfaces.h limits.h
|
||||
|
@@ -57,11 +57,12 @@ BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#define GLIBTOP_CMND_MOUNTLIST 20
|
||||
#define GLIBTOP_CMND_FSUSAGE 21
|
||||
#define GLIBTOP_CMND_NETLOAD 22
|
||||
#define GLIBTOP_CMND_INTERFACE_NAMES 23
|
||||
#define GLIBTOP_CMND_PPP 24
|
||||
#define GLIBTOP_CMND_INTERFACE_NAMES 22
|
||||
#define GLIBTOP_CMND_NETINFO 23
|
||||
#define GLIBTOP_CMND_NETLOAD 24
|
||||
#define GLIBTOP_CMND_PPP 25
|
||||
|
||||
#define GLIBTOP_MAX_CMND 25
|
||||
#define GLIBTOP_MAX_CMND 26
|
||||
|
||||
#define _GLIBTOP_PARAM_SIZE 16
|
||||
|
||||
|
104
include/glibtop/netinfo.h
Normal file
104
include/glibtop/netinfo.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_NETINFO_H__
|
||||
#define __GLIBTOP_NETINFO_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/global.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#define GLIBTOP_NETINFO_IF_FLAGS 0
|
||||
#define GLIBTOP_NETINFO_MTU 1
|
||||
#define GLIBTOP_NETINFO_SUBNET 2
|
||||
#define GLIBTOP_NETINFO_ADDRESS 3
|
||||
|
||||
#define GLIBTOP_MAX_NETINFO 4
|
||||
|
||||
typedef struct _glibtop_netinfo glibtop_netinfo;
|
||||
|
||||
#include <glibtop/interfaces.h>
|
||||
|
||||
enum {
|
||||
GLIBTOP_IF_FLAGS_UP = 1,
|
||||
GLIBTOP_IF_FLAGS_BROADCAST,
|
||||
GLIBTOP_IF_FLAGS_DEBUG,
|
||||
GLIBTOP_IF_FLAGS_LOOPBACK,
|
||||
GLIBTOP_IF_FLAGS_POINTOPOINT,
|
||||
GLIBTOP_IF_FLAGS_RUNNING,
|
||||
GLIBTOP_IF_FLAGS_NOARP,
|
||||
GLIBTOP_IF_FLAGS_PROMISC,
|
||||
GLIBTOP_IF_FLAGS_ALLMULTI,
|
||||
GLIBTOP_IF_FLAGS_OACTIVE,
|
||||
GLIBTOP_IF_FLAGS_SIMPLEX,
|
||||
GLIBTOP_IF_FLAGS_LINK0,
|
||||
GLIBTOP_IF_FLAGS_LINK1,
|
||||
GLIBTOP_IF_FLAGS_LINK2,
|
||||
GLIBTOP_IF_FLAGS_ALTPHYS,
|
||||
GLIBTOP_IF_FLAGS_MULTICAST
|
||||
};
|
||||
|
||||
struct _glibtop_netinfo
|
||||
{
|
||||
u_int64_t flags,
|
||||
if_flags, /* GLIBTOP_NETINFO_IF_FLAGS */
|
||||
mtu, /* GLIBTOP_NETINFO_MTU */
|
||||
subnet, /* GLIBTOP_NETINFO_SUBNET */
|
||||
address; /* GLIBTOP_NETINFO_ADDRESS */
|
||||
};
|
||||
|
||||
#define glibtop_get_netinfo(netinfo,interface) glibtop_get_netinfo_l(glibtop_global_server, netinfo, interface)
|
||||
|
||||
#if GLIBTOP_SUID_NETINFO
|
||||
#define glibtop_get_netinfo_r glibtop_get_netinfo_p
|
||||
#else
|
||||
#define glibtop_get_netinfo_r glibtop_get_netinfo_s
|
||||
#endif
|
||||
|
||||
int glibtop_get_netinfo_l (glibtop *server, glibtop_netinfo *buf, const char *interface);
|
||||
|
||||
#if GLIBTOP_SUID_NETINFO
|
||||
int glibtop_init_netinfo_p (glibtop *server);
|
||||
int glibtop_get_netinfo_p (glibtop *server, glibtop_netinfo *buf, const char *interface);
|
||||
#else
|
||||
int glibtop_init_netinfo_s (glibtop *server);
|
||||
int glibtop_get_netinfo_s (glibtop *server, glibtop_netinfo *buf, const char *interface);
|
||||
#endif
|
||||
|
||||
#ifdef GLIBTOP_NAMES
|
||||
|
||||
/* You need to link with -lgtop_names to get this stuff here. */
|
||||
|
||||
extern const char *glibtop_names_netinfo [];
|
||||
extern const unsigned glibtop_types_netinfo [];
|
||||
extern const char *glibtop_labels_netinfo [];
|
||||
extern const char *glibtop_descriptions_netinfo [];
|
||||
|
||||
#endif
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -31,53 +31,26 @@
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#define GLIBTOP_NETLOAD_IF_FLAGS 0
|
||||
#define GLIBTOP_NETLOAD_MTU 1
|
||||
#define GLIBTOP_NETLOAD_SUBNET 2
|
||||
#define GLIBTOP_NETLOAD_ADDRESS 3
|
||||
#define GLIBTOP_NETLOAD_PACKETS_IN 4
|
||||
#define GLIBTOP_NETLOAD_PACKETS_OUT 5
|
||||
#define GLIBTOP_NETLOAD_PACKETS_TOTAL 6
|
||||
#define GLIBTOP_NETLOAD_BYTES_IN 7
|
||||
#define GLIBTOP_NETLOAD_BYTES_OUT 8
|
||||
#define GLIBTOP_NETLOAD_BYTES_TOTAL 9
|
||||
#define GLIBTOP_NETLOAD_ERRORS_IN 10
|
||||
#define GLIBTOP_NETLOAD_ERRORS_OUT 11
|
||||
#define GLIBTOP_NETLOAD_ERRORS_TOTAL 12
|
||||
#define GLIBTOP_NETLOAD_COLLISIONS 13
|
||||
#define GLIBTOP_NETLOAD_PACKETS_IN 0
|
||||
#define GLIBTOP_NETLOAD_PACKETS_OUT 1
|
||||
#define GLIBTOP_NETLOAD_PACKETS_TOTAL 2
|
||||
#define GLIBTOP_NETLOAD_BYTES_IN 3
|
||||
#define GLIBTOP_NETLOAD_BYTES_OUT 4
|
||||
#define GLIBTOP_NETLOAD_BYTES_TOTAL 5
|
||||
#define GLIBTOP_NETLOAD_ERRORS_IN 6
|
||||
#define GLIBTOP_NETLOAD_ERRORS_OUT 7
|
||||
#define GLIBTOP_NETLOAD_ERRORS_TOTAL 8
|
||||
#define GLIBTOP_NETLOAD_COLLISIONS 9
|
||||
|
||||
#define GLIBTOP_MAX_NETLOAD 14
|
||||
#define GLIBTOP_MAX_NETLOAD 10
|
||||
|
||||
typedef struct _glibtop_netload glibtop_netload;
|
||||
|
||||
#include <glibtop/interfaces.h>
|
||||
|
||||
enum {
|
||||
GLIBTOP_IF_FLAGS_UP = 1,
|
||||
GLIBTOP_IF_FLAGS_BROADCAST,
|
||||
GLIBTOP_IF_FLAGS_DEBUG,
|
||||
GLIBTOP_IF_FLAGS_LOOPBACK,
|
||||
GLIBTOP_IF_FLAGS_POINTOPOINT,
|
||||
GLIBTOP_IF_FLAGS_RUNNING,
|
||||
GLIBTOP_IF_FLAGS_NOARP,
|
||||
GLIBTOP_IF_FLAGS_PROMISC,
|
||||
GLIBTOP_IF_FLAGS_ALLMULTI,
|
||||
GLIBTOP_IF_FLAGS_OACTIVE,
|
||||
GLIBTOP_IF_FLAGS_SIMPLEX,
|
||||
GLIBTOP_IF_FLAGS_LINK0,
|
||||
GLIBTOP_IF_FLAGS_LINK1,
|
||||
GLIBTOP_IF_FLAGS_LINK2,
|
||||
GLIBTOP_IF_FLAGS_ALTPHYS,
|
||||
GLIBTOP_IF_FLAGS_MULTICAST
|
||||
};
|
||||
|
||||
struct _glibtop_netload
|
||||
{
|
||||
u_int64_t flags,
|
||||
if_flags, /* GLIBTOP_NETLOAD_IF_FLAGS */
|
||||
mtu, /* GLIBTOP_NETLOAD_MTU */
|
||||
subnet, /* GLIBTOP_NETLOAD_SUBNET */
|
||||
address, /* GLIBTOP_NETLOAD_ADDRESS */
|
||||
packets_in, /* GLIBTOP_NETLOAD_PACKETS_IN */
|
||||
packets_out, /* GLIBTOP_NETLOAD_PACKETS_OUT */
|
||||
packets_total, /* GLIBTOP_NETLOAD_PACKETS_TOTAL*/
|
||||
|
@@ -50,11 +50,12 @@ BEGIN_LIBGTOP_DECLS
|
||||
#define GLIBTOP_SYSDEPS_PROC_MAP 17
|
||||
#define GLIBTOP_SYSDEPS_MOUNTLIST 18
|
||||
#define GLIBTOP_SYSDEPS_FSUSAGE 19
|
||||
#define GLIBTOP_SYSDEPS_NETLOAD 20
|
||||
#define GLIBTOP_SYSDEPS_INTERFACE_NAMES 21
|
||||
#define GLIBTOP_SYSDEPS_PPP 22
|
||||
#define GLIBTOP_SYSDEPS_INTERFACE_NAMES 20
|
||||
#define GLIBTOP_SYSDEPS_NETINFO 21
|
||||
#define GLIBTOP_SYSDEPS_NETLOAD 22
|
||||
#define GLIBTOP_SYSDEPS_PPP 23
|
||||
|
||||
#define GLIBTOP_MAX_SYSDEPS 25
|
||||
#define GLIBTOP_MAX_SYSDEPS 26
|
||||
|
||||
#define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1)
|
||||
|
||||
@@ -89,8 +90,9 @@ struct _glibtop_sysdeps
|
||||
proc_map, /* glibtop_proc_map */
|
||||
mountlist, /* glibtop_mountlist */
|
||||
fsusage, /* glibtop_fsusage */
|
||||
netload, /* glibtop_netload */
|
||||
interface_names, /* glibtop_interface_names */
|
||||
netinfo, /* glibtop_netinfo */
|
||||
netload, /* glibtop_netload */
|
||||
ppp; /* glibtop_ppp */
|
||||
};
|
||||
|
||||
|
@@ -50,6 +50,7 @@
|
||||
#include <glibtop/fsusage.h>
|
||||
|
||||
#include <glibtop/netload.h>
|
||||
#include <glibtop/netinfo.h>
|
||||
#include <glibtop/interfaces.h>
|
||||
#include <glibtop/ppp.h>
|
||||
|
||||
@@ -79,8 +80,9 @@ union _glibtop_union
|
||||
glibtop_proc_map proc_map;
|
||||
glibtop_mountlist mountlist;
|
||||
glibtop_fsusage fsusage;
|
||||
glibtop_netload netload;
|
||||
glibtop_interface_names interface_names;
|
||||
glibtop_netinfo netinfo;
|
||||
glibtop_netload netload;
|
||||
glibtop_ppp ppp;
|
||||
};
|
||||
|
||||
|
@@ -231,6 +231,12 @@ handle_parent_connection (int s)
|
||||
(server, &resp->u.data.ppp, device);
|
||||
do_output (s, resp, _offset_data (ppp), 0, NULL, retval);
|
||||
break;
|
||||
case GLIBTOP_CMND_NETINFO:
|
||||
retval = glibtop_get_netinfo_l
|
||||
(server, &resp->u.data.netinfo, parameter);
|
||||
do_output (s, resp, _offset_data (netinfo),
|
||||
0, NULL, retval);
|
||||
break;
|
||||
case GLIBTOP_CMND_NETLOAD:
|
||||
retval = glibtop_get_netload_l
|
||||
(server, &resp->u.data.netload, parameter);
|
||||
|
@@ -51,6 +51,7 @@ GLIBTOP_SUID_PROC_KERNEL +
|
||||
GLIBTOP_SUID_PROC_SEGMENT +
|
||||
GLIBTOP_SUID_PROC_ARGS +
|
||||
GLIBTOP_SUID_PROC_MAP +
|
||||
GLIBTOP_SUID_NETINFO +
|
||||
GLIBTOP_SUID_NETLOAD +
|
||||
GLIBTOP_SUID_INTERFACE_NAMES +
|
||||
GLIBTOP_SUID_PPP;
|
||||
|
@@ -263,6 +263,12 @@ handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
|
||||
resp->offset = _offset_data (proc_segment);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_NETINFO
|
||||
case GLIBTOP_CMND_NETINFO:
|
||||
retval = glibtop_get_netinfo_p (server, &resp->u.data.netinfo, parameter);
|
||||
resp->offset = _offset_data (netload);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_NETLOAD
|
||||
case GLIBTOP_CMND_NETLOAD:
|
||||
retval = glibtop_get_netload_p (server, &resp->u.data.netload, parameter);
|
||||
|
@@ -9,7 +9,8 @@ libgtop_sysdeps_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c siglist.c \
|
||||
sysinfo.c netload.c interfaces.c ppp.c
|
||||
sysinfo.c interfaces.c netinfo.c netload.c \
|
||||
ppp.c
|
||||
libgtop_sysdeps_la_LIBADD = @GLIB_LIBS@
|
||||
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
@@ -126,6 +126,7 @@ proc_stat_after_cmd (char *p)
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT 0
|
||||
#define GLIBTOP_SUID_PROC_ARGS 0
|
||||
#define GLIBTOP_SUID_PROC_MAP 0
|
||||
#define GLIBTOP_SUID_NETINFO 0
|
||||
#define GLIBTOP_SUID_NETLOAD 0
|
||||
#define GLIBTOP_SUID_INTERFACE_NAMES 0
|
||||
#define GLIBTOP_SUID_PPP 0
|
||||
|
143
sysdeps/linux/netinfo.c
Normal file
143
sysdeps/linux/netinfo.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/netinfo.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netinfo =
|
||||
(1L << GLIBTOP_NETINFO_ADDRESS) +
|
||||
(1L << GLIBTOP_NETINFO_SUBNET) +
|
||||
(1L << GLIBTOP_NETINFO_MTU);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
int
|
||||
glibtop_init_netinfo_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netinfo = _glibtop_sysdeps_netinfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
int
|
||||
glibtop_get_netinfo_s (glibtop *server, glibtop_netinfo *buf,
|
||||
const char *interface)
|
||||
{
|
||||
int skfd;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netinfo));
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (skfd) {
|
||||
struct ifreq ifr;
|
||||
unsigned flags;
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_IF_FLAGS);
|
||||
flags = ifr.ifr_flags;
|
||||
} else
|
||||
flags = 0;
|
||||
|
||||
if (flags & IFF_UP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
|
||||
|
||||
if (flags & IFF_BROADCAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
|
||||
|
||||
if (flags & IFF_DEBUG)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
|
||||
|
||||
if (flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
|
||||
|
||||
if (flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
|
||||
|
||||
if (flags & IFF_RUNNING)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
|
||||
|
||||
if (flags & IFF_NOARP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
|
||||
|
||||
if (flags & IFF_PROMISC)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
|
||||
|
||||
if (flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
|
||||
|
||||
if (flags & IFF_MULTICAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->address = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_ADDRESS);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->subnet = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_SUBNET);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
|
||||
buf->mtu = ifr.ifr_mtu;
|
||||
buf->flags |= (1L << GLIBTOP_NETINFO_MTU);
|
||||
}
|
||||
|
||||
close (skfd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -55,11 +55,6 @@ static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_data =
|
||||
(1L << GLIBTOP_NETLOAD_ADDRESS) +
|
||||
(1L << GLIBTOP_NETLOAD_SUBNET) +
|
||||
(1L << GLIBTOP_NETLOAD_MTU);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_bytes =
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
@@ -92,7 +87,6 @@ int
|
||||
glibtop_init_netload_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload |
|
||||
_glibtop_sysdeps_netload_data |
|
||||
_glibtop_sysdeps_netload_bytes |
|
||||
_glibtop_sysdeps_netload_packets;
|
||||
|
||||
@@ -106,78 +100,11 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int have_bytes, fields, skfd;
|
||||
int have_bytes, fields;
|
||||
FILE *f;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (skfd) {
|
||||
struct ifreq ifr;
|
||||
unsigned flags;
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
|
||||
flags = ifr.ifr_flags;
|
||||
} else
|
||||
flags = 0;
|
||||
|
||||
if (flags & IFF_UP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
|
||||
|
||||
if (flags & IFF_BROADCAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
|
||||
|
||||
if (flags & IFF_DEBUG)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
|
||||
|
||||
if (flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
|
||||
|
||||
if (flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
|
||||
|
||||
if (flags & IFF_RUNNING)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
|
||||
|
||||
if (flags & IFF_NOARP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
|
||||
|
||||
if (flags & IFF_PROMISC)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
|
||||
|
||||
if (flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
|
||||
|
||||
if (flags & IFF_MULTICAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->address = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->subnet = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
|
||||
buf->mtu = ifr.ifr_mtu;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
|
||||
}
|
||||
|
||||
close (skfd);
|
||||
}
|
||||
|
||||
/* Linux 2.1.114 - don't know where exactly this was added, but
|
||||
* recent kernels have byte count in /proc/net/dev so we don't
|
||||
* need IP accounting.
|
||||
|
@@ -9,8 +9,8 @@ libgtop_names_la_SOURCES = cpu.c mem.c swap.c uptime.c loadavg.c \
|
||||
proclist.c sysdeps.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c \
|
||||
prockernel.c procsegment.c fsusage.c \
|
||||
mountlist.c procargs.c procmap.c netload.c \
|
||||
interfaces.c ppp.c
|
||||
mountlist.c procargs.c procmap.c netinfo.c \
|
||||
netload.c interfaces.c ppp.c
|
||||
|
||||
libgtop_names_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
|
53
sysdeps/names/netinfo.c
Normal file
53
sysdeps/names/netinfo.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
LibGTop 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/netinfo.h>
|
||||
|
||||
const char *glibtop_names_netinfo[GLIBTOP_MAX_NETINFO] =
|
||||
{
|
||||
"if_flags", "mtu", "subnet", "address"
|
||||
};
|
||||
|
||||
const unsigned glibtop_types_netinfo[GLIBTOP_MAX_NETINFO] =
|
||||
{
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
|
||||
GLIBTOP_TYPE_ULONG
|
||||
};
|
||||
|
||||
const char *glibtop_labels_netinfo[GLIBTOP_MAX_NETINFO] =
|
||||
{
|
||||
N_ ("Interface Flags"),
|
||||
N_ ("MTU"),
|
||||
N_ ("Subnet"),
|
||||
N_ ("Address"),
|
||||
};
|
||||
|
||||
const char *glibtop_descriptions_netinfo[GLIBTOP_MAX_NETINFO] =
|
||||
{
|
||||
N_ ("Interface Flags"),
|
||||
N_ ("Maximum Transfer Unit"),
|
||||
N_ ("Subnet"),
|
||||
N_ ("Address"),
|
||||
};
|
@@ -27,9 +27,9 @@
|
||||
|
||||
const char *glibtop_names_netload[GLIBTOP_MAX_NETLOAD] =
|
||||
{
|
||||
"if_flags", "mtu", "subnet", "address", "packets_in",
|
||||
"packets_out", "packets_total", "bytes_in", "bytes_out",
|
||||
"bytes_total", "errors_in", "errors_out", "errors_total",
|
||||
"packets_in", "packets_out", "packets_total",
|
||||
"bytes_in", "bytes_out", "bytes_total",
|
||||
"errors_in", "errors_out", "errors_total",
|
||||
"collisions"
|
||||
};
|
||||
|
||||
@@ -38,16 +38,11 @@ const unsigned glibtop_types_netload[GLIBTOP_MAX_NETLOAD] =
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
|
||||
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG
|
||||
GLIBTOP_TYPE_ULONG
|
||||
};
|
||||
|
||||
const char *glibtop_labels_netload[GLIBTOP_MAX_NETLOAD] =
|
||||
{
|
||||
N_ ("Interface Flags"),
|
||||
N_ ("MTU"),
|
||||
N_ ("Subnet"),
|
||||
N_ ("Address"),
|
||||
N_ ("Packets In"),
|
||||
N_ ("Packets Out"),
|
||||
N_ ("Packets Total"),
|
||||
@@ -62,10 +57,6 @@ const char *glibtop_labels_netload[GLIBTOP_MAX_NETLOAD] =
|
||||
|
||||
const char *glibtop_descriptions_netload[GLIBTOP_MAX_NETLOAD] =
|
||||
{
|
||||
N_ ("Interface Flags"),
|
||||
N_ ("Maximum Transfer Unit"),
|
||||
N_ ("Subnet"),
|
||||
N_ ("Address"),
|
||||
N_ ("Packets In"),
|
||||
N_ ("Packets Out"),
|
||||
N_ ("Packets Total"),
|
||||
|
Reference in New Issue
Block a user