New file.
1999-12-12 Martin Baulig <martin@home-of-linux.org> * netinfo.c: New file. * interfaces.c: Reflect latest interface changes. * netload.c: Likewise.
This commit is contained in:
committed by
Martin Baulig
parent
881c2a2086
commit
1a25c3ade9
@@ -1,3 +1,10 @@
|
|||||||
|
1999-12-12 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
|
* netinfo.c: New file.
|
||||||
|
|
||||||
|
* interfaces.c: Reflect latest interface changes.
|
||||||
|
* netload.c: Likewise.
|
||||||
|
|
||||||
1999-10-24 Martin Baulig <martin@home-of-linux.org>
|
1999-10-24 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
* glibtop_machine.h: Make inclusion of <osreldate.h> conditional
|
* glibtop_machine.h: Make inclusion of <osreldate.h> conditional
|
||||||
|
@@ -13,7 +13,7 @@ libgtop_sysdeps_suid_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
|
|||||||
sem_limits.c proclist.c procstate.c procuid.c \
|
sem_limits.c proclist.c procstate.c procuid.c \
|
||||||
proctime.c procmem.c procsignal.c prockernel.c \
|
proctime.c procmem.c procsignal.c prockernel.c \
|
||||||
procsegment.c procargs.c procmap.c netload.c \
|
procsegment.c procargs.c procmap.c netload.c \
|
||||||
interfaces.c ppp.c
|
netinfo.c interfaces.c ppp.c
|
||||||
|
|
||||||
libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||||
|
|
||||||
|
@@ -45,6 +45,7 @@ BEGIN_LIBGTOP_DECLS
|
|||||||
#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
|
#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
|
||||||
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
|
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
|
||||||
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
|
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
|
||||||
|
#define GLIBTOP_SUID_NETINFO (1 << GLIBTOP_SYSDEPS_NETINFO)
|
||||||
#define GLIBTOP_SUID_INTERFACE_NAMES (1 << GLIBTOP_SYSDEPS_INTERFACE_NAMES)
|
#define GLIBTOP_SUID_INTERFACE_NAMES (1 << GLIBTOP_SYSDEPS_INTERFACE_NAMES)
|
||||||
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
|
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
|
||||||
|
|
||||||
|
@@ -26,8 +26,8 @@
|
|||||||
#include <glibtop/interfaces.h>
|
#include <glibtop/interfaces.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_interface_names =
|
static const unsigned long _glibtop_sysdeps_interface_names =
|
||||||
(1L << GLIBTOP_INTERFACE_NAMES_NUMBER) +
|
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE) +
|
||||||
(1L << GLIBTOP_INTERFACE_NAMES_SIZE);
|
(1L << GLIBTOP_ARRAY_TOTAL);
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
|
|
||||||
@@ -41,14 +41,14 @@ glibtop_init_interface_names_p (glibtop *server)
|
|||||||
|
|
||||||
/* Provides network statistics. */
|
/* Provides network statistics. */
|
||||||
|
|
||||||
char *
|
glibtop_interface *
|
||||||
glibtop_get_interface_names_p (glibtop *server, glibtop_interface_names *buf,
|
glibtop_get_interface_names_p (glibtop *server, glibtop_array *array,
|
||||||
unsigned interface, unsigned number,
|
u_int64_t interface, u_int64_t number,
|
||||||
unsigned instance, unsigned strategy)
|
u_int64_t instance, u_int64_t strategy)
|
||||||
{
|
{
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_INTERFACE_NAMES, 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_INTERFACE_NAMES), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_interface_names));
|
memset (array, 0, sizeof (glibtop_array));
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
195
sysdeps/freebsd/netinfo.c
Normal file
195
sysdeps/freebsd/netinfo.c
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
/* $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 <glibtop_suid.h>
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <net/if_dl.h>
|
||||||
|
#include <net/if_types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_NET_IF_VAR_H
|
||||||
|
#include <net/if_var.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/in_var.h>
|
||||||
|
|
||||||
|
static const unsigned long _glibtop_sysdeps_netinfo =
|
||||||
|
(1L << GLIBTOP_NETINFO_IF_FLAGS) +
|
||||||
|
(1L << GLIBTOP_NETINFO_MTU) +
|
||||||
|
(1L << GLIBTOP_NETINFO_SUBNET) +
|
||||||
|
(1L << GLIBTOP_NETINFO_ADDRESS);
|
||||||
|
|
||||||
|
/* nlist structure for kernel access */
|
||||||
|
static struct nlist nlst [] = {
|
||||||
|
{ "_ifnet" },
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Init function. */
|
||||||
|
|
||||||
|
int
|
||||||
|
glibtop_init_netinfo_p (glibtop *server)
|
||||||
|
{
|
||||||
|
server->sysdeps.netinfo = _glibtop_sysdeps_netinfo;
|
||||||
|
|
||||||
|
if (kvm_nlist (server->machine.kd, nlst) != 0)
|
||||||
|
glibtop_error_io_r (server, "kvm_nlist");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Provides Network statistics. */
|
||||||
|
|
||||||
|
int
|
||||||
|
glibtop_get_netinfo_p (glibtop *server, glibtop_netinfo *buf,
|
||||||
|
const char *interface, unsigned transport)
|
||||||
|
{
|
||||||
|
struct ifnet ifnet;
|
||||||
|
u_long ifnetaddr, ifnetfound, ifaddraddr;
|
||||||
|
struct sockaddr *sa;
|
||||||
|
char tname [16];
|
||||||
|
|
||||||
|
union {
|
||||||
|
struct ifaddr ifa;
|
||||||
|
struct in_ifaddr in;
|
||||||
|
} ifaddr;
|
||||||
|
|
||||||
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETINFO), 0);
|
||||||
|
|
||||||
|
memset (buf, 0, sizeof (glibtop_netinfo));
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||||
|
&ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
|
||||||
|
glibtop_error_io_r (server, "kvm_read (ifnet)");
|
||||||
|
|
||||||
|
ifaddraddr = 0;
|
||||||
|
while (ifnetaddr || ifaddraddr) {
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
register char *cp;
|
||||||
|
|
||||||
|
if (ifaddraddr == 0) {
|
||||||
|
ifnetfound = ifnetaddr;
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
|
||||||
|
sizeof (ifnet)) != sizeof (ifnet))
|
||||||
|
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
|
if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
|
||||||
|
tname, 16) != 16)
|
||||||
|
glibtop_error_io_r (server, "kvm_read (if_name)");
|
||||||
|
#else
|
||||||
|
strncpy (tname, ifnet.if_xname, 16);
|
||||||
|
tname [15] = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
|
||||||
|
ifaddraddr = (u_long) ifnet.if_addrhead.tqh_first;
|
||||||
|
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
|
ifaddraddr = (u_long) ifnet.if_addrlist;
|
||||||
|
#else
|
||||||
|
ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ifaddraddr) {
|
||||||
|
if ((kvm_read (server->machine.kd, ifaddraddr, &ifaddr,
|
||||||
|
sizeof (ifaddr)) != sizeof (ifaddr)))
|
||||||
|
glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
|
||||||
|
|
||||||
|
#define CP(x) ((char *)(x))
|
||||||
|
cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
|
||||||
|
CP(&ifaddr); sa = (struct sockaddr *)cp;
|
||||||
|
|
||||||
|
if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
|
||||||
|
sin = (struct sockaddr_in *)sa;
|
||||||
|
|
||||||
|
if (ifnet.if_flags & IFF_UP)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
|
||||||
|
if (ifnet.if_flags & IFF_BROADCAST)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
|
||||||
|
if (ifnet.if_flags & IFF_DEBUG)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
|
||||||
|
if (ifnet.if_flags & IFF_LOOPBACK)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
|
||||||
|
if (ifnet.if_flags & IFF_POINTOPOINT)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
|
||||||
|
if (ifnet.if_flags & IFF_RUNNING)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
|
||||||
|
if (ifnet.if_flags & IFF_NOARP)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
|
||||||
|
if (ifnet.if_flags & IFF_PROMISC)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
|
||||||
|
if (ifnet.if_flags & IFF_ALLMULTI)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
|
||||||
|
if (ifnet.if_flags & IFF_OACTIVE)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
|
||||||
|
if (ifnet.if_flags & IFF_SIMPLEX)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
|
||||||
|
if (ifnet.if_flags & IFF_LINK0)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
|
||||||
|
if (ifnet.if_flags & IFF_LINK1)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
|
||||||
|
if (ifnet.if_flags & IFF_LINK2)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
if (ifnet.if_flags & IFF_ALTPHYS)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
|
||||||
|
#endif
|
||||||
|
if (ifnet.if_flags & IFF_MULTICAST)
|
||||||
|
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
|
||||||
|
|
||||||
|
buf->subnet = htonl (ifaddr.in.ia_subnet);
|
||||||
|
buf->address = sin->sin_addr.s_addr;
|
||||||
|
|
||||||
|
buf->mtu = ifnet.if_mtu;
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_netinfo;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
|
||||||
|
ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
|
||||||
|
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
|
ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
|
||||||
|
#else
|
||||||
|
ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
|
||||||
|
ifnetaddr = (u_long) ifnet.if_link.tqe_next;
|
||||||
|
#elif defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
|
ifnetaddr = (u_long) ifnet.if_next;
|
||||||
|
#else
|
||||||
|
ifnetaddr = (u_long) ifnet.if_list.tqe_next;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -39,10 +39,6 @@
|
|||||||
#include <netinet/in_var.h>
|
#include <netinet/in_var.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_netload =
|
static const unsigned long _glibtop_sysdeps_netload =
|
||||||
(1L << GLIBTOP_NETLOAD_IF_FLAGS) +
|
|
||||||
(1L << GLIBTOP_NETLOAD_MTU) +
|
|
||||||
(1L << GLIBTOP_NETLOAD_SUBNET) +
|
|
||||||
(1L << GLIBTOP_NETLOAD_ADDRESS) +
|
|
||||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||||
@@ -77,7 +73,8 @@ glibtop_init_netload_p (glibtop *server)
|
|||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||||
const char *interface)
|
const char *interface, unsigned transport,
|
||||||
|
unsigned protocol)
|
||||||
{
|
{
|
||||||
struct ifnet ifnet;
|
struct ifnet ifnet;
|
||||||
u_long ifnetaddr, ifnetfound, ifaddraddr;
|
u_long ifnetaddr, ifnetfound, ifaddraddr;
|
||||||
@@ -139,46 +136,6 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
|||||||
if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
|
if (!strcmp (interface, tname) && (sa->sa_family == AF_INET)) {
|
||||||
sin = (struct sockaddr_in *)sa;
|
sin = (struct sockaddr_in *)sa;
|
||||||
|
|
||||||
if (ifnet.if_flags & IFF_UP)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
|
|
||||||
if (ifnet.if_flags & IFF_BROADCAST)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
|
|
||||||
if (ifnet.if_flags & IFF_DEBUG)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
|
|
||||||
if (ifnet.if_flags & IFF_LOOPBACK)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
|
|
||||||
if (ifnet.if_flags & IFF_POINTOPOINT)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
|
|
||||||
if (ifnet.if_flags & IFF_RUNNING)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
|
|
||||||
if (ifnet.if_flags & IFF_NOARP)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
|
|
||||||
if (ifnet.if_flags & IFF_PROMISC)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
|
|
||||||
if (ifnet.if_flags & IFF_ALLMULTI)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
|
|
||||||
if (ifnet.if_flags & IFF_OACTIVE)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
|
|
||||||
if (ifnet.if_flags & IFF_SIMPLEX)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
|
|
||||||
if (ifnet.if_flags & IFF_LINK0)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
|
|
||||||
if (ifnet.if_flags & IFF_LINK1)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
|
|
||||||
if (ifnet.if_flags & IFF_LINK2)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
|
|
||||||
#ifdef __FreeBSD__
|
|
||||||
if (ifnet.if_flags & IFF_ALTPHYS)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
|
|
||||||
#endif
|
|
||||||
if (ifnet.if_flags & IFF_MULTICAST)
|
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
|
|
||||||
|
|
||||||
buf->subnet = htonl (ifaddr.in.ia_subnet);
|
|
||||||
buf->address = sin->sin_addr.s_addr;
|
|
||||||
|
|
||||||
buf->mtu = ifnet.if_mtu;
|
|
||||||
|
|
||||||
buf->packets_in = ifnet.if_ipackets;
|
buf->packets_in = ifnet.if_ipackets;
|
||||||
buf->packets_out = ifnet.if_opackets;
|
buf->packets_out = ifnet.if_opackets;
|
||||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||||
|
Reference in New Issue
Block a user