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.31 by ats, Fri Feb 13 15:12:26 2004 UTC vs.
Revision 1.37 by ats, Sat Feb 14 00:08:51 2004 UTC

# Line 50 | Line 50 | typedef __uint16_t u16;
50   typedef __uint32_t u32;
51   #include <linux/ethtool.h>
52   #include <linux/sockios.h>
53 + #include <unistd.h>
54   #endif
55   #ifdef ALLBSD
56   #include <sys/types.h>
# Line 384 | 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 401 | 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 413 | 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 471 | 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
# Line 496 | Line 511 | network_iface_stat_t *get_network_iface_stats(int *ent
511                          network_iface_stat_ptr = network_iface_stats + ifaces;
512                          network_iface_stat_ptr->speed = knp->value.ui64 / (1000*1000);
513  
514 +                        if((knp=kstat_data_lookup(ksp, "link_up"))==NULL){
515 +                                /* Not a network interface, so skip to the next entry */
516 +                                continue;
517 +                        }
518 +                        /* Solaris has 1 for up, and 0 for not. As we do too */
519 +                        network_iface_stat_ptr->up = value.ui32;
520 +
521                          if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){
522                                  /* Not a network interface, so skip to the next entry */
523                                  continue;
524                          }
525  
526 <                        if(knp->value.ui64 == 0){
526 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
527 >                        if(knp->value.ui32 == 2){
528                                  network_iface_stat_ptr->dup = FULL_DUPLEX;
529 <                        }else{
529 >                        }
530 >                        if(knp->value.ui32 == 1){
531                                  network_iface_stat_ptr->dup = HALF_DUPLEX;
532                          }
533  
# Line 575 | Line 599 | network_iface_stat_t *get_network_iface_stats(int *ent
599                  network_iface_stat_ptr = network_iface_stats + ifaces;
600                  network_iface_stat_ptr->interface_name = strdup(name);
601                  network_iface_stat_ptr->speed = ethcmd->speed;
602 <                network_iface_stat_ptr->dup = UNKNOWN_DUPEX;
602 >                if((ifr.ifr_flags & IFF_UP) != 0){
603 >                        network_iface_stat_ptr->up = 1;
604 >                }else{
605 >                        network_iface_stat_ptr->up = 0;
606 >                }
607 >
608 >                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
609                  if(ethcmd->duplex == 0x00){
610                          network_iface_stat_ptr->dup = FULL_DUPLEX;
611                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines