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.66 by tdb, Wed Apr 7 21:08:40 2004 UTC

# Line 113 | Line 113 | sg_network_io_stats *sg_get_network_io_stats(int *entr
113  
114   #ifdef ALLBSD
115          if(getifaddrs(&net) != 0){
116 +                sg_set_error(SG_ERROR_GETIFADDRS, NULL);
117                  return NULL;
118          }
119  
# Line 146 | Line 147 | sg_network_io_stats *sg_get_network_io_stats(int *entr
147  
148   #ifdef SOLARIS
149          if ((kc = kstat_open()) == NULL) {
150 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
151                  return NULL;
152          }
153  
154          interfaces=0;
155  
156 <        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
156 >        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
157                  if (!strcmp(ksp->ks_class, "net")) {
158                          kstat_read(kc, ksp, NULL);
159  
# Line 243 | Line 245 | sg_network_io_stats *sg_get_network_io_stats(int *entr
245   #ifdef LINUX
246          f=fopen("/proc/net/dev", "r");
247          if(f==NULL){
248 +                sg_set_error(SG_ERROR_OPEN, "/proc/net/dev");
249                  return NULL;
250          }
251          /* read the 2 lines.. Its the title, so we dont care :) */
# Line 251 | Line 254 | sg_network_io_stats *sg_get_network_io_stats(int *entr
254  
255  
256          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){
257 +                sg_set_error(SG_ERROR_PARSE, NULL);
258                  return NULL;
259          }
260  
# Line 288 | Line 292 | sg_network_io_stats *sg_get_network_io_stats(int *entr
292   #endif
293  
294   #ifdef CYGWIN
295 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
296          return NULL;
297   #endif
298  
# Line 426 | Line 431 | sg_network_iface_stats *sg_get_network_iface_stats(int
431  
432   #ifdef ALLBSD
433          if(getifaddrs(&net) != 0){
434 +                sg_set_error(SG_ERROR_GETIFADDRS, NULL);
435                  return NULL;
436          }
437  
# Line 528 | Line 534 | sg_network_iface_stats *sg_get_network_iface_stats(int
534  
535   #ifdef SOLARIS
536          if ((kc = kstat_open()) == NULL) {
537 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
538                  return NULL;
539          }
540  
541          if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
542 +                sg_set_error(SG_ERROR_SOCKET, NULL);
543                  return NULL;
544          }
545  
# Line 590 | Line 598 | sg_network_iface_stats *sg_get_network_iface_stats(int
598   #ifdef LINUX
599          f = fopen("/proc/net/dev", "r");
600          if(f == NULL){
601 +                sg_set_error(SG_ERROR_OPEN, "/proc/net/dev");
602                  return NULL;
603          }
604  
605          /* Setup stuff so we can do the ioctl to get the info */
606          if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
607 +                sg_set_error(SG_ERROR_SOCKET, NULL);
608                  return NULL;
609          }
610  
611          /* Ignore first 2 lines.. Just headings */
612 <        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
613 <        if((fgets(line, sizeof(line), f)) == NULL) return NULL;
612 >        if((fgets(line, sizeof(line), f)) == NULL) {
613 >                sg_set_error(SG_ERROR_PARSE, NULL);
614 >                return NULL;
615 >        }
616 >        if((fgets(line, sizeof(line), f)) == NULL) {
617 >                sg_set_error(SG_ERROR_PARSE, NULL);
618 >                return NULL;
619 >        }
620  
621          while((fgets(line, sizeof(line), f)) != NULL){
622                  char *name, *ptr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines