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.65 by tdb, Wed Apr 7 14:53:40 2004 UTC vs.
Revision 1.71 by ats, Mon Nov 8 08:07:25 2004 UTC

# Line 45 | Line 45
45   #ifdef LINUX
46   #include <stdio.h>
47   #include <sys/types.h>
48 #include <regex.h>
48   #include <sys/ioctl.h>
49   #include <sys/socket.h>
50   #include <net/if.h>
# Line 113 | Line 112 | sg_network_io_stats *sg_get_network_io_stats(int *entr
112  
113   #ifdef ALLBSD
114          if(getifaddrs(&net) != 0){
115 +                sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL);
116                  return NULL;
117          }
118  
# Line 146 | Line 146 | sg_network_io_stats *sg_get_network_io_stats(int *entr
146  
147   #ifdef SOLARIS
148          if ((kc = kstat_open()) == NULL) {
149 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
150                  return NULL;
151          }
152  
153          interfaces=0;
154  
155 <        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
155 >        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
156                  if (!strcmp(ksp->ks_class, "net")) {
157                          kstat_read(kc, ksp, NULL);
158  
# Line 243 | Line 244 | sg_network_io_stats *sg_get_network_io_stats(int *entr
244   #ifdef LINUX
245          f=fopen("/proc/net/dev", "r");
246          if(f==NULL){
247 +                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev");
248                  return NULL;
249          }
250          /* read the 2 lines.. Its the title, so we dont care :) */
# Line 251 | Line 253 | sg_network_io_stats *sg_get_network_io_stats(int *entr
253  
254  
255          if((regcomp(&regex, "^ *([^:]+): *([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +([0-9]+)", REG_EXTENDED))!=0){
256 +                sg_set_error(SG_ERROR_PARSE, NULL);
257                  return NULL;
258          }
259  
# Line 288 | Line 291 | sg_network_io_stats *sg_get_network_io_stats(int *entr
291   #endif
292  
293   #ifdef CYGWIN
294 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
295          return NULL;
296   #endif
297 + #ifdef HPUX
298 +        sg_set_error(SG_ERROR_UNSUPPORTED, "HP-UX");
299 +        return NULL;
300 + #endif
301  
302          *entries=interfaces;
303  
# Line 386 | Line 394 | sg_network_io_stats *sg_get_network_io_stats_diff(int
394          return diff;
395   }
396  
397 + int sg_network_io_compare_name(const void *va, const void *vb) {
398 +        const sg_network_io_stats *a = (const sg_network_io_stats *)va;
399 +        const sg_network_io_stats *b = (const sg_network_io_stats *)vb;
400 +
401 +        return strcmp(a->interface_name, b->interface_name);
402 + }
403 +
404   /* NETWORK INTERFACE STATS */
405  
406   static void network_iface_stat_init(sg_network_iface_stats *s) {
# Line 426 | Line 441 | sg_network_iface_stats *sg_get_network_iface_stats(int
441  
442   #ifdef ALLBSD
443          if(getifaddrs(&net) != 0){
444 +                sg_set_error_with_errno(SG_ERROR_GETIFADDRS, NULL);
445                  return NULL;
446          }
447  
# Line 528 | Line 544 | sg_network_iface_stats *sg_get_network_iface_stats(int
544  
545   #ifdef SOLARIS
546          if ((kc = kstat_open()) == NULL) {
547 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
548                  return NULL;
549          }
550  
551          if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
552 +                sg_set_error_with_errno(SG_ERROR_SOCKET, NULL);
553                  return NULL;
554          }
555  
# Line 590 | Line 608 | sg_network_iface_stats *sg_get_network_iface_stats(int
608   #ifdef LINUX
609          f = fopen("/proc/net/dev", "r");
610          if(f == NULL){
611 +                sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/net/dev");
612                  return NULL;
613          }
614  
615          /* Setup stuff so we can do the ioctl to get the info */
616          if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
617 +                sg_set_error_with_errno(SG_ERROR_SOCKET, NULL);
618                  return NULL;
619          }
620  
621          /* Ignore first 2 lines.. Just headings */
622 <        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
623 <        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
622 >        if((fgets(line, sizeof(line), f)) == NULL) {
623 >                sg_set_error(SG_ERROR_PARSE, NULL);
624 >                return NULL;
625 >        }
626 >        if((fgets(line, sizeof(line), f)) == NULL) {
627 >                sg_set_error(SG_ERROR_PARSE, NULL);
628 >                return NULL;
629 >        }
630  
631          while((fgets(line, sizeof(line), f)) != NULL){
632                  char *name, *ptr;
# Line 669 | Line 695 | sg_network_iface_stats *sg_get_network_iface_stats(int
695          close(sock);
696          fclose(f);
697   #endif
698 + #ifdef CYGWIN
699 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
700 +        return NULL;
701 + #endif
702 + #ifdef HPUX
703 +        sg_set_error(SG_ERROR_UNSUPPORTED, "HP-UX");
704 +        return NULL;
705 + #endif
706 +
707          *entries = ifaces;
708          return network_iface_stats;
709 + }
710 +
711 + int sg_network_iface_compare_name(const void *va, const void *vb) {
712 +        const sg_network_iface_stats *a = (const sg_network_iface_stats *)va;
713 +        const sg_network_iface_stats *b = (const sg_network_iface_stats *)vb;
714 +
715 +        return strcmp(a->interface_name, b->interface_name);
716   }
717  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines