ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/network_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/network_stats.c (file contents):
Revision 1.77 by tdb, Sun Jan 22 18:10:39 2006 UTC vs.
Revision 1.81 by tdb, Wed Jun 9 14:44:28 2010 UTC

# Line 230 | Line 230 | sg_network_io_stats *sg_get_network_io_stats(int *entr
230  
231                          /* Create new network_stats */
232                          if (VECTOR_RESIZE(network_stats, interfaces + 1) < 0) {
233 +                                kstat_close(kc);
234                                  return NULL;
235                          }
236                          network_stat_ptr=network_stats+interfaces;
237  
238 +                        /* Read interface name */
239 +                        if (sg_update_string(&network_stat_ptr->interface_name,
240 +                                             ksp->ks_name) < 0) {
241 +                                kstat_close(kc);
242 +                                return NULL;
243 +                        }
244 +
245                          /* Finish reading rx */
246                          network_stat_ptr->rx=knp->VALTYPE;
247  
# Line 273 | Line 281 | sg_network_io_stats *sg_get_network_io_stats(int *entr
281                          }
282                          network_stat_ptr->collisions=knp->value.ui32;
283  
276                        /* Read interface name */
277                        if (sg_update_string(&network_stat_ptr->interface_name,
278                                             ksp->ks_name) < 0) {
279                                return NULL;
280                        }
284  
285                          /* Store systime */
286                          network_stat_ptr->systime=time(NULL);
# Line 604 | Line 607 | sg_network_iface_stats *sg_get_network_iface_stats(int
607                          continue;
608                  }
609  
610 <                /* Only intrested in the first 4 bits)  - Assuming only ETHER devices */
611 <                x = ifmed.ifm_active & 0x0f;    
610 >                /* Assuming only ETHER devices */
611 >                x = IFM_SUBTYPE(ifmed.ifm_active);
612                  switch(x){
613                          /* 10 Mbit connections. Speedy :) */
614                          case(IFM_10_T):
# Line 615 | Line 618 | sg_network_iface_stats *sg_get_network_iface_stats(int
618                          case(IFM_10_FL):
619                                  network_iface_stat_ptr->speed = 10;
620                                  break;
621 <                        /* 100 Mbit conneections */
621 >                        /* 100 Mbit connections */
622                          case(IFM_100_TX):
623                          case(IFM_100_FX):
624                          case(IFM_100_T4):
# Line 665 | Line 668 | sg_network_iface_stats *sg_get_network_iface_stats(int
668  
669          if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
670                  sg_set_error_with_errno(SG_ERROR_SOCKET, NULL);
671 +                kstat_close(kc);
672                  return NULL;
673          }
674  
# Line 681 | Line 685 | sg_network_iface_stats *sg_get_network_iface_stats(int
685                          }
686  
687                          if (VECTOR_RESIZE(network_iface_stats, ifaces + 1) < 0) {
688 +                                kstat_close(kc);
689                                  return NULL;
690                          }
691                          network_iface_stat_ptr = network_iface_stats + ifaces;
# Line 688 | Line 693 | sg_network_iface_stats *sg_get_network_iface_stats(int
693  
694                          if (sg_update_string(&network_iface_stat_ptr->interface_name,
695                                               ksp->ks_name) < 0) {
696 +                                kstat_close(kc);
697                                  return NULL;
698                          }
699  
700                          if ((ifr.ifr_flags & IFF_UP) != 0) {
701 <                                network_iface_stat_ptr->up = 1;
701 >                                if ((knp = kstat_data_lookup(ksp, "link_up")) != NULL) {
702 >                                        /* take in to account if link
703 >                                         * is up as well as interface */
704 >                                        if (knp->value.ui32 != 0u) {
705 >                                                network_iface_stat_ptr->up = 1;
706 >                                        } else {
707 >                                                network_iface_stat_ptr->up = 0;
708 >                                        }
709 >                                }
710 >                                else {
711 >                                        /* maintain compatibility */
712 >                                        network_iface_stat_ptr->up = 1;
713 >                                }
714                          } else {
715                                  network_iface_stat_ptr->up = 0;
716                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines