File ifdata.c changed (mode: 100644) (index 92b68a6..c9a4622) |
... |
... |
struct if_stat *get_stats(char *iface) { |
275 |
275 |
int state=START; |
int state=START; |
276 |
276 |
int len; |
int len; |
277 |
277 |
struct if_stat *res=malloc(sizeof(struct if_stat)); |
struct if_stat *res=malloc(sizeof(struct if_stat)); |
|
278 |
|
|
|
279 |
|
if (!res) { |
|
280 |
|
perror("malloc"); |
|
281 |
|
return NULL; |
|
282 |
|
} |
|
283 |
|
|
278 |
284 |
fd=open("/proc/net/dev",O_RDONLY); |
fd=open("/proc/net/dev",O_RDONLY); |
279 |
285 |
if (fd==-1) { |
if (fd==-1) { |
280 |
|
perror("open"); |
|
|
286 |
|
perror("open(\"/proc/net/dev\")"); |
281 |
287 |
return NULL; |
return NULL; |
282 |
288 |
} |
} |
283 |
289 |
while ((len=read(fd,buffer,4096))) { |
while ((len=read(fd,buffer,4096))) { |
|
... |
... |
void please_do(int ndo, int *todo, char *ifname) { |
442 |
448 |
break; |
break; |
443 |
449 |
case DO_SINPACKETS: |
case DO_SINPACKETS: |
444 |
450 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
445 |
|
printf("%llu",stats->in_packets); |
|
|
451 |
|
if (stats) |
|
452 |
|
printf("%llu",stats->in_packets); |
446 |
453 |
break; |
break; |
447 |
454 |
case DO_SINBYTES: |
case DO_SINBYTES: |
448 |
455 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
449 |
|
printf("%llu",stats->in_bytes); |
|
|
456 |
|
if (stats) |
|
457 |
|
printf("%llu",stats->in_bytes); |
450 |
458 |
break; |
break; |
451 |
459 |
case DO_SINERRORS: |
case DO_SINERRORS: |
452 |
460 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
453 |
|
printf("%llu",stats->in_errors); |
|
|
461 |
|
if (stats) |
|
462 |
|
printf("%llu",stats->in_errors); |
454 |
463 |
break; |
break; |
455 |
464 |
case DO_SINDROPS: |
case DO_SINDROPS: |
456 |
465 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
457 |
|
printf("%llu",stats->in_drops); |
|
|
466 |
|
if (stats) |
|
467 |
|
printf("%llu",stats->in_drops); |
458 |
468 |
break; |
break; |
459 |
469 |
case DO_SINFIFO: |
case DO_SINFIFO: |
460 |
470 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
461 |
|
printf("%llu",stats->in_fifo); |
|
|
471 |
|
if (stats) |
|
472 |
|
printf("%llu",stats->in_fifo); |
462 |
473 |
break; |
break; |
463 |
474 |
case DO_SINFRAME: |
case DO_SINFRAME: |
464 |
475 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
465 |
|
printf("%llu",stats->in_frame); |
|
|
476 |
|
if (stats) |
|
477 |
|
printf("%llu",stats->in_frame); |
466 |
478 |
break; |
break; |
467 |
479 |
case DO_SINCOMPRESSES: |
case DO_SINCOMPRESSES: |
468 |
480 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
469 |
|
printf("%llu",stats->in_compress); |
|
|
481 |
|
if (stats) |
|
482 |
|
printf("%llu",stats->in_compress); |
470 |
483 |
break; |
break; |
471 |
484 |
case DO_SINMULTICAST: |
case DO_SINMULTICAST: |
472 |
485 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
473 |
|
printf("%llu",stats->in_multicast); |
|
|
486 |
|
if (stats) |
|
487 |
|
printf("%llu",stats->in_multicast); |
474 |
488 |
break; |
break; |
475 |
489 |
case DO_SINALL: |
case DO_SINALL: |
476 |
490 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
477 |
|
printf("%llu %llu %llu %llu %llu %llu %llu %llu", |
|
|
491 |
|
if (stats) |
|
492 |
|
printf("%llu %llu %llu %llu %llu %llu %llu %llu", |
478 |
493 |
stats->in_packets, |
stats->in_packets, |
479 |
494 |
stats->in_bytes, |
stats->in_bytes, |
480 |
495 |
stats->in_errors, |
stats->in_errors, |
|
... |
... |
void please_do(int ndo, int *todo, char *ifname) { |
486 |
501 |
break; |
break; |
487 |
502 |
case DO_SOUTBYTES: |
case DO_SOUTBYTES: |
488 |
503 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
489 |
|
printf("%llu",stats->out_bytes); |
|
|
504 |
|
if (stats) |
|
505 |
|
printf("%llu",stats->out_bytes); |
490 |
506 |
break; |
break; |
491 |
507 |
case DO_SOUTPACKETS: |
case DO_SOUTPACKETS: |
492 |
508 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
493 |
|
printf("%llu",stats->out_packets); |
|
|
509 |
|
if (stats) |
|
510 |
|
printf("%llu",stats->out_packets); |
494 |
511 |
break; |
break; |
495 |
512 |
case DO_SOUTERRORS: |
case DO_SOUTERRORS: |
496 |
513 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
497 |
|
printf("%llu",stats->out_errors); |
|
|
514 |
|
if (stats) |
|
515 |
|
printf("%llu",stats->out_errors); |
498 |
516 |
break; |
break; |
499 |
517 |
case DO_SOUTDROPS: |
case DO_SOUTDROPS: |
500 |
518 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
501 |
|
printf("%llu",stats->out_drops); |
|
|
519 |
|
if (stats) |
|
520 |
|
printf("%llu",stats->out_drops); |
502 |
521 |
break; |
break; |
503 |
522 |
case DO_SOUTFIFO: |
case DO_SOUTFIFO: |
504 |
523 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
505 |
|
printf("%llu",stats->out_fifo); |
|
|
524 |
|
if (stats) |
|
525 |
|
printf("%llu",stats->out_fifo); |
506 |
526 |
break; |
break; |
507 |
527 |
case DO_SOUTCOLLS: |
case DO_SOUTCOLLS: |
508 |
528 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
509 |
|
printf("%llu",stats->out_colls); |
|
|
529 |
|
if (stats) |
|
530 |
|
printf("%llu",stats->out_colls); |
510 |
531 |
break; |
break; |
511 |
532 |
case DO_SOUTCARRIER: |
case DO_SOUTCARRIER: |
512 |
533 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
513 |
|
printf("%llu",stats->out_carrier); |
|
|
534 |
|
if (stats) |
|
535 |
|
printf("%llu",stats->out_carrier); |
514 |
536 |
break; |
break; |
515 |
537 |
case DO_SOUTMULTICAST: |
case DO_SOUTMULTICAST: |
516 |
538 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
517 |
|
printf("%llu",stats->out_multicast); |
|
|
539 |
|
if (stats) |
|
540 |
|
printf("%llu",stats->out_multicast); |
518 |
541 |
break; |
break; |
519 |
542 |
case DO_SOUTALL: |
case DO_SOUTALL: |
520 |
543 |
if (!stats) stats=get_stats(ifname); |
if (!stats) stats=get_stats(ifname); |
521 |
|
printf("%llu %llu %llu %llu %llu %llu %llu %llu", |
|
|
544 |
|
if (stats) |
|
545 |
|
printf("%llu %llu %llu %llu %llu %llu %llu %llu", |
522 |
546 |
stats->out_packets, |
stats->out_packets, |
523 |
547 |
stats->out_bytes, |
stats->out_bytes, |
524 |
548 |
stats->out_errors, |
stats->out_errors, |