295 lines
7.9 KiB
Diff
295 lines
7.9 KiB
Diff
# net-tools-1.60-cont-buff.patch
|
|
# This Patch fixes the -ic option from netstat
|
|
# without destroying the proc_read buffer function
|
|
# if any questions occur contact my at fdg@suse.de
|
|
diff -uNr net-tools-1.60-unpatched/ifconfig.c net-tools-1.60/ifconfig.c
|
|
--- net-tools-1.60-unpatched/ifconfig.c 2001-04-13 20:25:18.000000000 +0200
|
|
+++ net-tools-1.60/ifconfig.c 2004-07-30 11:49:21.735995630 +0200
|
|
@@ -108,7 +108,7 @@
|
|
printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
|
|
|
if (!ifname) {
|
|
- res = for_all_interfaces(do_if_print, &opt_a);
|
|
+ res = for_all_interfaces(do_if_print, &opt_a, 0);
|
|
} else {
|
|
struct interface *ife;
|
|
|
|
@@ -1081,7 +1081,7 @@
|
|
pt.flag = flag;
|
|
memset(searcher, 0, sizeof(searcher));
|
|
i = for_all_interfaces((int (*)(struct interface *,void *))do_ifcmd,
|
|
- &pt);
|
|
+ &pt, 0);
|
|
if (i == -1)
|
|
return -1;
|
|
if (i == 1)
|
|
diff -uNr net-tools-1.60-unpatched/include/interface.h net-tools-1.60/include/interface.h
|
|
--- net-tools-1.60-unpatched/include/interface.h 2004-07-30 11:01:42.000000000 +0200
|
|
+++ net-tools-1.60/include/interface.h 2004-07-30 12:13:58.028172544 +0200
|
|
@@ -63,10 +63,10 @@
|
|
|
|
extern int if_fetch(struct interface *ife);
|
|
|
|
-extern int for_all_interfaces(int (*)(struct interface *, void *), void *);
|
|
+extern int for_all_interfaces(int (*)(struct interface *, void *), void *, int);
|
|
extern int free_interface_list(void);
|
|
extern struct interface *lookup_interface(char *name);
|
|
-extern int if_readlist(void);
|
|
+extern int if_readlist(int);
|
|
|
|
extern int do_if_fetch(struct interface *ife);
|
|
extern int do_if_print(struct interface *ife, void *cookie);
|
|
@@ -76,6 +76,8 @@
|
|
extern int ife_short;
|
|
|
|
extern const char *if_port_text[][4];
|
|
+extern int get_iface_count(void);
|
|
+char *get_iface_name(int index);
|
|
|
|
/* Defines for poor glibc2.0 users, the feature check is done at runtime */
|
|
#if !defined(SIOCSIFTXQLEN)
|
|
diff -uNr net-tools-1.60-unpatched/lib/interface.c net-tools-1.60/lib/interface.c
|
|
--- net-tools-1.60-unpatched/lib/interface.c 2004-07-30 11:01:42.000000000 +0200
|
|
+++ net-tools-1.60/lib/interface.c 2004-07-30 12:01:59.537031709 +0200
|
|
@@ -89,7 +89,7 @@
|
|
|
|
static struct interface *int_list, *int_last;
|
|
|
|
-static int if_readlist_proc(char *);
|
|
+static int if_readlist_proc(char *, int);
|
|
|
|
static struct interface *add_interface(char *name)
|
|
{
|
|
@@ -119,17 +119,17 @@
|
|
{
|
|
struct interface *ife = NULL;
|
|
|
|
- if (if_readlist_proc(name) < 0)
|
|
+ if (if_readlist_proc(name, 0) < 0)
|
|
return NULL;
|
|
ife = add_interface(name);
|
|
return ife;
|
|
}
|
|
|
|
-int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
|
|
+int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie, int flag_cacheof)
|
|
{
|
|
struct interface *ife;
|
|
|
|
- if (!int_list && (if_readlist() < 0))
|
|
+ if (!int_list && (if_readlist(flag_cacheof) < 0))
|
|
return -1;
|
|
for (ife = int_list; ife; ife = ife->next) {
|
|
int err = doit(ife, cookie);
|
|
@@ -145,6 +145,7 @@
|
|
while ((ife = int_list) != NULL) {
|
|
int_list = ife->next;
|
|
free(ife);
|
|
+ int_last = NULL;
|
|
}
|
|
return 0;
|
|
}
|
|
@@ -298,7 +299,7 @@
|
|
return 0;
|
|
}
|
|
|
|
-static int if_readlist_proc(char *target)
|
|
+static int if_readlist_proc(char *target, int flag_cacheof)
|
|
{
|
|
static int proc_read;
|
|
FILE *fh;
|
|
@@ -306,10 +307,12 @@
|
|
struct interface *ife;
|
|
int err;
|
|
|
|
- if (proc_read)
|
|
- return 0;
|
|
- if (!target)
|
|
- proc_read = 1;
|
|
+ if (proc_read) {
|
|
+ return 0;
|
|
+ }
|
|
+ if ((!target) && (flag_cacheof == 0)) {
|
|
+ proc_read = 1;
|
|
+ }
|
|
|
|
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
if (!fh) {
|
|
@@ -369,9 +372,9 @@
|
|
return err;
|
|
}
|
|
|
|
-int if_readlist(void)
|
|
+int if_readlist(int flag_cacheof)
|
|
{
|
|
- int err = if_readlist_proc(NULL);
|
|
+ int err = if_readlist_proc(NULL, flag_cacheof);
|
|
if (!err)
|
|
err = if_readconf();
|
|
return err;
|
|
@@ -891,3 +894,26 @@
|
|
else
|
|
ife_print_long(i);
|
|
}
|
|
+
|
|
+int get_iface_count(void)
|
|
+{
|
|
+ int num_iface = 0;
|
|
+ struct interface* ife = int_list;
|
|
+
|
|
+ for (; ife != NULL; ife=ife->next) {
|
|
+ num_iface++;
|
|
+ }
|
|
+
|
|
+ return num_iface;
|
|
+}
|
|
+
|
|
+char* get_iface_name(int index) {
|
|
+ struct interface* ife = int_list;
|
|
+
|
|
+ while ((index-- > 0) && (ife->next != NULL)) {
|
|
+ ife = ife->next;
|
|
+ }
|
|
+
|
|
+ return ife->name;
|
|
+}
|
|
+
|
|
diff -uNr net-tools-1.60-unpatched/netstat.c net-tools-1.60/netstat.c
|
|
--- net-tools-1.60-unpatched/netstat.c 2001-04-15 16:41:17.000000000 +0200
|
|
+++ net-tools-1.60/netstat.c 2004-07-30 11:43:43.415346672 +0200
|
|
@@ -149,9 +149,24 @@
|
|
int flag_prg = 0;
|
|
int flag_arg = 0;
|
|
int flag_ver = 0;
|
|
+int flag_cacheof = 0;
|
|
|
|
FILE *procinfo;
|
|
|
|
+struct iface_cache {
|
|
+ char iface_name[16+1];
|
|
+ int rxok;
|
|
+ int rxerr;
|
|
+ int rxdrp;
|
|
+ int rxovr;
|
|
+ int txok;
|
|
+ int txerr;
|
|
+ int txdrp;
|
|
+ int txovr;
|
|
+};
|
|
+
|
|
+static struct iface_cache* mycache;
|
|
+
|
|
#define INFO_GUTS1(file,name,proc) \
|
|
procinfo = fopen((file), "r"); \
|
|
if (procinfo == NULL) { \
|
|
@@ -249,6 +264,77 @@
|
|
/* NOT working as of glibc-2.0.7: */
|
|
#undef DIRENT_HAVE_D_TYPE_WORKS
|
|
|
|
+int do_if_cache_print(struct interface *ife, void *cookie)
|
|
+{
|
|
+ int *opt_a = (int *) cookie;
|
|
+ int res;
|
|
+ int num_iface = get_iface_count();
|
|
+ int i;
|
|
+
|
|
+ struct iface_cache* cur_iface_cache = NULL;
|
|
+
|
|
+ res = do_if_fetch(ife);
|
|
+
|
|
+ if (mycache == NULL) {
|
|
+ mycache = malloc(num_iface * sizeof(struct iface_cache));
|
|
+ if (mycache == NULL) { exit(-1); }
|
|
+ memset(mycache, '\0', num_iface * sizeof(struct iface_cache));
|
|
+ for (i=0; i < num_iface; i++) {
|
|
+ strncpy(mycache[i].iface_name, get_iface_name(i), 16);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ for (i=0; i < num_iface; i++) {
|
|
+ if (strcmp(ife->name, mycache[i].iface_name) == 0) {
|
|
+ cur_iface_cache = &mycache[i];
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (cur_iface_cache != NULL) {
|
|
+ int swap;
|
|
+
|
|
+ swap = ife->stats.rx_packets;
|
|
+ ife->stats.rx_packets -= cur_iface_cache->rxok;
|
|
+ cur_iface_cache->rxok = swap;
|
|
+
|
|
+ swap = ife->stats.rx_errors;
|
|
+ ife->stats.rx_errors -= cur_iface_cache->rxerr;
|
|
+ cur_iface_cache->rxerr = swap;
|
|
+
|
|
+ swap = ife->stats.rx_dropped;
|
|
+ ife->stats.rx_dropped -= cur_iface_cache->rxdrp;
|
|
+ cur_iface_cache->rxdrp = swap;
|
|
+
|
|
+ swap = ife->stats.rx_fifo_errors;
|
|
+ ife->stats.rx_fifo_errors -= cur_iface_cache->rxovr;
|
|
+ cur_iface_cache->rxovr = swap;
|
|
+
|
|
+ swap = ife->stats.tx_packets;
|
|
+ ife->stats.tx_packets -= cur_iface_cache->txok;
|
|
+ cur_iface_cache->txok = swap;
|
|
+
|
|
+ swap = ife->stats.tx_errors;
|
|
+ ife->stats.tx_errors -= cur_iface_cache->txerr;
|
|
+ cur_iface_cache->txerr = swap;
|
|
+
|
|
+ swap = ife->stats.tx_dropped;
|
|
+ ife->stats.tx_dropped -= cur_iface_cache->txdrp;
|
|
+ cur_iface_cache->txdrp = swap;
|
|
+
|
|
+ swap = ife->stats.tx_fifo_errors;
|
|
+ ife->stats.tx_fifo_errors -= cur_iface_cache->txovr;
|
|
+ cur_iface_cache->txovr = swap;
|
|
+ }
|
|
+
|
|
+ if (res >= 0) {
|
|
+ if ((ife->flags & IFF_UP) || *opt_a) {
|
|
+ ife_print(ife);
|
|
+ }
|
|
+ }
|
|
+ return res;
|
|
+}
|
|
+
|
|
static void prg_cache_add(int inode, char *name)
|
|
{
|
|
unsigned hi = PRG_HASHIT(inode);
|
|
@@ -1452,10 +1538,20 @@
|
|
printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
|
}
|
|
|
|
- if (for_all_interfaces(do_if_print, &flag_all) < 0) {
|
|
- perror(_("missing interface information"));
|
|
- exit(1);
|
|
+ if (flag_cacheof == 1) {
|
|
+ if (for_all_interfaces(do_if_cache_print, &flag_all, flag_cacheof) < 0) {
|
|
+ perror(_("missing interface information"));
|
|
+ exit(1);
|
|
+ }
|
|
+ }
|
|
+ else {
|
|
+ if (for_all_interfaces(do_if_print, &flag_all, flag_cacheof) < 0) {
|
|
+ perror(_("missing interface information"));
|
|
+ exit(1);
|
|
+ }
|
|
}
|
|
+
|
|
+
|
|
if (flag_cnt)
|
|
free_interface_list();
|
|
else {
|
|
@@ -1582,6 +1678,7 @@
|
|
flag_lst++;
|
|
break;
|
|
case 'c':
|
|
+ flag_cacheof = 1;
|
|
flag_cnt++;
|
|
break;
|
|
|