|
|
612949 |
diff -up net-tools-2.0/include/interface.h.stack net-tools-2.0/include/interface.h
|
|
|
612949 |
--- net-tools-2.0/include/interface.h.stack 2013-05-23 05:27:34.000000000 +0200
|
|
|
612949 |
+++ net-tools-2.0/include/interface.h 2013-06-07 11:58:25.474623871 +0200
|
|
|
612949 |
@@ -72,7 +72,7 @@ extern int do_if_print(struct interface
|
|
|
612949 |
|
|
|
612949 |
extern int procnetdev_version(char *buf);
|
|
|
612949 |
extern int get_dev_fields(char *bp, struct interface *ife);
|
|
|
612949 |
-extern char * get_name(char *name, char *p);
|
|
|
612949 |
+extern char * get_name(char **namep, char *p);
|
|
|
612949 |
|
|
|
612949 |
extern void ife_print(struct interface *ptr);
|
|
|
612949 |
|
|
|
612949 |
diff -up net-tools-2.0/lib/interface.c.stack net-tools-2.0/lib/interface.c
|
|
|
612949 |
--- net-tools-2.0/lib/interface.c.stack 2013-06-07 11:58:25.471623910 +0200
|
|
|
612949 |
+++ net-tools-2.0/lib/interface.c 2013-06-07 12:00:13.901191277 +0200
|
|
|
612949 |
@@ -214,10 +214,11 @@ out:
|
|
|
612949 |
return err;
|
|
|
612949 |
}
|
|
|
612949 |
|
|
|
612949 |
-char *get_name(char *name, char *p)
|
|
|
612949 |
+char *get_name(char **namep, char *p)
|
|
|
612949 |
{
|
|
|
612949 |
while (isspace(*p))
|
|
|
612949 |
p++;
|
|
|
612949 |
+ char *name = *namep = p;
|
|
|
612949 |
while (*p) {
|
|
|
612949 |
if (isspace(*p))
|
|
|
612949 |
break;
|
|
|
612949 |
@@ -320,9 +321,10 @@ int get_dev_fields(char *bp, struct inte
|
|
|
612949 |
static int if_readlist_proc(char *target)
|
|
|
612949 |
{
|
|
|
612949 |
FILE *fh;
|
|
|
612949 |
- char buf[512];
|
|
|
612949 |
struct interface *ife;
|
|
|
612949 |
int err;
|
|
|
612949 |
+ char *line = NULL;
|
|
|
612949 |
+ size_t linelen = 0;
|
|
|
612949 |
|
|
|
612949 |
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
612949 |
if (!fh) {
|
|
|
612949 |
@@ -330,10 +332,11 @@ static int if_readlist_proc(char *target
|
|
|
612949 |
_PATH_PROCNET_DEV, strerror(errno));
|
|
|
612949 |
return -2;
|
|
|
612949 |
}
|
|
|
612949 |
- if (fgets(buf, sizeof buf, fh))
|
|
|
612949 |
- /* eat line */;
|
|
|
612949 |
- if (fgets(buf, sizeof buf, fh))
|
|
|
612949 |
- /* eat line */;
|
|
|
612949 |
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
|
|
612949 |
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
|
|
612949 |
+ err = -1;
|
|
|
612949 |
+ goto out;
|
|
|
612949 |
+ }
|
|
|
612949 |
|
|
|
612949 |
#if 0 /* pretty, but can't cope with missing fields */
|
|
|
612949 |
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
|
|
|
612949 |
@@ -358,13 +361,13 @@ static int if_readlist_proc(char *target
|
|
|
612949 |
if (!fmt)
|
|
|
612949 |
return -1;
|
|
|
612949 |
#else
|
|
|
612949 |
- procnetdev_vsn = procnetdev_version(buf);
|
|
|
612949 |
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
612949 |
#endif
|
|
|
612949 |
|
|
|
612949 |
err = 0;
|
|
|
612949 |
- while (fgets(buf, sizeof buf, fh)) {
|
|
|
612949 |
- char *s, name[IFNAMSIZ];
|
|
|
612949 |
- s = get_name(name, buf);
|
|
|
612949 |
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
612949 |
+ char *s, *name;
|
|
|
612949 |
+ s = get_name(&name, line);
|
|
|
612949 |
ife = if_cache_add(name);
|
|
|
612949 |
get_dev_fields(s, ife);
|
|
|
612949 |
ife->statistics_valid = 1;
|
|
|
612949 |
@@ -379,6 +382,8 @@ static int if_readlist_proc(char *target
|
|
|
612949 |
#if 0
|
|
|
612949 |
free(fmt);
|
|
|
612949 |
#endif
|
|
|
612949 |
+ out:
|
|
|
612949 |
+ free(line);
|
|
|
612949 |
fclose(fh);
|
|
|
612949 |
return err;
|
|
|
612949 |
}
|
|
|
612949 |
@@ -386,24 +391,28 @@ static int if_readlist_proc(char *target
|
|
|
612949 |
static int if_readlist_rep(char *target, struct interface *ife)
|
|
|
612949 |
{
|
|
|
612949 |
FILE *fh;
|
|
|
612949 |
- char buf[512];
|
|
|
612949 |
int err;
|
|
|
612949 |
+ char *line = NULL;
|
|
|
612949 |
+ size_t linelen = 0;
|
|
|
612949 |
|
|
|
612949 |
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
612949 |
if (!fh) {
|
|
|
612949 |
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
|
|
612949 |
_PATH_PROCNET_DEV, strerror(errno));
|
|
|
612949 |
return if_readconf();
|
|
|
612949 |
- }
|
|
|
612949 |
- fgets(buf, sizeof buf, fh); /* eat line */
|
|
|
612949 |
- fgets(buf, sizeof buf, fh);
|
|
|
612949 |
+ }
|
|
|
612949 |
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
|
|
612949 |
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
|
|
612949 |
+ err = -1;
|
|
|
612949 |
+ goto out;
|
|
|
612949 |
+ }
|
|
|
612949 |
|
|
|
612949 |
- procnetdev_vsn = procnetdev_version(buf);
|
|
|
612949 |
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
612949 |
|
|
|
612949 |
err = 0;
|
|
|
612949 |
- while (fgets(buf, sizeof buf, fh)) {
|
|
|
612949 |
- char *s, name[IFNAMSIZ];
|
|
|
612949 |
- s = get_name(name, buf);
|
|
|
612949 |
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
612949 |
+ char *s, *name;
|
|
|
612949 |
+ s = get_name(&name, line);
|
|
|
612949 |
get_dev_fields(s, ife);
|
|
|
612949 |
if (target && !strcmp(target,name))
|
|
|
612949 |
{
|
|
|
612949 |
@@ -416,6 +425,8 @@ static int if_readlist_rep(char *target,
|
|
|
612949 |
err = -1;
|
|
|
612949 |
}
|
|
|
612949 |
|
|
|
612949 |
+ out:
|
|
|
612949 |
+ free(line);
|
|
|
612949 |
fclose(fh);
|
|
|
612949 |
return err;
|
|
|
612949 |
}
|