You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.6 KiB
130 lines
3.6 KiB
6 years ago
|
diff -up net-tools-2.0/include/interface.h.stack net-tools-2.0/include/interface.h
|
||
|
--- net-tools-2.0/include/interface.h.stack 2013-05-23 05:27:34.000000000 +0200
|
||
|
+++ net-tools-2.0/include/interface.h 2013-06-07 11:58:25.474623871 +0200
|
||
|
@@ -72,7 +72,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-2.0/lib/interface.c.stack net-tools-2.0/lib/interface.c
|
||
|
--- net-tools-2.0/lib/interface.c.stack 2013-06-07 11:58:25.471623910 +0200
|
||
|
+++ net-tools-2.0/lib/interface.c 2013-06-07 12:00:13.901191277 +0200
|
||
|
@@ -214,10 +214,11 @@ out:
|
||
|
return err;
|
||
|
}
|
||
|
|
||
|
-char *get_name(char *name, char *p)
|
||
|
+char *get_name(char **namep, char *p)
|
||
|
{
|
||
|
while (isspace(*p))
|
||
|
p++;
|
||
|
+ char *name = *namep = p;
|
||
|
while (*p) {
|
||
|
if (isspace(*p))
|
||
|
break;
|
||
|
@@ -320,9 +321,10 @@ int get_dev_fields(char *bp, struct inte
|
||
|
static int if_readlist_proc(char *target)
|
||
|
{
|
||
|
FILE *fh;
|
||
|
- char buf[512];
|
||
|
struct interface *ife;
|
||
|
int err;
|
||
|
+ char *line = NULL;
|
||
|
+ size_t linelen = 0;
|
||
|
|
||
|
fh = fopen(_PATH_PROCNET_DEV, "r");
|
||
|
if (!fh) {
|
||
|
@@ -330,10 +332,11 @@ static int if_readlist_proc(char *target
|
||
|
_PATH_PROCNET_DEV, strerror(errno));
|
||
|
return -2;
|
||
|
}
|
||
|
- if (fgets(buf, sizeof buf, fh))
|
||
|
- /* eat line */;
|
||
|
- if (fgets(buf, sizeof buf, fh))
|
||
|
- /* eat line */;
|
||
|
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
||
|
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
||
|
+ err = -1;
|
||
|
+ goto out;
|
||
|
+ }
|
||
|
|
||
|
#if 0 /* pretty, but can't cope with missing fields */
|
||
|
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
|
||
|
@@ -358,13 +361,13 @@ static int if_readlist_proc(char *target
|
||
|
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);
|
||
|
ife = if_cache_add(name);
|
||
|
get_dev_fields(s, ife);
|
||
|
ife->statistics_valid = 1;
|
||
|
@@ -379,6 +382,8 @@ static int if_readlist_proc(char *target
|
||
|
#if 0
|
||
|
free(fmt);
|
||
|
#endif
|
||
|
+ out:
|
||
|
+ free(line);
|
||
|
fclose(fh);
|
||
|
return err;
|
||
|
}
|
||
|
@@ -386,24 +391,28 @@ static int if_readlist_proc(char *target
|
||
|
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) {
|
||
|
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
||
|
_PATH_PROCNET_DEV, strerror(errno));
|
||
|
return if_readconf();
|
||
|
- }
|
||
|
- fgets(buf, sizeof buf, fh); /* eat line */
|
||
|
- fgets(buf, sizeof buf, fh);
|
||
|
+ }
|
||
|
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
||
|
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
||
|
+ err = -1;
|
||
|
+ goto out;
|
||
|
+ }
|
||
|
|
||
|
- 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))
|
||
|
{
|
||
|
@@ -416,6 +425,8 @@ static int if_readlist_rep(char *target,
|
||
|
err = -1;
|
||
|
}
|
||
|
|
||
|
+ out:
|
||
|
+ free(line);
|
||
|
fclose(fh);
|
||
|
return err;
|
||
|
}
|