]>
Commit | Line | Data |
---|---|---|
44f64d91 SS |
1 | diff -up net-tools-2.0/lib/interface.c.cycle net-tools-2.0/lib/interface.c |
2 | --- net-tools-2.0/lib/interface.c.cycle 2014-11-11 14:38:03.000000000 +0100 | |
3 | +++ net-tools-2.0/lib/interface.c 2014-11-24 14:45:46.128480980 +0100 | |
4 | @@ -93,6 +93,7 @@ int if_list_all = 0; /* do we have reque | |
5 | static struct interface *int_list, *int_last; | |
6 | ||
7 | static int if_readlist_proc(const char *); | |
8 | +static int if_readlist_rep(const char *, struct interface *); | |
9 | ||
10 | static struct interface *if_cache_add(const char *name) | |
11 | { | |
12 | @@ -138,11 +139,14 @@ struct interface *lookup_interface(const | |
13 | int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie) | |
14 | { | |
15 | struct interface *ife; | |
16 | + int err; | |
17 | ||
18 | if (!if_list_all && (if_readlist() < 0)) | |
19 | return -1; | |
20 | for (ife = int_list; ife; ife = ife->next) { | |
21 | - int err = doit(ife, cookie); | |
22 | + if_readlist_rep(ife->name, ife); | |
23 | + err = doit(ife, cookie); | |
24 | + | |
25 | if (err) | |
26 | return err; | |
27 | } | |
28 | @@ -379,6 +383,41 @@ static int if_readlist_proc(const char * | |
29 | fclose(fh); | |
30 | return err; | |
31 | } | |
32 | + | |
33 | +static int if_readlist_rep(const char *target, struct interface *ife) | |
34 | +{ | |
35 | + FILE *fh; | |
36 | + char buf[512]; | |
37 | + int err; | |
38 | + | |
39 | + fh = fopen(_PATH_PROCNET_DEV, "r"); | |
40 | + if (!fh) { | |
41 | + fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"), | |
42 | + _PATH_PROCNET_DEV, strerror(errno)); | |
43 | + return if_readconf(); | |
44 | + } | |
45 | + fgets(buf, sizeof buf, fh); /* eat line */ | |
46 | + fgets(buf, sizeof buf, fh); | |
47 | + | |
48 | + procnetdev_vsn = procnetdev_version(buf); | |
49 | + | |
50 | + err = 0; | |
51 | + while (fgets(buf, sizeof buf, fh)) { | |
52 | + char *s, name[IFNAMSIZ]; | |
53 | + s = get_name(name, buf); | |
54 | + get_dev_fields(s, ife); | |
55 | + ife->statistics_valid = 1; | |
56 | + if (target && !strcmp(target,name)) | |
57 | + break; | |
58 | + } | |
59 | + if (ferror(fh)) { | |
60 | + perror(_PATH_PROCNET_DEV); | |
61 | + err = -1; | |
62 | + } | |
63 | + | |
64 | + fclose(fh); | |
65 | + return err; | |
66 | +} | |
67 | ||
68 | int if_readlist(void) | |
69 | { | |
70 | diff -up net-tools-2.0/man/en_US/netstat.8.cycle net-tools-2.0/man/en_US/netstat.8 | |
71 | --- net-tools-2.0/man/en_US/netstat.8.cycle 2014-11-11 14:38:03.000000000 +0100 | |
72 | +++ net-tools-2.0/man/en_US/netstat.8 2014-11-24 14:47:36.140944944 +0100 | |
73 | @@ -36,6 +36,7 @@ netstat \- Print network connections, ro | |
74 | .RB [ \-\-verbose | \-v ] | |
75 | .RB [ \-\-continuous | \-c] | |
76 | .RB [ \-\-wide | \-W ] | |
77 | +.RB [delay] | |
78 | .P | |
79 | .B netstat | |
80 | .RB { \-\-route | \-r } | |
81 | @@ -45,6 +46,7 @@ netstat \- Print network connections, ro | |
82 | .RB [ \-\-numeric | \-n ] | |
83 | .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] | |
84 | .RB [ \-\-continuous | \-c ] | |
85 | +.RB [delay] | |
86 | .P | |
87 | .B netstat | |
88 | .RB { \-\-interfaces | \-i } | |
89 | @@ -55,12 +57,14 @@ netstat \- Print network connections, ro | |
90 | .RB [ \-\-numeric | \-n ] | |
91 | .RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ] | |
92 | .RB [ \-\-continuous | \-c ] | |
93 | +.RB [delay] | |
94 | .P | |
95 | .B netstat | |
96 | .RB { \-\-groups | \-g } | |
97 | .RB [ \-\-numeric | \-n ] | |
98 | .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] | |
99 | .RB [ \-\-continuous | \-c ] | |
100 | +.RB [delay] | |
101 | .P | |
102 | .B netstat | |
103 | .RB { \-\-masquerade | \-M } | |
104 | @@ -68,6 +72,7 @@ netstat \- Print network connections, ro | |
105 | .RB [ \-\-numeric | \-n ] | |
106 | .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] | |
107 | .RB [ \-\-continuous | \-c ] | |
108 | +.RB [delay] | |
109 | .P | |
110 | .B netstat | |
111 | .RB { \-\-statistics | -s } | |
112 | @@ -76,6 +81,7 @@ netstat \- Print network connections, ro | |
113 | .RB [ \-\-udplite | \-U ] | |
114 | .RB [ \-\-sctp | \-S ] | |
115 | .RB [ \-\-raw | \-w ] | |
116 | +.RB [delay] | |
117 | .P | |
118 | .B netstat | |
119 | .RB { \-\-version | \-V } | |
120 | @@ -208,6 +214,10 @@ option, show interfaces that are not up | |
121 | Print routing information from the FIB. (This is the default.) | |
122 | .SS "\-C" | |
123 | Print routing information from the route cache. | |
124 | +.SS delay | |
125 | +Netstat will cycle printing through statistics every | |
126 | +.B delay | |
127 | +seconds. | |
128 | .P | |
129 | .SH OUTPUT | |
130 | .P | |
131 | diff -up net-tools-2.0/netstat.c.cycle net-tools-2.0/netstat.c | |
132 | --- net-tools-2.0/netstat.c.cycle 2014-11-11 14:38:03.000000000 +0100 | |
133 | +++ net-tools-2.0/netstat.c 2014-11-24 14:44:24.948614445 +0100 | |
134 | @@ -115,9 +115,9 @@ | |
135 | #endif | |
136 | ||
137 | /* prototypes for statistics.c */ | |
138 | -void parsesnmp(int, int, int); | |
139 | +int parsesnmp(int, int, int); | |
140 | void inittab(void); | |
141 | -void parsesnmp6(int, int, int); | |
142 | +int parsesnmp6(int, int, int); | |
143 | void inittab6(void); | |
144 | ||
145 | typedef enum { | |
146 | @@ -342,10 +342,10 @@ static void prg_cache_clear(void) | |
147 | prg_cache_loaded = 0; | |
148 | } | |
149 | ||
150 | -static void wait_continous(void) | |
151 | +static void wait_continous(int reptimer) | |
152 | { | |
153 | fflush(stdout); | |
154 | - sleep(1); | |
155 | + sleep(reptimer); | |
156 | } | |
157 | ||
158 | static int extract_type_1_socket_inode(const char lname[], unsigned long * inode_p) { | |
159 | @@ -1787,6 +1787,8 @@ static int rfcomm_info(void) | |
160 | ||
161 | static int iface_info(void) | |
162 | { | |
163 | + static int count=0; | |
164 | + | |
165 | if (skfd < 0) { | |
166 | if ((skfd = sockets_open(0)) < 0) { | |
167 | perror("socket"); | |
168 | @@ -1796,20 +1798,21 @@ static int iface_info(void) | |
169 | } | |
170 | if (flag_exp < 2) { | |
171 | ife_short = 1; | |
172 | - printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); | |
173 | + if(!(count % 8)) | |
174 | + printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); | |
175 | } | |
176 | ||
177 | if (for_all_interfaces(do_if_print, &flag_all) < 0) { | |
178 | perror(_("missing interface information")); | |
179 | exit(1); | |
180 | } | |
181 | - if (flag_cnt) | |
182 | + if (!flag_cnt) { | |
183 | if_cache_free(); | |
184 | - else { | |
185 | close(skfd); | |
186 | skfd = -1; | |
187 | } | |
188 | ||
189 | + count++; | |
190 | return 0; | |
191 | } | |
192 | ||
193 | @@ -1825,7 +1828,7 @@ static void usage(void) | |
194 | { | |
195 | fprintf(stderr, _("usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}\n")); | |
196 | fprintf(stderr, _(" netstat [-vWnNcaeol] [<Socket> ...]\n")); | |
197 | - fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n")); | |
198 | + fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n")); | |
199 | ||
200 | fprintf(stderr, _(" -r, --route display routing table\n")); | |
201 | fprintf(stderr, _(" -i, --interfaces display interface table\n")); | |
202 | @@ -1867,6 +1870,7 @@ int main | |
203 | (int argc, char *argv[]) { | |
204 | int i; | |
205 | int lop; | |
206 | + int reptimer = 1; | |
207 | static struct option longopts[] = | |
208 | { | |
209 | AFTRANS_OPTS, | |
210 | @@ -2049,6 +2053,12 @@ int main | |
211 | flag_sta++; | |
212 | } | |
213 | ||
214 | + if(argc == optind + 1) { | |
215 | + if((reptimer = atoi(argv[optind])) <= 0) | |
216 | + usage(); | |
217 | + flag_cnt++; | |
218 | + } | |
219 | + | |
220 | if (flag_int + flag_rou + flag_mas + flag_sta > 1) | |
221 | usage(); | |
222 | ||
223 | @@ -2078,7 +2088,7 @@ int main | |
224 | flag_not & FLAG_NUM_PORT, flag_exp); | |
225 | if (i || !flag_cnt) | |
226 | break; | |
227 | - wait_continous(); | |
228 | + wait_continous(reptimer); | |
229 | } | |
230 | #else | |
231 | ENOSUPP("netstat", "FW_MASQUERADE"); | |
232 | @@ -2091,17 +2101,18 @@ int main | |
233 | if (!afname[0]) | |
234 | safe_strncpy(afname, DFLT_AF, sizeof(afname)); | |
235 | ||
236 | + for (;;) { | |
237 | if (!strcmp(afname, "inet")) { | |
238 | #if HAVE_AFINET | |
239 | inittab(); | |
240 | - parsesnmp(flag_raw, flag_tcp, flag_udp); | |
241 | + i = parsesnmp(flag_raw, flag_tcp, flag_udp); | |
242 | #else | |
243 | ENOSUPP("netstat", "AF INET"); | |
244 | #endif | |
245 | } else if(!strcmp(afname, "inet6")) { | |
246 | #if HAVE_AFINET6 | |
247 | inittab6(); | |
248 | - parsesnmp6(flag_raw, flag_tcp, flag_udp); | |
249 | + i = parsesnmp6(flag_raw, flag_tcp, flag_udp); | |
250 | #else | |
251 | ENOSUPP("netstat", "AF INET6"); | |
252 | #endif | |
253 | @@ -2109,7 +2120,11 @@ int main | |
254 | printf(_("netstat: No statistics support for specified address family: %s\n"), afname); | |
255 | exit(1); | |
256 | } | |
257 | - exit(0); | |
258 | + if(i || !flag_cnt) | |
259 | + break; | |
260 | + sleep(reptimer); | |
261 | + } | |
262 | + return (i); | |
263 | } | |
264 | ||
265 | if (flag_rou) { | |
266 | @@ -2131,7 +2146,7 @@ int main | |
267 | i = route_info(afname, options); | |
268 | if (i || !flag_cnt) | |
269 | break; | |
270 | - wait_continous(); | |
271 | + wait_continous(reptimer); | |
272 | } | |
273 | return (i); | |
274 | } | |
275 | @@ -2140,7 +2155,7 @@ int main | |
276 | i = iface_info(); | |
277 | if (!flag_cnt || i) | |
278 | break; | |
279 | - wait_continous(); | |
280 | + wait_continous(reptimer); | |
281 | } | |
282 | return (i); | |
283 | } | |
284 | @@ -2327,7 +2342,7 @@ int main | |
285 | ||
286 | if (!flag_cnt || i) | |
287 | break; | |
288 | - wait_continous(); | |
289 | + wait_continous(reptimer); | |
290 | prg_cache_clear(); | |
291 | } | |
292 | return (i); | |
293 | diff -up net-tools-2.0/statistics.c.cycle net-tools-2.0/statistics.c | |
294 | --- net-tools-2.0/statistics.c.cycle 2014-11-11 14:38:03.000000000 +0100 | |
295 | +++ net-tools-2.0/statistics.c 2014-11-24 14:44:24.949614431 +0100 | |
296 | @@ -502,7 +502,7 @@ void process6_fd(FILE *f) | |
297 | ||
298 | } | |
299 | ||
300 | -void parsesnmp(int flag_raw, int flag_tcp, int flag_udp) | |
301 | +int parsesnmp(int flag_raw, int flag_tcp, int flag_udp) | |
302 | { | |
303 | FILE *f; | |
304 | ||
305 | @@ -511,14 +511,17 @@ void parsesnmp(int flag_raw, int flag_tc | |
306 | f = proc_fopen("/proc/net/snmp"); | |
307 | if (!f) { | |
308 | perror(_("cannot open /proc/net/snmp")); | |
309 | - return; | |
310 | + return(1); | |
311 | } | |
312 | ||
313 | if (process_fd(f, 1, NULL) < 0) | |
314 | fprintf(stderr, _("Problem while parsing /proc/net/snmp\n")); | |
315 | ||
316 | - if (ferror(f)) | |
317 | + if (ferror(f)) { | |
318 | perror("/proc/net/snmp"); | |
319 | + fclose(f); | |
320 | + return(1); | |
321 | + } | |
322 | ||
323 | fclose(f); | |
324 | ||
325 | @@ -528,15 +531,18 @@ void parsesnmp(int flag_raw, int flag_tc | |
326 | if (process_fd(f, 1, NULL) <0) | |
327 | fprintf(stderr, _("Problem while parsing /proc/net/netstat\n")); | |
328 | ||
329 | - if (ferror(f)) | |
330 | - perror("/proc/net/netstat"); | |
331 | + if (ferror(f)) { | |
332 | + perror("/proc/net/netstat"); | |
333 | + fclose(f); | |
334 | + return(1); | |
335 | + } | |
336 | ||
337 | fclose(f); | |
338 | } | |
339 | - return; | |
340 | + return(0); | |
341 | } | |
342 | ||
343 | -void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp) | |
344 | +int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp) | |
345 | { | |
346 | FILE *f; | |
347 | ||
348 | @@ -545,7 +551,7 @@ void parsesnmp6(int flag_raw, int flag_t | |
349 | f = fopen("/proc/net/snmp6", "r"); | |
350 | if (!f) { | |
351 | perror(_("cannot open /proc/net/snmp6")); | |
352 | - return; | |
353 | + return(1); | |
354 | } | |
355 | process6_fd(f); | |
356 | if (ferror(f)) | |
357 | @@ -555,13 +561,16 @@ void parsesnmp6(int flag_raw, int flag_t | |
358 | f = fopen("/proc/net/snmp", "r"); | |
359 | if (!f) { | |
360 | perror(_("cannot open /proc/net/snmp")); | |
361 | - return; | |
362 | + return(1); | |
363 | } | |
364 | process_fd(f, 0, "Tcp"); | |
365 | - if (ferror(f)) | |
366 | + if (ferror(f)) { | |
367 | perror("/proc/net/snmp"); | |
368 | + return(1); | |
369 | + } | |
370 | ||
371 | fclose(f); | |
372 | + return(0); | |
373 | } | |
374 | ||
375 | void inittab(void) |