From b746f488b028dc9002140b7cd31b70a56b9fe367 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Sun, 21 Nov 1999 18:35:40 +0000 Subject: [PATCH] Added new feature to get a list of network interface names. 1999-11-21 Martin Baulig Added new feature to get a list of network interface names. * features.def: Added `interface_names' feature. * include/glibtop/interfaces.h: New file. * include/glibtop/sysdeps.h (GLIBTOP_SYSDEPS_INTERFACE_NAMES): Added. (glibtop_sysdeps): Added `interface_names'. * include/glibtop/union.h (glibtop_union): Added `interface_names'. * include/glibtop/command.h (GLIBTOP_CMND_INTERFACE_NAMES): Added. --- ChangeLog | 13 +++++ RELNOTES-1.1.x | 4 ++ features.def | 1 + include/glibtop/command.h | 5 +- include/glibtop/interfaces.h | 102 +++++++++++++++++++++++++++++++++++ include/glibtop/netload.h | 6 ++- include/glibtop/sysdeps.h | 6 ++- include/glibtop/union.h | 2 + lib/lib.pl | 42 ++++++++++----- src/daemon/server.c | 1 + sysdeps/names/Makefile.am | 2 +- sysdeps/names/interfaces.c | 48 +++++++++++++++++ sysdeps/names/sysdeps.c | 8 ++- 13 files changed, 217 insertions(+), 23 deletions(-) create mode 100644 include/glibtop/interfaces.h create mode 100644 sysdeps/names/interfaces.c diff --git a/ChangeLog b/ChangeLog index d4f4ad1b..345caea1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +1999-11-21 Martin Baulig + + Added new feature to get a list of network interface names. + + * features.def: Added `interface_names' feature. + + * include/glibtop/interfaces.h: New file. + + * include/glibtop/sysdeps.h (GLIBTOP_SYSDEPS_INTERFACE_NAMES): Added. + (glibtop_sysdeps): Added `interface_names'. + * include/glibtop/union.h (glibtop_union): Added `interface_names'. + * include/glibtop/command.h (GLIBTOP_CMND_INTERFACE_NAMES): Added. + 1999-11-21 Martin Baulig * include/glibtop/sysdeps.h (glibtop_init_func_t): Use `int' diff --git a/RELNOTES-1.1.x b/RELNOTES-1.1.x index e962b0e7..4fb1aeb7 100644 --- a/RELNOTES-1.1.x +++ b/RELNOTES-1.1.x @@ -11,6 +11,10 @@ Please use LibGTop 1.0.x if you're not on a Solaris system IMPORTANT CHANGES SINCE 1.0: ---------------------------- +* All `glibtop_get__* ()' and all `glibtop_init__* ()' + functions now have an `int' return value and return 0 on success and -1 + on failure. + * glibtop_cpu: Added `xcpu_flags' * glibtop_proc_state: Changed `state' from char to unsigned and added diff --git a/features.def b/features.def index f9b55bae..11b00ba3 100644 --- a/features.def +++ b/features.def @@ -19,4 +19,5 @@ 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,strategy) retval|ppp|ulong(state,bytes_in,bytes_out)|ushort(device) diff --git a/include/glibtop/command.h b/include/glibtop/command.h index d3941439..f4ad5e63 100644 --- a/include/glibtop/command.h +++ b/include/glibtop/command.h @@ -58,9 +58,10 @@ BEGIN_LIBGTOP_DECLS #define GLIBTOP_CMND_MOUNTLIST 20 #define GLIBTOP_CMND_FSUSAGE 21 #define GLIBTOP_CMND_NETLOAD 22 -#define GLIBTOP_CMND_PPP 23 +#define GLIBTOP_CMND_INTERFACE_NAMES 23 +#define GLIBTOP_CMND_PPP 24 -#define GLIBTOP_MAX_CMND 24 +#define GLIBTOP_MAX_CMND 25 #define _GLIBTOP_PARAM_SIZE 16 diff --git a/include/glibtop/interfaces.h b/include/glibtop/interfaces.h new file mode 100644 index 00000000..70876918 --- /dev/null +++ b/include/glibtop/interfaces.h @@ -0,0 +1,102 @@ +/* -*- 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 , 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_INTERFACES_H__ +#define __GLIBTOP_INTERFACES_H__ + +#include +#include + +BEGIN_LIBGTOP_DECLS + +#define GLIBTOP_INTERFACE_NAMES_NUMBER 0 +#define GLIBTOP_INTERFACE_NAMES_SIZE 1 + +#define GLIBTOP_MAX_INTERFACE_NAMES 2 + +typedef struct _glibtop_interface_names glibtop_interface_names; + +typedef enum _glibtop_protocol glibtop_protocol; +typedef enum _glibtop_interface glibtop_interface; + +enum _glibtop_protocol { + GLIBTOP_NETLOAD_DEFAULT = 0, + GLIBTOP_NETLOAD_IPV4, + GLIBTOP_NETLOAD_IPV6, + GLIBTOP_NETLOAD_IPX, +}; + +enum _glibtop_interface { + GLIBTOP_INTERFACE_ALL = 0, + GLIBTOP_INTERFACE_ETHERNET, + GLIBTOP_INTERFACE_LOOPBACK, + GLIBTOP_INTERFACE_DUMMY, + GLIBTOP_INTERFACE_PPP, +}; + +enum { + GLIBTOP_INTERFACES_ALL = 0, + GLIBTOP_INTERFACES_BEST_MATCHING, +}; + +struct _glibtop_interface_names +{ + u_int64_t flags, + number, /* GLIBTOP_INTERFACES_NUMBER */ + size; /* GLIBTOP_INTERFACES_SIZE */ +}; + +#define glibtop_get_interface_names(buf, interface,number,strategy) glibtop_get_interface_names_l(glibtop_global_server, buf, interface, number, strategy) + +#if GLIBTOP_SUID_INTERFACE_NAMES +#define glibtop_get_interface_names_r glibtop_get_interface_names_p +#else +#define glibtop_get_interface_names_r glibtop_get_interface_names_s +#endif + +char *glibtop_get_interface_names_l (glibtop *server, glibtop_interface_names *buf, unsigned interface, unsigned number, unsigned strategy); + +#if GLIBTOP_SUID_INTERFACES +int glibtop_init_interface_names_p (glibtop *server); +char *glibtop_get_interface_names_p (glibtop *server, glibtop_interface_names *buf, unsigned interface, unsigned number, unsigned strategy); +#else +int glibtop_init_interface_names_s (glibtop *server); +char *glibtop_get_interface_names_s (glibtop *server, glibtop_interface_names *buf, unsigned interface, unsigned number, unsigned strategy); +#endif + +#ifdef GLIBTOP_NAMES + +/* You need to link with -lgtop_names to get this stuff here. */ + +extern const char *glibtop_names_interface_names []; +extern const unsigned glibtop_types_interface_names []; +extern const char *glibtop_labels_interface_names []; +extern const char *glibtop_descriptions_interface_names []; + +#endif + +END_LIBGTOP_DECLS + +#endif diff --git a/include/glibtop/netload.h b/include/glibtop/netload.h index f4df5ba4..8eb8dcc9 100644 --- a/include/glibtop/netload.h +++ b/include/glibtop/netload.h @@ -50,6 +50,8 @@ BEGIN_LIBGTOP_DECLS typedef struct _glibtop_netload glibtop_netload; +#include + enum { GLIBTOP_IF_FLAGS_UP = 1, GLIBTOP_IF_FLAGS_BROADCAST, @@ -91,9 +93,9 @@ struct _glibtop_netload #define glibtop_get_netload(netload,interface) glibtop_get_netload_l(glibtop_global_server, netload, interface) #if GLIBTOP_SUID_NETLOAD -#define glibtop_get_netload_r glibtop_get_netload_p +#define glibtop_get_netload_r glibtop_get_netload_p #else -#define glibtop_get_netload_r glibtop_get_netload_s +#define glibtop_get_netload_r glibtop_get_netload_s #endif int glibtop_get_netload_l (glibtop *server, glibtop_netload *buf, const char *interface); diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h index baa353e3..b737fad9 100644 --- a/include/glibtop/sysdeps.h +++ b/include/glibtop/sysdeps.h @@ -51,9 +51,10 @@ BEGIN_LIBGTOP_DECLS #define GLIBTOP_SYSDEPS_MOUNTLIST 18 #define GLIBTOP_SYSDEPS_FSUSAGE 19 #define GLIBTOP_SYSDEPS_NETLOAD 20 -#define GLIBTOP_SYSDEPS_PPP 21 +#define GLIBTOP_SYSDEPS_INTERFACE_NAMES 21 +#define GLIBTOP_SYSDEPS_PPP 22 -#define GLIBTOP_MAX_SYSDEPS 24 +#define GLIBTOP_MAX_SYSDEPS 25 #define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1) @@ -89,6 +90,7 @@ struct _glibtop_sysdeps mountlist, /* glibtop_mountlist */ fsusage, /* glibtop_fsusage */ netload, /* glibtop_netload */ + interface_names, /* glibtop_interface_names */ ppp; /* glibtop_ppp */ }; diff --git a/include/glibtop/union.h b/include/glibtop/union.h index aac6b518..7446c2ff 100644 --- a/include/glibtop/union.h +++ b/include/glibtop/union.h @@ -50,6 +50,7 @@ #include #include +#include #include BEGIN_LIBGTOP_DECLS @@ -79,6 +80,7 @@ union _glibtop_union glibtop_mountlist mountlist; glibtop_fsusage fsusage; glibtop_netload netload; + glibtop_interface_names interface_names; glibtop_ppp ppp; }; diff --git a/lib/lib.pl b/lib/lib.pl index 18776f94..9e2cef8c 100755 --- a/lib/lib.pl +++ b/lib/lib.pl @@ -71,6 +71,7 @@ $convert{'int'} = 'int'; $convert{'retval'} = 'int'; $convert{'ushort'} = 'unsigned short'; $convert{'unsigned'} = 'unsigned'; +$convert{'string'} = 'const char *'; while (<>) { chop; # strip record separator @@ -176,9 +177,12 @@ sub output { } } - print 'glibtop_get_' . $feature . '_l (glibtop *server, glibtop_' . - - $feature . ' *buf' . $param_decl . ')'; + if ($line_fields[3] eq '') { + print 'glibtop_get_' . $feature . '_l (glibtop *server' . $param_decl . ')'; + } else { + print 'glibtop_get_' . $feature . '_l (glibtop *server, glibtop_' . + $feature . ' *buf' . $param_decl . ')'; + } print '{' . $send_ptr . '' . $send_size; if ($retval !~ /^void$/) { @@ -205,9 +209,12 @@ sub output { &toupper($feature) . ','; print "\t\t\t\t" . $call_prefix_space . 'send_size, send_ptr,'; - print "\t\t\t\t" . $call_prefix_space . 'sizeof (glibtop_' . $feature . - - '), buf,'; + if ($line_fields[3] eq '') { + print "\t\t\t\t". $call_prefix_space . "0, NULL,"; + } else { + print "\t\t\t\t" . $call_prefix_space . 'sizeof (glibtop_' . $feature . + '), buf,'; + } print "\t\t\t\t" . $call_prefix_space . $retval_param . ');'; print "\t} else {"; @@ -215,9 +222,14 @@ sub output { if ($orig !~ /^@/) { print '#if (!GLIBTOP_SUID_' . &toupper($feature) . ')'; } - print "\t\t" . $prefix . 'glibtop_get_' . $feature . '_s (server, buf' . - $call_param . ');'; + if ($line_fields[3] eq '') { + print "\t\t" . $prefix . 'glibtop_get_' . $feature . '_s (server' . + $call_param . ');'; + } else { + print "\t\t" . $prefix . 'glibtop_get_' . $feature . '_s (server, buf' . + $call_param . ');'; + } if ($orig !~ /^@/) { print '#else'; @@ -230,15 +242,17 @@ sub output { print "\t}"; - print ''; - print "\t/* Make sure that all required fields are present. */"; print ''; - print "\tif (buf->flags & server->required." . $feature . ')'; - print "\t\t_glibtop_missing_feature (server, \"" . $feature . + if (!($line_fields[3] eq '')) { + print "\t/* Make sure that all required fields are present. */"; + print ''; - "\", buf->flags,"; - print "\t\t\t\t\t &server->required." . $feature . ');'; + print "\tif (buf->flags & server->required." . $feature . ')'; + print "\t\t_glibtop_missing_feature (server, \"" . $feature . + "\", buf->flags,"; + print "\t\t\t\t\t &server->required." . $feature . ');'; + } if ($retval !~ /^void$/) { print "\n\t/* Now we can return. */"; diff --git a/src/daemon/server.c b/src/daemon/server.c index a4e18476..43127042 100644 --- a/src/daemon/server.c +++ b/src/daemon/server.c @@ -52,6 +52,7 @@ GLIBTOP_SUID_PROC_SEGMENT + GLIBTOP_SUID_PROC_ARGS + GLIBTOP_SUID_PROC_MAP + GLIBTOP_SUID_NETLOAD + +GLIBTOP_SUID_INTERFACE_NAMES + GLIBTOP_SUID_PPP; #include diff --git a/sysdeps/names/Makefile.am b/sysdeps/names/Makefile.am index b8b04ed6..c260abc2 100644 --- a/sysdeps/names/Makefile.am +++ b/sysdeps/names/Makefile.am @@ -10,7 +10,7 @@ libgtop_names_la_SOURCES = cpu.c mem.c swap.c uptime.c loadavg.c \ proctime.c procmem.c procsignal.c \ prockernel.c procsegment.c fsusage.c \ mountlist.c procargs.c procmap.c netload.c \ - ppp.c + interfaces.c ppp.c libgtop_names_la_LDFLAGS = $(LT_VERSION_INFO) diff --git a/sysdeps/names/interfaces.c b/sysdeps/names/interfaces.c new file mode 100644 index 00000000..91b30e82 --- /dev/null +++ b/sysdeps/names/interfaces.c @@ -0,0 +1,48 @@ +/* -*- 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 , 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 + +const char *glibtop_names_interface_names[GLIBTOP_MAX_INTERFACE_NAMES] = +{ + "number", "size" +}; + +const unsigned glibtop_types_interface_names[GLIBTOP_MAX_INTERFACE_NAMES] = +{ + GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG +}; + +const char *glibtop_labels_interface_names[GLIBTOP_MAX_INTERFACE_NAMES] = +{ + N_ ("Number"), + N_ ("Size") +}; + +const char *glibtop_descriptions_interface_names[GLIBTOP_MAX_INTERFACE_NAMES] = +{ + N_ ("Number"), + N_ ("Size") +}; diff --git a/sysdeps/names/sysdeps.c b/sysdeps/names/sysdeps.c index 65209a71..647e57c0 100644 --- a/sysdeps/names/sysdeps.c +++ b/sysdeps/names/sysdeps.c @@ -31,7 +31,8 @@ const char *glibtop_names_sysdeps[GLIBTOP_MAX_SYSDEPS] = "loadavg", "shm_limits", "msg_limits", "sem_limits", "proclist", "proc_state", "proc_uid", "proc_mem", "proc_time", "proc_signal", "proc_kernel", "proc_segment", "proc_args", - "proc_map", "mountlist", "fsusage", "netload", "ppp" + "proc_map", "mountlist", "fsusage", "netload", "interface_names", + "ppp" }; const unsigned glibtop_types_sysdeps[GLIBTOP_MAX_SYSDEPS] = @@ -43,7 +44,8 @@ const unsigned glibtop_types_sysdeps[GLIBTOP_MAX_SYSDEPS] = 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, + GLIBTOP_TYPE_ULONG }; const char *glibtop_labels_sysdeps[GLIBTOP_MAX_SYSDEPS] = @@ -71,6 +73,7 @@ const char *glibtop_labels_sysdeps[GLIBTOP_MAX_SYSDEPS] = N_ ("Mount List"), N_ ("File System Usage"), N_ ("Network Load"), + N_ ("Interface Names"), N_ ("PPP Statistics") }; @@ -99,5 +102,6 @@ const char *glibtop_descriptions_sysdeps[GLIBTOP_MAX_SYSDEPS] = N_ ("List of currently mounted filesystems"), N_ ("File System Usage"), N_ ("Network Load"), + N_ ("Interface Names"), N_ ("PPP Statistics") };