]> git.ipfire.org Git - people/pmueller/ipfire-3.x.git/blob - net-tools/patches/007-net-tools-interface_stack.patch
net-tools: Update to 2.0 git-rev e5f1be13.
[people/pmueller/ipfire-3.x.git] / net-tools / patches / 007-net-tools-interface_stack.patch
1 diff -up net-tools-2.0/include/interface.h.stack net-tools-2.0/include/interface.h
2 diff -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:
6 return err;
7 }
8
9 -static const char *get_name(char *name, const char *p)
10 +static const char *get_name(char **namep, const char *p)
11 {
12 while (isspace(*p))
13 p++;
14 + char *name = *namep = p;
15 while (*p) {
16 if (isspace(*p))
17 break;
18 @@ -320,9 +321,10 @@ static int get_dev_fields(const char *bp
19 static int if_readlist_proc(const char *target)
20 {
21 FILE *fh;
22 - char buf[512];
23 struct interface *ife;
24 int err;
25 + char *line = NULL;
26 + size_t linelen = 0;
27
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 */;
38 + if (getline(&line, &linelen, fh) == -1 /* eat line */
39 + || getline(&line, &linelen, fh) == -1) { /* eat line */
40 + err = -1;
41 + goto out;
42 + }
43
44 #if 0 /* pretty, but can't cope with missing fields */
45 fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
46 @@ -358,14 +361,14 @@ static int if_readlist_proc(const char *
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)) {
56 + while (getline(&line, &linelen, fh) != -1) {
57 const char *s;
58 - char name[IFNAMSIZ];
59 - s = get_name(name, buf);
60 + char *name;
61 + s = get_name(&name, line);
62 ife = if_cache_add(name);
63 get_dev_fields(s, ife);
64 ife->statistics_valid = 1;
65 @@ -380,6 +383,8 @@ static int if_readlist_proc(const char *
66 #if 0
67 free(fmt);
68 #endif
69 + out:
70 + free(line);
71 fclose(fh);
72 return err;
73 }
74 @@ -387,24 +392,28 @@ static int if_readlist_proc(const char *
75 static int if_readlist_rep(const char *target, struct interface *ife)
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) {
85 fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
86 _PATH_PROCNET_DEV, strerror(errno));
87 return if_readconf();
88 - }
89 - fgets(buf, sizeof buf, fh); /* eat line */
90 - fgets(buf, sizeof buf, fh);
91 + }
92 + if (getline(&line, &linelen, fh) == -1 /* eat line */
93 + || getline(&line, &linelen, fh) == -1) { /* eat line */
94 + err = -1;
95 + goto out;
96 + }
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 {
111 @@ -417,6 +426,8 @@ static int if_readlist_rep(const char *t
112 err = -1;
113 }
114
115 + out:
116 + free(line);
117 fclose(fh);
118 return err;
119 }