]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blame - net-tools/patches/007-net-tools-interface_stack.patch
net-tools: Update to 2.0 git-rev e5f1be13.
[people/amarx/ipfire-3.x.git] / net-tools / patches / 007-net-tools-interface_stack.patch
CommitLineData
44f64d91
SS
1diff -up net-tools-2.0/include/interface.h.stack net-tools-2.0/include/interface.h
2diff -up net-tools-2.0/lib/interface.c.stack net-tools-2.0/lib/interface.c
3--- net-tools-2.0/lib/interface.c.stack 2014-11-24 14:54:32.293134466 +0100
4+++ net-tools-2.0/lib/interface.c 2014-11-24 15:07:58.434764441 +0100
5@@ -214,10 +214,11 @@ out:
236898d6
MT
6 return err;
7 }
8
44f64d91
SS
9-static const char *get_name(char *name, const char *p)
10+static const char *get_name(char **namep, const char *p)
236898d6
MT
11 {
12 while (isspace(*p))
13 p++;
14+ char *name = *namep = p;
15 while (*p) {
16 if (isspace(*p))
17 break;
44f64d91
SS
18@@ -320,9 +321,10 @@ static int get_dev_fields(const char *bp
19 static int if_readlist_proc(const char *target)
236898d6 20 {
236898d6
MT
21 FILE *fh;
22- char buf[512];
23 struct interface *ife;
24 int err;
25+ char *line = NULL;
44f64d91 26+ size_t linelen = 0;
236898d6 27
44f64d91
SS
28 fh = fopen(_PATH_PROCNET_DEV, "r");
29 if (!fh) {
30@@ -330,10 +332,11 @@ static int if_readlist_proc(const char *
31 _PATH_PROCNET_DEV, strerror(errno));
32 return -2;
33 }
34- if (fgets(buf, sizeof buf, fh))
35- /* eat line */;
36- if (fgets(buf, sizeof buf, fh))
37- /* eat line */;
236898d6 38+ if (getline(&line, &linelen, fh) == -1 /* eat line */
44f64d91 39+ || getline(&line, &linelen, fh) == -1) { /* eat line */
236898d6
MT
40+ err = -1;
41+ goto out;
44f64d91 42+ }
236898d6
MT
43
44 #if 0 /* pretty, but can't cope with missing fields */
45 fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
44f64d91 46@@ -358,14 +361,14 @@ static int if_readlist_proc(const char *
236898d6
MT
47 if (!fmt)
48 return -1;
49 #else
50- procnetdev_vsn = procnetdev_version(buf);
51+ procnetdev_vsn = procnetdev_version(line);
52 #endif
53
54 err = 0;
55- while (fgets(buf, sizeof buf, fh)) {
236898d6 56+ while (getline(&line, &linelen, fh) != -1) {
44f64d91
SS
57 const char *s;
58- char name[IFNAMSIZ];
59- s = get_name(name, buf);
60+ char *name;
236898d6 61+ s = get_name(&name, line);
44f64d91 62 ife = if_cache_add(name);
236898d6
MT
63 get_dev_fields(s, ife);
64 ife->statistics_valid = 1;
44f64d91 65@@ -380,6 +383,8 @@ static int if_readlist_proc(const char *
236898d6
MT
66 #if 0
67 free(fmt);
68 #endif
69+ out:
70+ free(line);
71 fclose(fh);
72 return err;
73 }
44f64d91
SS
74@@ -387,24 +392,28 @@ static int if_readlist_proc(const char *
75 static int if_readlist_rep(const char *target, struct interface *ife)
236898d6
MT
76 {
77 FILE *fh;
78- char buf[512];
79 int err;
80+ char *line = NULL;
81+ size_t linelen = 0;
82
83 fh = fopen(_PATH_PROCNET_DEV, "r");
84 if (!fh) {
44f64d91 85 fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
236898d6
MT
86 _PATH_PROCNET_DEV, strerror(errno));
87 return if_readconf();
44f64d91 88- }
236898d6
MT
89- fgets(buf, sizeof buf, fh); /* eat line */
90- fgets(buf, sizeof buf, fh);
44f64d91 91+ }
236898d6 92+ if (getline(&line, &linelen, fh) == -1 /* eat line */
44f64d91 93+ || getline(&line, &linelen, fh) == -1) { /* eat line */
236898d6
MT
94+ err = -1;
95+ goto out;
44f64d91 96+ }
236898d6
MT
97
98- procnetdev_vsn = procnetdev_version(buf);
99+ procnetdev_vsn = procnetdev_version(line);
100
101 err = 0;
102- while (fgets(buf, sizeof buf, fh)) {
103- char *s, name[IFNAMSIZ];
104- s = get_name(name, buf);
105+ while (getline(&line, &linelen, fh) != -1) {
106+ char *s, *name;
107+ s = get_name(&name, line);
108 get_dev_fields(s, ife);
109 if (target && !strcmp(target,name))
110 {
44f64d91 111@@ -417,6 +426,8 @@ static int if_readlist_rep(const char *t
236898d6
MT
112 err = -1;
113 }
114
115+ out:
116+ free(line);
117 fclose(fh);
118 return err;
119 }