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.68 by ats, Thu Apr 8 13:44:44 2004 UTC vs.
Revision 1.74 by tdb, Wed Jul 13 09:31:54 2005 UTC

# Line 52 | Line 52
52   /* Stuff which could be defined by defining KERNEL, but
53   * that would be a bad idea, so we'll just declare it here
54   */
55 + #include <linux/version.h>
56 + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
57 + typedef __uint8_t __u8;
58 + typedef __uint16_t __u16;
59 + typedef __uint32_t __u32;
60 + typedef __uint64_t __u64;
61 + #else
62   typedef __uint8_t u8;
63   typedef __uint16_t u16;
64   typedef __uint32_t u32;
65   typedef __uint64_t u64;
66 + #endif
67   #include <linux/ethtool.h>
68   #include <linux/sockios.h>
69   #include <unistd.h>
# Line 112 | Line 120 | sg_network_io_stats *sg_get_network_io_stats(int *entr
120  
121   #ifdef ALLBSD
122          if(getifaddrs(&net) != 0){
123 <                sg_set_error(SG_ERROR_GETIFADDRS, NULL);
123 >                sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL);
124                  return NULL;
125          }
126  
# Line 244 | Line 252 | sg_network_io_stats *sg_get_network_io_stats(int *entr
252   #ifdef LINUX
253          f=fopen("/proc/net/dev", "r");
254          if(f==NULL){
255 <                sg_set_error(SG_ERROR_OPEN, "/proc/net/dev");
255 >                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev");
256                  return NULL;
257          }
258          /* read the 2 lines.. Its the title, so we dont care :) */
# Line 294 | Line 302 | sg_network_io_stats *sg_get_network_io_stats(int *entr
302          sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
303          return NULL;
304   #endif
305 + #ifdef HPUX
306 +        sg_set_error(SG_ERROR_UNSUPPORTED, "HP-UX");
307 +        return NULL;
308 + #endif
309  
310          *entries=interfaces;
311  
# Line 402 | Line 414 | int sg_network_io_compare_name(const void *va, const v
414   static void network_iface_stat_init(sg_network_iface_stats *s) {
415          s->interface_name = NULL;
416          s->speed = 0;
417 <        s->dup = SG_IFACE_DUPLEX_UNKNOWN;
417 >        s->duplex = SG_IFACE_DUPLEX_UNKNOWN;
418   }
419  
420   static void network_iface_stat_destroy(sg_network_iface_stats *s) {
# Line 437 | Line 449 | sg_network_iface_stats *sg_get_network_iface_stats(int
449  
450   #ifdef ALLBSD
451          if(getifaddrs(&net) != 0){
452 <                sg_set_error(SG_ERROR_GETIFADDRS, NULL);
452 >                sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL);
453                  return NULL;
454          }
455  
# Line 469 | Line 481 | sg_network_iface_stats *sg_get_network_iface_stats(int
481                  }
482  
483                  network_iface_stat_ptr->speed = 0;
484 <                network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN;
484 >                network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_UNKNOWN;
485                  ifaces++;
486  
487                  memset(&ifmed, 0, sizeof(struct ifmediareq));
# Line 526 | Line 538 | sg_network_iface_stats *sg_get_network_iface_stats(int
538                  }
539  
540                  if( (ifmed.ifm_active | IFM_FDX) == ifmed.ifm_active ){
541 <                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL;
541 >                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_FULL;
542                  }else if( (ifmed.ifm_active | IFM_HDX) == ifmed.ifm_active ){
543 <                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF;
543 >                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_HALF;
544                  }else{
545 <                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN;
545 >                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_UNKNOWN;
546                  }
547  
548          }      
# Line 545 | Line 557 | sg_network_iface_stats *sg_get_network_iface_stats(int
557          }
558  
559          if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
560 <                sg_set_error(SG_ERROR_SOCKET, NULL);
560 >                sg_set_error_with_errno(SG_ERROR_SOCKET, NULL);
561                  return NULL;
562          }
563  
# Line 584 | Line 596 | sg_network_iface_stats *sg_get_network_iface_stats(int
596                                  network_iface_stat_ptr->speed = 0;
597                          }
598  
599 <                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN;
599 >                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_UNKNOWN;
600                          if ((knp = kstat_data_lookup(ksp, "link_duplex")) != NULL) {
601                                  switch (knp->value.ui32) {
602                                  case 1:
603 <                                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF;
603 >                                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_HALF;
604                                          break;
605                                  case 2:
606 <                                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL;
606 >                                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_FULL;
607                                          break;
608                                  }
609                          }
# Line 604 | Line 616 | sg_network_iface_stats *sg_get_network_iface_stats(int
616   #ifdef LINUX
617          f = fopen("/proc/net/dev", "r");
618          if(f == NULL){
619 <                sg_set_error(SG_ERROR_OPEN, "/proc/net/dev");
619 >                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev");
620                  return NULL;
621          }
622  
623          /* Setup stuff so we can do the ioctl to get the info */
624          if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
625 <                sg_set_error(SG_ERROR_SOCKET, NULL);
625 >                sg_set_error_with_errno(SG_ERROR_SOCKET, NULL);
626                  return NULL;
627          }
628  
# Line 671 | Line 683 | sg_network_iface_stats *sg_get_network_iface_stats(int
683                          network_iface_stat_ptr->speed = ethcmd.speed;
684  
685                          switch (ethcmd.duplex) {
686 <                        case 0x00:
687 <                                network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL;
686 >                        case DUPLEX_FULL:
687 >                                network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_FULL;
688                                  break;
689 <                        case 0x01:
690 <                                network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF;
689 >                        case DUPLEX_HALF:
690 >                                network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_HALF;
691                                  break;
692                          default:
693 <                                network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN;
693 >                                network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_UNKNOWN;
694                          }
695                  } else {
696                          /* Not all interfaces support the ethtool ioctl. */
697                          network_iface_stat_ptr->speed = 0;
698 <                        network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN;
698 >                        network_iface_stat_ptr->duplex = SG_IFACE_DUPLEX_UNKNOWN;
699                  }
700  
701                  ifaces++;
# Line 691 | Line 703 | sg_network_iface_stats *sg_get_network_iface_stats(int
703          close(sock);
704          fclose(f);
705   #endif
706 + #ifdef CYGWIN
707 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
708 +        return NULL;
709 + #endif
710 + #ifdef HPUX
711 +        sg_set_error(SG_ERROR_UNSUPPORTED, "HP-UX");
712 +        return NULL;
713 + #endif
714 +
715 + #ifdef SG_ENABLE_DEPRECATED
716 +        network_iface_stat_ptr->dup = network_iface_stat_ptr->duplex;
717 + #endif
718 +
719          *entries = ifaces;
720          return network_iface_stats;
721   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines