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.38 by ats, Sat Feb 14 00:27:58 2004 UTC vs.
Revision 1.41 by pajs, Sat Feb 14 11:33:33 2004 UTC

# Line 411 | Line 411 | network_iface_stat_t *get_network_iface_stats(int *ent
411                  }
412                  network_iface_stat_ptr = network_iface_stats + ifaces;
413  
414 +                memset(&ifr, 0, sizeof(ifr));
415 +                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
416 +
417 +                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
418 +                        continue;
419 +                }      
420 +                if((ifr.ifr_flags & IFF_UP) != 0){
421 +                        network_iface_stat_ptr->up = 1;
422 +                }else{
423 +                        network_iface_stat_ptr->up = 0;
424 +                }
425 +
426 +                if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
427 +                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
428 +                if (network_iface_stat_ptr->interface_name == NULL) return NULL;
429 +
430 +                network_iface_stat_ptr->speed = 0;
431 +                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
432 +                ifaces++;
433 +
434                  memset(&ifmed, 0, sizeof(struct ifmediareq));
435                  strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name));
436                  if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
437 +                        /* Not all interfaces support the media ioctls. */
438                          continue;
439                  }
440  
# Line 423 | Line 444 | network_iface_stat_t *get_network_iface_stats(int *ent
444                          continue;
445                  }
446  
426                if(network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
427                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
428                if(network_iface_stat_ptr->interface_name == NULL) return NULL;
429
447                  /* Only intrested in the first 4 bits)  - Assuming only ETHER devices */
448                  x = ifmed.ifm_active & 0x0f;    
449                  switch(x){
# Line 472 | Line 489 | network_iface_stat_t *get_network_iface_stats(int *ent
489                          network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
490                  }
491  
475                memset(&ifr, 0, sizeof(ifr));
476                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
477
478                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
479                        continue;
480                }      
481                if((ifr.ifr_flags & IFF_UP) != 0){
482                        network_iface_stat_ptr->up = 1;
483                }else{
484                        network_iface_stat_ptr->up = 0;
485                }
486
487                ifaces++;
492          }      
493          freeifaddrs(net);
494          close(sock);
# Line 514 | Line 518 | network_iface_stat_t *get_network_iface_stats(int *ent
518                                  continue;
519                          }
520                          /* Solaris has 1 for up, and 0 for not. As we do too */
521 <                        network_iface_stat_ptr->up = value.ui32;
521 >                        network_iface_stat_ptr->up = knp->value.ui32;
522  
523                          if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){
524                                  /* Not a network interface, so skip to the next entry */
# Line 608 | Line 612 | network_iface_stat_t *get_network_iface_stats(int *ent
612                          }
613                  } else {
614                          /* Not all interfaces support the ethtool ioctl. */
615 <                        network_iface_stat_ptr->speed = -1;
615 >                        network_iface_stat_ptr->speed = 0;
616                          network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
617                  }
618  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines