| 1 | 
   | 
 /* | 
 
 
 
 
 
 
 
 
 
 
 
 | 2 | 
 < | 
  * i-scream central monitoring system | 
 
 
 
 
 
 
 
 
 
 | 2 | 
 > | 
  * i-scream libstatgrab | 
 
 
 
 
 
 
 
 
 
 
 
 | 3 | 
   | 
  * http://www.i-scream.org | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 4 | 
   | 
  * Copyright (C) 2000-2004 i-scream | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 5 | 
   | 
  * | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 27 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 28 | 
   | 
 int main(int argc, char **argv){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 29 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 30 | 
 < | 
         network_iface_stat_t *network_iface_stats; | 
 
 
 
 
 
 
 
 
 
 | 30 | 
 > | 
         sg_network_iface_stats *network_iface_stats; | 
 
 
 
 
 
 
 
 
 
 
 
 | 31 | 
   | 
         int iface_count, i; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 32 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 33 | 
   | 
         /* Initialise statgrab */ | 
 
 
 
 
 
 
 
 
 
 
 
 | 34 | 
 < | 
         statgrab_init(); | 
 
 
 
 
 
 
 
 
 
 | 34 | 
 > | 
         sg_init(); | 
 
 
 
 
 
 
 
 
 
 
 
 | 35 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 36 | 
   | 
         /* Drop setuid/setgid privileges. */ | 
 
 
 
 
 
 
 
 
 
 
 
 | 37 | 
 < | 
         if (statgrab_drop_privileges() != 0) { | 
 
 
 
 
 
 
 
 
 
 | 37 | 
 > | 
         if (sg_drop_privileges() != 0) { | 
 
 
 
 
 
 
 
 
 
 
 
 | 38 | 
   | 
                 perror("Error. Failed to drop privileges"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 39 | 
   | 
                 return 1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 40 | 
   | 
         } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 41 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 42 | 
 < | 
         network_iface_stats = get_network_iface_stats(&iface_count); | 
 
 
 
 
 
 
 
 
 
 | 42 | 
 > | 
         network_iface_stats = sg_get_network_iface_stats(&iface_count); | 
 
 
 
 
 
 
 
 
 
 
 
 | 43 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 44 | 
   | 
         if(network_iface_stats == NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 45 | 
   | 
                 fprintf(stderr, "Failed to get network interface stats\n"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 46 | 
   | 
                 exit(1); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 47 | 
   | 
         } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 48 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 49 | 
 + | 
         if (argc != 1) { | 
 
 
 
 
 
 
 
 
 | 50 | 
 + | 
                 /* If an argument is given, use bsearch to find just that | 
 
 
 
 
 
 
 
 
 | 51 | 
 + | 
                  * interface. */ | 
 
 
 
 
 
 
 
 
 | 52 | 
 + | 
                 sg_network_iface_stats key; | 
 
 
 
 
 
 
 
 
 | 53 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 | 54 | 
 + | 
                 key.interface_name = argv[1]; | 
 
 
 
 
 
 
 
 
 | 55 | 
 + | 
                 network_iface_stats = bsearch(&key, network_iface_stats, | 
 
 
 
 
 
 
 
 
 | 56 | 
 + | 
                                               iface_count, | 
 
 
 
 
 
 
 
 
 | 57 | 
 + | 
                                               sizeof *network_iface_stats, | 
 
 
 
 
 
 
 
 
 | 58 | 
 + | 
                                               sg_network_iface_compare_name); | 
 
 
 
 
 
 
 
 
 | 59 | 
 + | 
                 if (network_iface_stats == NULL) { | 
 
 
 
 
 
 
 
 
 | 60 | 
 + | 
                         fprintf(stderr, "Interface %s not found\n", argv[1]); | 
 
 
 
 
 
 
 
 
 | 61 | 
 + | 
                         exit(1); | 
 
 
 
 
 
 
 
 
 | 62 | 
 + | 
                 } | 
 
 
 
 
 
 
 
 
 | 63 | 
 + | 
                 iface_count = 1; | 
 
 
 
 
 
 
 
 
 | 64 | 
 + | 
         } | 
 
 
 
 
 
 
 
 
 | 65 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 66 | 
   | 
         printf("Name\tSpeed\tDuplex\n"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 67 | 
   | 
         for(i = 0; i < iface_count; i++) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 68 | 
   | 
                 printf("%s\t%d\t", network_iface_stats->interface_name, network_iface_stats->speed); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 69 | 
   | 
                 switch (network_iface_stats->dup) { | 
 
 
 
 
 
 
 
 
 
 
 
 | 70 | 
 < | 
                 case FULL_DUPLEX: | 
 
 
 
 
 
 
 
 
 
 | 70 | 
 > | 
                 case SG_IFACE_DUPLEX_FULL: | 
 
 
 
 
 
 
 
 
 
 
 
 | 71 | 
   | 
                         printf("full\n"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 72 | 
   | 
                         break; | 
 
 
 
 
 
 
 
 
 
 
 
 | 73 | 
 < | 
                 case HALF_DUPLEX: | 
 
 
 
 
 
 
 
 
 
 | 73 | 
 > | 
                 case SG_IFACE_DUPLEX_HALF: | 
 
 
 
 
 
 
 
 
 
 
 
 | 74 | 
   | 
                         printf("half\n"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 75 | 
   | 
                         break; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 76 | 
   | 
                 default: | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 77 | 
   | 
                         printf("unknown\n"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 78 | 
   | 
                         break; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 79 | 
   | 
                 } | 
 
 
 
 
 
 
 
 
 | 80 | 
 + | 
                 network_iface_stats++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 81 | 
   | 
         } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 82 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 83 | 
   | 
         exit(0); |