2011-12-06 18:15:09 +00:00
|
|
|
diff -up net-tools-1.60/include/interface.h.stack net-tools-1.60/include/interface.h
|
2012-01-05 12:41:31 +00:00
|
|
|
--- net-tools-1.60/include/interface.h.stack 2012-01-05 12:22:43.000000000 +0100
|
|
|
|
+++ net-tools-1.60/include/interface.h 2012-01-05 13:00:10.564699085 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -73,7 +73,7 @@ extern int do_if_print(struct interface
|
|
|
|
|
|
|
|
extern int procnetdev_version(char *buf);
|
|
|
|
extern int get_dev_fields(char *bp, struct interface *ife);
|
|
|
|
-extern char * get_name(char *name, char *p);
|
|
|
|
+extern char * get_name(char **namep, char *p);
|
|
|
|
|
|
|
|
extern void ife_print(struct interface *ptr);
|
|
|
|
|
|
|
|
diff -up net-tools-1.60/lib/interface.c.stack net-tools-1.60/lib/interface.c
|
2012-01-05 12:41:31 +00:00
|
|
|
--- net-tools-1.60/lib/interface.c.stack 2012-01-05 13:00:10.561699123 +0100
|
|
|
|
+++ net-tools-1.60/lib/interface.c 2012-01-05 13:03:19.522336790 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -214,10 +214,11 @@ out:
|
2006-01-02 10:00:42 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
-char *get_name(char *name, char *p)
|
|
|
|
+char *get_name(char **namep, char *p)
|
2006-01-02 10:00:42 +00:00
|
|
|
{
|
|
|
|
while (isspace(*p))
|
|
|
|
p++;
|
|
|
|
+ char *name = *namep = p;
|
|
|
|
while (*p) {
|
|
|
|
if (isspace(*p))
|
|
|
|
break;
|
2012-01-05 12:41:31 +00:00
|
|
|
@@ -320,20 +321,22 @@ int get_dev_fields(char *bp, struct inte
|
2011-12-06 18:15:09 +00:00
|
|
|
static int if_readlist_proc(char *target)
|
2006-01-02 10:00:42 +00:00
|
|
|
{
|
|
|
|
FILE *fh;
|
|
|
|
- char buf[512];
|
|
|
|
struct interface *ife;
|
|
|
|
int err;
|
|
|
|
+ char *line = NULL;
|
|
|
|
+ size_t linelen = 0;
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
|
if (!fh) {
|
2012-01-05 12:41:31 +00:00
|
|
|
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
2006-01-02 10:00:42 +00:00
|
|
|
_PATH_PROCNET_DEV, strerror(errno));
|
2011-12-06 18:15:09 +00:00
|
|
|
return -2;
|
2012-01-05 12:41:31 +00:00
|
|
|
- }
|
|
|
|
- if (fgets(buf, sizeof buf, fh))
|
|
|
|
- /* eat line */;
|
|
|
|
- if (fgets(buf, sizeof buf, fh))
|
|
|
|
- /* eat line */;
|
|
|
|
+ }
|
2006-01-02 10:00:42 +00:00
|
|
|
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
2012-01-05 12:41:31 +00:00
|
|
|
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
2006-01-02 10:00:42 +00:00
|
|
|
+ err = -1;
|
|
|
|
+ goto out;
|
2012-01-05 12:41:31 +00:00
|
|
|
+ }
|
2006-01-02 10:00:42 +00:00
|
|
|
|
|
|
|
#if 0 /* pretty, but can't cope with missing fields */
|
|
|
|
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
|
2012-01-05 12:41:31 +00:00
|
|
|
@@ -358,13 +361,13 @@ static int if_readlist_proc(char *target
|
2006-01-02 10:00:42 +00:00
|
|
|
if (!fmt)
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
- procnetdev_vsn = procnetdev_version(buf);
|
|
|
|
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
- while (fgets(buf, sizeof buf, fh)) {
|
|
|
|
- char *s, name[IFNAMSIZ];
|
|
|
|
- s = get_name(name, buf);
|
|
|
|
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
|
+ char *s, *name;
|
|
|
|
+ s = get_name(&name, line);
|
2011-12-06 18:15:09 +00:00
|
|
|
ife = if_cache_add(name);
|
2006-01-02 10:00:42 +00:00
|
|
|
get_dev_fields(s, ife);
|
|
|
|
ife->statistics_valid = 1;
|
2012-01-05 12:41:31 +00:00
|
|
|
@@ -379,6 +382,8 @@ static int if_readlist_proc(char *target
|
2006-01-02 10:00:42 +00:00
|
|
|
#if 0
|
|
|
|
free(fmt);
|
|
|
|
#endif
|
|
|
|
+ out:
|
|
|
|
+ free(line);
|
|
|
|
fclose(fh);
|
|
|
|
return err;
|
|
|
|
}
|
2012-01-05 12:41:31 +00:00
|
|
|
@@ -386,24 +391,28 @@ static int if_readlist_proc(char *target
|
2006-01-02 10:00:42 +00:00
|
|
|
static int if_readlist_rep(char *target, struct interface *ife)
|
|
|
|
{
|
|
|
|
FILE *fh;
|
|
|
|
- char buf[512];
|
|
|
|
int err;
|
|
|
|
+ char *line = NULL;
|
|
|
|
+ size_t linelen = 0;
|
|
|
|
|
|
|
|
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
|
if (!fh) {
|
2012-01-05 12:41:31 +00:00
|
|
|
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
2006-01-02 10:00:42 +00:00
|
|
|
_PATH_PROCNET_DEV, strerror(errno));
|
|
|
|
return if_readconf();
|
2012-01-05 12:41:31 +00:00
|
|
|
- }
|
2006-01-02 10:00:42 +00:00
|
|
|
- fgets(buf, sizeof buf, fh); /* eat line */
|
|
|
|
- fgets(buf, sizeof buf, fh);
|
2012-01-05 12:41:31 +00:00
|
|
|
+ }
|
2006-01-02 10:00:42 +00:00
|
|
|
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
2012-01-05 12:41:31 +00:00
|
|
|
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
2006-01-02 10:00:42 +00:00
|
|
|
+ err = -1;
|
|
|
|
+ goto out;
|
2012-01-05 12:41:31 +00:00
|
|
|
+ }
|
2006-01-02 10:00:42 +00:00
|
|
|
|
|
|
|
- procnetdev_vsn = procnetdev_version(buf);
|
|
|
|
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
- while (fgets(buf, sizeof buf, fh)) {
|
|
|
|
- char *s, name[IFNAMSIZ];
|
|
|
|
- s = get_name(name, buf);
|
|
|
|
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
|
+ char *s, *name;
|
|
|
|
+ s = get_name(&name, line);
|
|
|
|
get_dev_fields(s, ife);
|
|
|
|
if (target && !strcmp(target,name))
|
|
|
|
{
|
2012-01-05 12:41:31 +00:00
|
|
|
@@ -416,6 +425,8 @@ static int if_readlist_rep(char *target,
|
2006-01-02 10:00:42 +00:00
|
|
|
err = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ out:
|
|
|
|
+ free(line);
|
|
|
|
fclose(fh);
|
|
|
|
return err;
|
|
|
|
}
|