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> |
112 |
|
|
113 |
|
#ifdef ALLBSD |
114 |
|
if(getifaddrs(&net) != 0){ |
115 |
+ |
sg_set_error(SG_ERROR_GETIFADDRS, NULL); |
116 |
|
return NULL; |
117 |
|
} |
118 |
|
|
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 |
|
|
244 |
|
#ifdef LINUX |
245 |
|
f=fopen("/proc/net/dev", "r"); |
246 |
|
if(f==NULL){ |
247 |
+ |
sg_set_error(SG_ERROR_OPEN, "/proc/net/dev"); |
248 |
|
return NULL; |
249 |
|
} |
250 |
|
/* read the 2 lines.. Its the title, so we dont care :) */ |
253 |
|
|
254 |
|
|
255 |
|
if((regcomp(®ex, "^ *([^:]+): *([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 |
|
|
291 |
|
#endif |
292 |
|
|
293 |
|
#ifdef CYGWIN |
294 |
+ |
sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin"); |
295 |
|
return NULL; |
296 |
|
#endif |
297 |
|
|
430 |
|
|
431 |
|
#ifdef ALLBSD |
432 |
|
if(getifaddrs(&net) != 0){ |
433 |
+ |
sg_set_error(SG_ERROR_GETIFADDRS, NULL); |
434 |
|
return NULL; |
435 |
|
} |
436 |
|
|
533 |
|
|
534 |
|
#ifdef SOLARIS |
535 |
|
if ((kc = kstat_open()) == NULL) { |
536 |
+ |
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
537 |
|
return NULL; |
538 |
|
} |
539 |
|
|
540 |
|
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { |
541 |
+ |
sg_set_error(SG_ERROR_SOCKET, NULL); |
542 |
|
return NULL; |
543 |
|
} |
544 |
|
|
597 |
|
#ifdef LINUX |
598 |
|
f = fopen("/proc/net/dev", "r"); |
599 |
|
if(f == NULL){ |
600 |
+ |
sg_set_error(SG_ERROR_OPEN, "/proc/net/dev"); |
601 |
|
return NULL; |
602 |
|
} |
603 |
|
|
604 |
|
/* Setup stuff so we can do the ioctl to get the info */ |
605 |
|
if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ |
606 |
+ |
sg_set_error(SG_ERROR_SOCKET, NULL); |
607 |
|
return NULL; |
608 |
|
} |
609 |
|
|
610 |
|
/* Ignore first 2 lines.. Just headings */ |
611 |
< |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
612 |
< |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
611 |
> |
if((fgets(line, sizeof(line), f)) == NULL) { |
612 |
> |
sg_set_error(SG_ERROR_PARSE, NULL); |
613 |
> |
return NULL; |
614 |
> |
} |
615 |
> |
if((fgets(line, sizeof(line), f)) == NULL) { |
616 |
> |
sg_set_error(SG_ERROR_PARSE, NULL); |
617 |
> |
return NULL; |
618 |
> |
} |
619 |
|
|
620 |
|
while((fgets(line, sizeof(line), f)) != NULL){ |
621 |
|
char *name, *ptr; |