aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/netstat.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/networking/netstat.c b/networking/netstat.c
index 1c78f9d19..29c2384a4 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -148,7 +148,7 @@ static char *ip_port_str(struct sockaddr *addr, int port, const char *proto, int
148 return host_port; 148 return host_port;
149} 149}
150 150
151static void tcp_do_one(int lnr, char *line) 151static int tcp_do_one(int lnr, char *line)
152{ 152{
153 char local_addr[64], rem_addr[64]; 153 char local_addr[64], rem_addr[64];
154 char more[512]; 154 char more[512];
@@ -161,7 +161,7 @@ static void tcp_do_one(int lnr, char *line)
161 unsigned long rxq, txq, time_len, retr, inode; 161 unsigned long rxq, txq, time_len, retr, inode;
162 162
163 if (lnr == 0) 163 if (lnr == 0)
164 return; 164 return 0;
165 165
166 more[0] = '\0'; 166 more[0] = '\0';
167 num = sscanf(line, 167 num = sscanf(line,
@@ -171,8 +171,7 @@ static void tcp_do_one(int lnr, char *line)
171 &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); 171 &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
172 172
173 if (num < 10) { 173 if (num < 10) {
174 bb_error_msg("warning, got bogus tcp line"); 174 return 1; /* error */
175 return;
176 } 175 }
177 176
178 if (strlen(local_addr) > 8) { 177 if (strlen(local_addr) > 8) {
@@ -199,9 +198,10 @@ static void tcp_do_one(int lnr, char *line)
199 free(l); 198 free(l);
200 free(r); 199 free(r);
201 } 200 }
201 return 0;
202} 202}
203 203
204static void udp_do_one(int lnr, char *line) 204static int udp_do_one(int lnr, char *line)
205{ 205{
206 char local_addr[64], rem_addr[64]; 206 char local_addr[64], rem_addr[64];
207 const char *state_str; 207 const char *state_str;
@@ -215,7 +215,7 @@ static void udp_do_one(int lnr, char *line)
215 unsigned long rxq, txq, time_len, retr, inode; 215 unsigned long rxq, txq, time_len, retr, inode;
216 216
217 if (lnr == 0) 217 if (lnr == 0)
218 return; 218 return 0;
219 219
220 more[0] = '\0'; 220 more[0] = '\0';
221 num = sscanf(line, 221 num = sscanf(line,
@@ -236,8 +236,7 @@ static void udp_do_one(int lnr, char *line)
236 } 236 }
237 237
238 if (num < 10) { 238 if (num < 10) {
239 bb_error_msg("warning, got bogus udp line"); 239 return 1; /* error */
240 return;
241 } 240 }
242 switch (state) { 241 switch (state) {
243 case TCP_ESTABLISHED: 242 case TCP_ESTABLISHED:
@@ -281,9 +280,10 @@ static void udp_do_one(int lnr, char *line)
281 free(r); 280 free(r);
282 } 281 }
283 } 282 }
283 return 0;
284} 284}
285 285
286static void raw_do_one(int lnr, char *line) 286static int raw_do_one(int lnr, char *line)
287{ 287{
288 char local_addr[64], rem_addr[64]; 288 char local_addr[64], rem_addr[64];
289 char more[512]; 289 char more[512];
@@ -296,7 +296,7 @@ static void raw_do_one(int lnr, char *line)
296 unsigned long rxq, txq, time_len, retr, inode; 296 unsigned long rxq, txq, time_len, retr, inode;
297 297
298 if (lnr == 0) 298 if (lnr == 0)
299 return; 299 return 0;
300 300
301 more[0] = '\0'; 301 more[0] = '\0';
302 num = sscanf(line, 302 num = sscanf(line,
@@ -316,8 +316,7 @@ static void raw_do_one(int lnr, char *line)
316 } 316 }
317 317
318 if (num < 10) { 318 if (num < 10) {
319 bb_error_msg("warning, got bogus raw line"); 319 return 1; /* error */
320 return;
321 } 320 }
322 321
323 { 322 {
@@ -337,9 +336,10 @@ static void raw_do_one(int lnr, char *line)
337 free(r); 336 free(r);
338 } 337 }
339 } 338 }
339 return 0;
340} 340}
341 341
342static void unix_do_one(int nr, char *line) 342static int unix_do_one(int nr, char *line)
343{ 343{
344 unsigned long refcnt, proto, unix_flags; 344 unsigned long refcnt, proto, unix_flags;
345 unsigned long inode; 345 unsigned long inode;
@@ -352,7 +352,7 @@ static void unix_do_one(int nr, char *line)
352 /* TODO: currently we stop at first NUL byte. Is it a problem? */ 352 /* TODO: currently we stop at first NUL byte. Is it a problem? */
353 353
354 if (nr == 0) 354 if (nr == 0)
355 return; /* skip header */ 355 return 0; /* skip header */
356 356
357 *strchrnul(line, '\n') = '\0'; 357 *strchrnul(line, '\n') = '\0';
358 358
@@ -360,22 +360,21 @@ static void unix_do_one(int nr, char *line)
360 * Other users report long lines filled by NUL bytes. 360 * Other users report long lines filled by NUL bytes.
361 * (those ^@ are NUL bytes too). We see them as empty lines. */ 361 * (those ^@ are NUL bytes too). We see them as empty lines. */
362 if (!line[0]) 362 if (!line[0])
363 return; 363 return 0;
364 364
365 path_ofs = 0; /* paranoia */ 365 path_ofs = 0; /* paranoia */
366 num = sscanf(line, "%p: %lX %lX %lX %X %X %lu %n", 366 num = sscanf(line, "%p: %lX %lX %lX %X %X %lu %n",
367 &d, &refcnt, &proto, &unix_flags, &type, &state, &inode, &path_ofs); 367 &d, &refcnt, &proto, &unix_flags, &type, &state, &inode, &path_ofs);
368 if (num < 7) { 368 if (num < 7) {
369 bb_error_msg("got bogus unix line '%s'", line); 369 return 1; /* error */
370 return;
371 } 370 }
372 if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) != (NETSTAT_LISTENING|NETSTAT_CONNECTED)) { 371 if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) != (NETSTAT_LISTENING|NETSTAT_CONNECTED)) {
373 if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) { 372 if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) {
374 if (!(flags & NETSTAT_LISTENING)) 373 if (!(flags & NETSTAT_LISTENING))
375 return; 374 return 0;
376 } else { 375 } else {
377 if (!(flags & NETSTAT_CONNECTED)) 376 if (!(flags & NETSTAT_CONNECTED))
378 return; 377 return 0;
379 } 378 }
380 } 379 }
381 380
@@ -447,6 +446,7 @@ static void unix_do_one(int nr, char *line)
447 printf("%-5s %-6ld %-11s %-10s %-13s %6lu %s\n", 446 printf("%-5s %-6ld %-11s %-10s %-13s %6lu %s\n",
448 ss_proto, refcnt, ss_flags, ss_type, ss_state, inode, 447 ss_proto, refcnt, ss_flags, ss_type, ss_state, inode,
449 line + path_ofs); 448 line + path_ofs);
449 return 0;
450} 450}
451 451
452#define _PATH_PROCNET_UDP "/proc/net/udp" 452#define _PATH_PROCNET_UDP "/proc/net/udp"
@@ -457,7 +457,7 @@ static void unix_do_one(int nr, char *line)
457#define _PATH_PROCNET_RAW6 "/proc/net/raw6" 457#define _PATH_PROCNET_RAW6 "/proc/net/raw6"
458#define _PATH_PROCNET_UNIX "/proc/net/unix" 458#define _PATH_PROCNET_UNIX "/proc/net/unix"
459 459
460static void do_info(const char *file, const char *name, void (*proc)(int, char *)) 460static void do_info(const char *file, const char *name, int (*proc)(int, char *))
461{ 461{
462 int lnr; 462 int lnr;
463 FILE *procinfo; 463 FILE *procinfo;
@@ -468,14 +468,15 @@ static void do_info(const char *file, const char *name, void (*proc)(int, char *
468 if (errno != ENOENT) { 468 if (errno != ENOENT) {
469 bb_simple_perror_msg(file); 469 bb_simple_perror_msg(file);
470 } else { 470 } else {
471 bb_error_msg("no support for '%s' on this system", name); 471 bb_error_msg("no kernel support for %s", name);
472 } 472 }
473 return; 473 return;
474 } 474 }
475 lnr = 0; 475 lnr = 0;
476 /* Why? because xmalloc_fgets_str doesn't stop on NULs */ 476 /* Why? because xmalloc_fgets_str doesn't stop on NULs */
477 while ((buffer = xmalloc_fgets_str(procinfo, "\n")) != NULL) { 477 while ((buffer = xmalloc_fgets_str(procinfo, "\n")) != NULL) {
478 (proc)(lnr++, buffer); 478 if (proc(lnr++, buffer))
479 bb_error_msg("%s: bogus data on line %d", file, lnr);
479 free(buffer); 480 free(buffer);
480 } 481 }
481 fclose(procinfo); 482 fclose(procinfo);