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.35 by pajs, Fri Feb 13 18:45:43 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 450 | Line 451 | network_iface_stat_t *get_network_iface_stats(int *ent
451                          case(IFM_1000_SX):
452                          case(IFM_1000_LX):
453                          case(IFM_1000_CX):
454 + #if defined(FREEBSD) && !defined(FREEBSD5)
455                          case(IFM_1000_TX):
456 +                        case(IFM_1000_FX):
457 + #else
458 +                        case(IFM_1000_T):
459 + #endif
460                                  network_iface_stat_ptr->speed = 1000;
461                                  break;
462                          /* We don't know what it is */
# Line 459 | Line 465 | network_iface_stat_t *get_network_iface_stats(int *ent
465                                  break;
466                  }
467  
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 +
474                  if( (ifmed.ifm_active | IFM_FDX) == ifmed.ifm_active ){
475                          network_iface_stat_ptr->dup = FULL_DUPLEX;
476                  }else if( (ifmed.ifm_active | IFM_HDX) == ifmed.ifm_active ){
477                          network_iface_stat_ptr->dup = HALF_DUPLEX;
478                  }else{
479 <                        network_iface_stat_ptr->dup = NO_DUPLEX;
479 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
480                  }
481                  ifaces++;
482          }      
483          freeifaddrs(net);
484 +        close(s);
485   #endif
486  
487   #ifdef SOLARIS
# Line 490 | Line 503 | network_iface_stat_t *get_network_iface_stats(int *ent
503                          network_iface_stat_ptr = network_iface_stats + ifaces;
504                          network_iface_stat_ptr->speed = knp->value.ui64 / (1000*1000);
505  
506 +                        if((knp=kstat_data_lookup(ksp, "link_up"))==NULL){
507 +                                /* Not a network interface, so skip to the next entry */
508 +                                continue;
509 +                        }
510 +                        /* Solaris has 1 for up, and 0 for not. As we do too */
511 +                        network_iface_stat_ptr->up = value.ui32;
512 +
513                          if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){
514                                  /* Not a network interface, so skip to the next entry */
515                                  continue;
516                          }
517  
518 <                        if(knp->value.ui64 == 0){
518 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
519 >                        if(knp->value.ui32 == 2){
520                                  network_iface_stat_ptr->dup = FULL_DUPLEX;
521 <                        }else{
521 >                        }
522 >                        if(knp->value.ui32 == 1){
523                                  network_iface_stat_ptr->dup = HALF_DUPLEX;
524                          }
525  
# Line 527 | Line 549 | network_iface_stat_t *get_network_iface_stats(int *ent
549          if(eth_tool_cmd_buf == NULL) return NULL;
550  
551          /* Ignore first 2 lines.. Just headings */
552 <        fgets(line, sizeof(line), f);
553 <        fgets(line, sizeof(line), f);
552 >        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
553 >        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
554  
555          while((fgets(line, sizeof(line), f)) != NULL){
556                  char *name, *ptr;
# Line 550 | Line 572 | network_iface_stat_t *get_network_iface_stats(int *ent
572                  ifr.ifr_data = (caddr_t) eth_tool_cmd_buf;
573                  strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
574  
575 <                ethcmd = (struct ethtool_cmd *)(&ifr)->ifr_data;
575 >                ethcmd = (struct ethtool_cmd *) ifr.ifr_data;
576                  ethcmd->cmd = ETHTOOL_GSET;
577  
578                  err = ioctl(sock, SIOCETHTOOL, &ifr);
# Line 569 | Line 591 | network_iface_stat_t *get_network_iface_stats(int *ent
591                  network_iface_stat_ptr = network_iface_stats + ifaces;
592                  network_iface_stat_ptr->interface_name = strdup(name);
593                  network_iface_stat_ptr->speed = ethcmd->speed;
594 <                network_iface_stat_ptr->dup = NO_DUPLEX;
594 >                if((ifr.ifr_flags & IFF_UP) != 0){
595 >                        network_iface_stat_ptr->up = 1;
596 >                }else{
597 >                        network_iface_stat_ptr->up = 0;
598 >                }
599 >
600 >                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
601                  if(ethcmd->duplex == 0x00){
602                          network_iface_stat_ptr->dup = FULL_DUPLEX;
603                  }
# Line 578 | Line 606 | network_iface_stat_t *get_network_iface_stats(int *ent
606                  }
607                  ifaces++;
608          }
609 <
609 >        close(sock);
610          free(eth_tool_cmd_buf);
611   #endif
612          *entries = ifaces;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines