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.27 by pajs, Thu Feb 12 21:25:02 2004 UTC vs.
Revision 1.36 by pajs, Fri Feb 13 18:54:29 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 339 | Line 340 | void network_iface_stat_init(int start, int end, netwo
340          for(net_stats+=start; start<end; start++){
341                  net_stats->interface_name=NULL;
342                  net_stats->speed=0;
343 <                net_stats->dup=NO_DUPLEX;
343 >                net_stats->dup=UNKNOWN_DUPLEX;
344                  net_stats++;
345          }
346   }
# 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 +        struct ifreq ifr;
389          int s;
390          int x;
391   #endif
# Line 450 | Line 452 | network_iface_stat_t *get_network_iface_stats(int *ent
452                          case(IFM_1000_SX):
453                          case(IFM_1000_LX):
454                          case(IFM_1000_CX):
455 + #if defined(FREEBSD) && !defined(FREEBSD5)
456                          case(IFM_1000_TX):
457 +                        case(IFM_1000_FX):
458 + #else
459 +                        case(IFM_1000_T):
460 + #endif
461                                  network_iface_stat_ptr->speed = 1000;
462                                  break;
463                          /* We don't know what it is */
# Line 464 | Line 471 | network_iface_stat_t *get_network_iface_stats(int *ent
471                  }else if( (ifmed.ifm_active | IFM_HDX) == ifmed.ifm_active ){
472                          network_iface_stat_ptr->dup = HALF_DUPLEX;
473                  }else{
474 <                        network_iface_stat_ptr->dup = NO_DUPLEX;
474 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
475                  }
476 +
477 +                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
478 +                        continue;
479 +                }      
480 +                if((ifr.ifr_flags & IFF_UP) != 0){
481 +                        network_iface_stat_ptr->up = 1;
482 +                }else{
483 +                        network_iface_stat_ptr->up = 0;
484 +                }
485 +
486                  ifaces++;
487          }      
488          freeifaddrs(net);
489 +        close(s);
490   #endif
491  
492   #ifdef SOLARIS
# Line 490 | Line 508 | network_iface_stat_t *get_network_iface_stats(int *ent
508                          network_iface_stat_ptr = network_iface_stats + ifaces;
509                          network_iface_stat_ptr->speed = knp->value.ui64 / (1000*1000);
510  
511 +                        if((knp=kstat_data_lookup(ksp, "link_up"))==NULL){
512 +                                /* Not a network interface, so skip to the next entry */
513 +                                continue;
514 +                        }
515 +                        /* Solaris has 1 for up, and 0 for not. As we do too */
516 +                        network_iface_stat_ptr->up = value.ui32;
517 +
518                          if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){
519                                  /* Not a network interface, so skip to the next entry */
520                                  continue;
521                          }
522  
523 <                        if(knp->value.ui64 == 0){
523 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
524 >                        if(knp->value.ui32 == 2){
525                                  network_iface_stat_ptr->dup = FULL_DUPLEX;
526 <                        }else{
526 >                        }
527 >                        if(knp->value.ui32 == 1){
528                                  network_iface_stat_ptr->dup = HALF_DUPLEX;
529                          }
530  
# Line 527 | Line 554 | network_iface_stat_t *get_network_iface_stats(int *ent
554          if(eth_tool_cmd_buf == NULL) return NULL;
555  
556          /* Ignore first 2 lines.. Just headings */
557 <        fgets(line, sizeof(line), f);
558 <        fgets(line, sizeof(line), f);
557 >        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
558 >        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
559  
560          while((fgets(line, sizeof(line), f)) != NULL){
561                  char *name, *ptr;
# Line 550 | Line 577 | network_iface_stat_t *get_network_iface_stats(int *ent
577                  ifr.ifr_data = (caddr_t) eth_tool_cmd_buf;
578                  strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
579  
580 <                ethcmd = (struct ethtool_cmd *)(&ifr)->ifr_data;
580 >                ethcmd = (struct ethtool_cmd *) ifr.ifr_data;
581                  ethcmd->cmd = ETHTOOL_GSET;
582  
583                  err = ioctl(sock, SIOCETHTOOL, &ifr);
# Line 569 | Line 596 | network_iface_stat_t *get_network_iface_stats(int *ent
596                  network_iface_stat_ptr = network_iface_stats + ifaces;
597                  network_iface_stat_ptr->interface_name = strdup(name);
598                  network_iface_stat_ptr->speed = ethcmd->speed;
599 <                network_iface_stat_ptr->dup = NO_DUPLEX;
599 >                if((ifr.ifr_flags & IFF_UP) != 0){
600 >                        network_iface_stat_ptr->up = 1;
601 >                }else{
602 >                        network_iface_stat_ptr->up = 0;
603 >                }
604 >
605 >                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
606                  if(ethcmd->duplex == 0x00){
607                          network_iface_stat_ptr->dup = FULL_DUPLEX;
608                  }
# Line 578 | Line 611 | network_iface_stat_t *get_network_iface_stats(int *ent
611                  }
612                  ifaces++;
613          }
614 <
614 >        close(sock);
615          free(eth_tool_cmd_buf);
616   #endif
617          *entries = ifaces;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines