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.35 by pajs, Fri Feb 13 18:45:43 2004 UTC vs.
Revision 1.37 by ats, Sat Feb 14 00:08:51 2004 UTC

# Line 385 | Line 385 | network_iface_stat_t *get_network_iface_stats(int *ent
385   #ifdef ALLBSD
386          struct ifaddrs *net, *net_ptr;
387          struct ifmediareq ifmed;
388 <        int s;
388 >        struct ifreq ifr;
389 >        int sock;
390          int x;
391   #endif
392   #ifdef LINUX
# Line 402 | Line 403 | network_iface_stat_t *get_network_iface_stats(int *ent
403                  return NULL;
404          }
405  
406 <        if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == NULL) return NULL;
406 >        if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 0) return NULL;
407  
408          for(net_ptr=net; net_ptr!=NULL; net_ptr=net_ptr->ifa_next){
409                  if(net_ptr->ifa_addr->sa_family != AF_LINK) continue;
# Line 414 | Line 415 | network_iface_stat_t *get_network_iface_stats(int *ent
415  
416                  memset(&ifmed, 0, sizeof(struct ifmediareq));
417                  strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name));
418 <                if(ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
418 >                if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
419                          continue;
420                  }
421  
# Line 465 | Line 466 | network_iface_stat_t *get_network_iface_stats(int *ent
466                                  break;
467                  }
468  
468                if((ifmr.ifm_status & IFM_ACTIVE)){
469                        network_iface_stat_ptr->up = 1;
470                }else{
471                        network_iface_stat_ptr->up = 0;
472                }
473
469                  if( (ifmed.ifm_active | IFM_FDX) == ifmed.ifm_active ){
470                          network_iface_stat_ptr->dup = FULL_DUPLEX;
471                  }else if( (ifmed.ifm_active | IFM_HDX) == ifmed.ifm_active ){
# Line 478 | Line 473 | network_iface_stat_t *get_network_iface_stats(int *ent
473                  }else{
474                          network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
475                  }
476 +
477 +                memset(&ifr, 0, sizeof(ifr));
478 +                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
479 +
480 +                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
481 +                        continue;
482 +                }      
483 +                if((ifr.ifr_flags & IFF_UP) != 0){
484 +                        network_iface_stat_ptr->up = 1;
485 +                }else{
486 +                        network_iface_stat_ptr->up = 0;
487 +                }
488 +
489                  ifaces++;
490          }      
491          freeifaddrs(net);
492 <        close(s);
492 >        close(sock);
493   #endif
494  
495   #ifdef SOLARIS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines