87 |
|
} |
88 |
|
|
89 |
|
VECTOR_DECLARE_STATIC(network_stats, sg_network_io_stats, 5, |
90 |
< |
network_stat_init, network_stat_destroy); |
90 |
> |
network_stat_init, network_stat_destroy); |
91 |
|
|
92 |
|
sg_network_io_stats *sg_get_network_io_stats(int *entries){ |
93 |
|
int interfaces; |
94 |
|
sg_network_io_stats *network_stat_ptr; |
95 |
|
|
96 |
|
#ifdef SOLARIS |
97 |
< |
kstat_ctl_t *kc; |
98 |
< |
kstat_t *ksp; |
97 |
> |
kstat_ctl_t *kc; |
98 |
> |
kstat_t *ksp; |
99 |
|
kstat_named_t *knp; |
100 |
|
#endif |
101 |
|
|
127 |
|
network_stat_ptr=network_stats+interfaces; |
128 |
|
|
129 |
|
if (sg_update_string(&network_stat_ptr->interface_name, |
130 |
< |
net_ptr->ifa_name) < 0) { |
130 |
> |
net_ptr->ifa_name) < 0) { |
131 |
|
return NULL; |
132 |
|
} |
133 |
|
net_data=(struct if_data *)net_ptr->ifa_data; |
145 |
|
#endif |
146 |
|
|
147 |
|
#ifdef SOLARIS |
148 |
< |
if ((kc = kstat_open()) == NULL) { |
149 |
< |
return NULL; |
150 |
< |
} |
148 |
> |
if ((kc = kstat_open()) == NULL) { |
149 |
> |
return NULL; |
150 |
> |
} |
151 |
|
|
152 |
|
interfaces=0; |
153 |
|
|
154 |
|
for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { |
155 |
< |
if (!strcmp(ksp->ks_class, "net")) { |
156 |
< |
kstat_read(kc, ksp, NULL); |
155 |
> |
if (!strcmp(ksp->ks_class, "net")) { |
156 |
> |
kstat_read(kc, ksp, NULL); |
157 |
|
|
158 |
|
#ifdef SOL7 |
159 |
|
#define LRX "rbytes" |
227 |
|
|
228 |
|
/* Read interface name */ |
229 |
|
if (sg_update_string(&network_stat_ptr->interface_name, |
230 |
< |
ksp->ks_name) < 0) { |
230 |
> |
ksp->ks_name) < 0) { |
231 |
|
return NULL; |
232 |
|
} |
233 |
|
|
264 |
|
if (VECTOR_RESIZE(network_stats, interfaces + 1) < 0) { |
265 |
|
return NULL; |
266 |
|
} |
267 |
< |
network_stat_ptr=network_stats+interfaces; |
267 |
> |
network_stat_ptr=network_stats+interfaces; |
268 |
|
|
269 |
|
if(network_stat_ptr->interface_name!=NULL){ |
270 |
|
free(network_stat_ptr->interface_name); |
313 |
|
|
314 |
|
sg_network_io_stats *sg_get_network_io_stats_diff(int *entries) { |
315 |
|
VECTOR_DECLARE_STATIC(diff, sg_network_io_stats, 1, |
316 |
< |
network_stat_init, network_stat_destroy); |
316 |
> |
network_stat_init, network_stat_destroy); |
317 |
|
sg_network_io_stats *src = NULL, *dest; |
318 |
|
int i, j, diff_count, new_count; |
319 |
|
|
334 |
|
dest = &diff[i]; |
335 |
|
|
336 |
|
if (sg_update_string(&dest->interface_name, |
337 |
< |
src->interface_name) < 0) { |
337 |
> |
src->interface_name) < 0) { |
338 |
|
return NULL; |
339 |
|
} |
340 |
|
dest->rx = src->rx; |
400 |
|
|
401 |
|
sg_network_iface_stats *sg_get_network_iface_stats(int *entries){ |
402 |
|
VECTOR_DECLARE_STATIC(network_iface_stats, sg_network_iface_stats, 5, |
403 |
< |
network_iface_stat_init, network_iface_stat_destroy); |
403 |
> |
network_iface_stat_init, network_iface_stat_destroy); |
404 |
|
sg_network_iface_stats *network_iface_stat_ptr; |
405 |
|
int ifaces = 0; |
406 |
|
|
407 |
|
#ifdef SOLARIS |
408 |
< |
kstat_ctl_t *kc; |
409 |
< |
kstat_t *ksp; |
408 |
> |
kstat_ctl_t *kc; |
409 |
> |
kstat_t *ksp; |
410 |
|
kstat_named_t *knp; |
411 |
|
int sock; |
412 |
|
#endif |
413 |
|
#ifdef ALLBSD |
414 |
< |
struct ifaddrs *net, *net_ptr; |
414 |
> |
struct ifaddrs *net, *net_ptr; |
415 |
|
struct ifmediareq ifmed; |
416 |
|
struct ifreq ifr; |
417 |
|
int sock; |
418 |
|
int x; |
419 |
|
#endif |
420 |
|
#ifdef LINUX |
421 |
< |
FILE *f; |
422 |
< |
/* Horrible big enough, but it should be easily big enough */ |
423 |
< |
char line[8096]; |
421 |
> |
FILE *f; |
422 |
> |
/* Horrible big enough, but it should be easily big enough */ |
423 |
> |
char line[8096]; |
424 |
|
int sock; |
425 |
|
#endif |
426 |
|
|
427 |
|
#ifdef ALLBSD |
428 |
< |
if(getifaddrs(&net) != 0){ |
429 |
< |
return NULL; |
430 |
< |
} |
428 |
> |
if(getifaddrs(&net) != 0){ |
429 |
> |
return NULL; |
430 |
> |
} |
431 |
|
|
432 |
|
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 0) return NULL; |
433 |
|
|
434 |
|
for(net_ptr=net; net_ptr!=NULL; net_ptr=net_ptr->ifa_next){ |
435 |
< |
if(net_ptr->ifa_addr->sa_family != AF_LINK) continue; |
435 |
> |
if(net_ptr->ifa_addr->sa_family != AF_LINK) continue; |
436 |
|
|
437 |
|
if (VECTOR_RESIZE(network_iface_stats, ifaces + 1) < 0) { |
438 |
< |
return NULL; |
439 |
< |
} |
440 |
< |
network_iface_stat_ptr = network_iface_stats + ifaces; |
438 |
> |
return NULL; |
439 |
> |
} |
440 |
> |
network_iface_stat_ptr = network_iface_stats + ifaces; |
441 |
|
|
442 |
|
memset(&ifr, 0, sizeof(ifr)); |
443 |
|
strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name)); |
452 |
|
} |
453 |
|
|
454 |
|
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
455 |
< |
net_ptr->ifa_name) < 0) { |
455 |
> |
net_ptr->ifa_name) < 0) { |
456 |
|
return NULL; |
457 |
|
} |
458 |
|
|
554 |
|
ifaces++; |
555 |
|
|
556 |
|
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
557 |
< |
ksp->ks_name) < 0) { |
557 |
> |
ksp->ks_name) < 0) { |
558 |
|
return NULL; |
559 |
|
} |
560 |
|
|
589 |
|
#endif |
590 |
|
#ifdef LINUX |
591 |
|
f = fopen("/proc/net/dev", "r"); |
592 |
< |
if(f == NULL){ |
593 |
< |
return NULL; |
594 |
< |
} |
592 |
> |
if(f == NULL){ |
593 |
> |
return NULL; |
594 |
> |
} |
595 |
|
|
596 |
|
/* Setup stuff so we can do the ioctl to get the info */ |
597 |
|
if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ |
599 |
|
} |
600 |
|
|
601 |
|
/* Ignore first 2 lines.. Just headings */ |
602 |
< |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
603 |
< |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
602 |
> |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
603 |
> |
if((fgets(line, sizeof(line), f)) == NULL) return NULL; |
604 |
|
|
605 |
< |
while((fgets(line, sizeof(line), f)) != NULL){ |
606 |
< |
char *name, *ptr; |
607 |
< |
struct ifreq ifr; |
608 |
< |
struct ethtool_cmd ethcmd; |
609 |
< |
int err; |
605 |
> |
while((fgets(line, sizeof(line), f)) != NULL){ |
606 |
> |
char *name, *ptr; |
607 |
> |
struct ifreq ifr; |
608 |
> |
struct ethtool_cmd ethcmd; |
609 |
> |
int err; |
610 |
|
|
611 |
|
/* Get the interface name */ |
612 |
< |
ptr = strchr(line, ':'); |
613 |
< |
if (ptr == NULL) continue; |
614 |
< |
*ptr='\0'; |
615 |
< |
name = line; |
616 |
< |
while(isspace(*(name))){ |
617 |
< |
name++; |
618 |
< |
} |
612 |
> |
ptr = strchr(line, ':'); |
613 |
> |
if (ptr == NULL) continue; |
614 |
> |
*ptr='\0'; |
615 |
> |
name = line; |
616 |
> |
while(isspace(*(name))){ |
617 |
> |
name++; |
618 |
> |
} |
619 |
|
|
620 |
< |
memset(&ifr, 0, sizeof ifr); |
621 |
< |
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); |
620 |
> |
memset(&ifr, 0, sizeof ifr); |
621 |
> |
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); |
622 |
|
|
623 |
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { |
624 |
|
continue; |
631 |
|
network_iface_stat_ptr = network_iface_stats + ifaces; |
632 |
|
|
633 |
|
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
634 |
< |
name) < 0) { |
634 |
> |
name) < 0) { |
635 |
|
return NULL; |
636 |
|
} |
637 |
|
if ((ifr.ifr_flags & IFF_UP) != 0) { |
640 |
|
network_iface_stat_ptr->up = 0; |
641 |
|
} |
642 |
|
|
643 |
< |
memset(ðcmd, 0, sizeof ethcmd); |
644 |
< |
ethcmd.cmd = ETHTOOL_GSET; |
645 |
< |
ifr.ifr_data = (caddr_t) ðcmd; |
643 |
> |
memset(ðcmd, 0, sizeof ethcmd); |
644 |
> |
ethcmd.cmd = ETHTOOL_GSET; |
645 |
> |
ifr.ifr_data = (caddr_t) ðcmd; |
646 |
|
|
647 |
< |
err = ioctl(sock, SIOCETHTOOL, &ifr); |
648 |
< |
if (err == 0) { |
647 |
> |
err = ioctl(sock, SIOCETHTOOL, &ifr); |
648 |
> |
if (err == 0) { |
649 |
|
network_iface_stat_ptr->speed = ethcmd.speed; |
650 |
|
|
651 |
|
switch (ethcmd.duplex) { |