| 71 |
|
#include <unistd.h> |
| 72 |
|
#endif |
| 73 |
|
|
| 74 |
< |
static void network_stat_init(network_stat_t *s) { |
| 74 |
> |
static void network_stat_init(sg_network_io_stats *s) { |
| 75 |
|
s->interface_name = NULL; |
| 76 |
|
s->tx = 0; |
| 77 |
|
s->rx = 0; |
| 82 |
|
s->collisions = 0; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
< |
static void network_stat_destroy(network_stat_t *s) { |
| 85 |
> |
static void network_stat_destroy(sg_network_io_stats *s) { |
| 86 |
|
free(s->interface_name); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
< |
VECTOR_DECLARE_STATIC(network_stats, network_stat_t, 5, |
| 89 |
> |
VECTOR_DECLARE_STATIC(network_stats, sg_network_io_stats, 5, |
| 90 |
|
network_stat_init, network_stat_destroy); |
| 91 |
|
|
| 92 |
< |
network_stat_t *get_network_stats(int *entries){ |
| 92 |
> |
sg_network_io_stats *sg_get_network_io_stats(int *entries){ |
| 93 |
|
int interfaces; |
| 94 |
< |
network_stat_t *network_stat_ptr; |
| 94 |
> |
sg_network_io_stats *network_stat_ptr; |
| 95 |
|
|
| 96 |
|
#ifdef SOLARIS |
| 97 |
|
kstat_ctl_t *kc; |
| 126 |
|
} |
| 127 |
|
network_stat_ptr=network_stats+interfaces; |
| 128 |
|
|
| 129 |
< |
if (update_string(&network_stat_ptr->interface_name, |
| 130 |
< |
net_ptr->ifa_name) == NULL) { |
| 129 |
> |
if (sg_update_string(&network_stat_ptr->interface_name, |
| 130 |
> |
net_ptr->ifa_name) == NULL) { |
| 131 |
|
return NULL; |
| 132 |
|
} |
| 133 |
|
net_data=(struct if_data *)net_ptr->ifa_data; |
| 226 |
|
network_stat_ptr->collisions=knp->value.ui32; |
| 227 |
|
|
| 228 |
|
/* Read interface name */ |
| 229 |
< |
if (update_string(&network_stat_ptr->interface_name, |
| 230 |
< |
ksp->ks_name) == NULL) { |
| 229 |
> |
if (sg_update_string(&network_stat_ptr->interface_name, |
| 230 |
> |
ksp->ks_name) == NULL) { |
| 231 |
|
return NULL; |
| 232 |
|
} |
| 233 |
|
|
| 270 |
|
free(network_stat_ptr->interface_name); |
| 271 |
|
} |
| 272 |
|
|
| 273 |
< |
network_stat_ptr->interface_name=get_string_match(line, &line_match[1]); |
| 274 |
< |
network_stat_ptr->rx=get_ll_match(line, &line_match[2]); |
| 275 |
< |
network_stat_ptr->tx=get_ll_match(line, &line_match[5]); |
| 276 |
< |
network_stat_ptr->ipackets=get_ll_match(line, &line_match[3]); |
| 277 |
< |
network_stat_ptr->opackets=get_ll_match(line, &line_match[6]); |
| 278 |
< |
network_stat_ptr->ierrors=get_ll_match(line, &line_match[4]); |
| 279 |
< |
network_stat_ptr->oerrors=get_ll_match(line, &line_match[7]); |
| 280 |
< |
network_stat_ptr->collisions=get_ll_match(line, &line_match[8]); |
| 273 |
> |
network_stat_ptr->interface_name=sg_get_string_match(line, &line_match[1]); |
| 274 |
> |
network_stat_ptr->rx=sg_get_ll_match(line, &line_match[2]); |
| 275 |
> |
network_stat_ptr->tx=sg_get_ll_match(line, &line_match[5]); |
| 276 |
> |
network_stat_ptr->ipackets=sg_get_ll_match(line, &line_match[3]); |
| 277 |
> |
network_stat_ptr->opackets=sg_get_ll_match(line, &line_match[6]); |
| 278 |
> |
network_stat_ptr->ierrors=sg_get_ll_match(line, &line_match[4]); |
| 279 |
> |
network_stat_ptr->oerrors=sg_get_ll_match(line, &line_match[7]); |
| 280 |
> |
network_stat_ptr->collisions=sg_get_ll_match(line, &line_match[8]); |
| 281 |
|
network_stat_ptr->systime=time(NULL); |
| 282 |
|
|
| 283 |
|
interfaces++; |
| 296 |
|
return network_stats; |
| 297 |
|
} |
| 298 |
|
|
| 299 |
< |
long long transfer_diff(long long new, long long old){ |
| 299 |
> |
static long long transfer_diff(long long new, long long old){ |
| 300 |
|
#if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD) || defined(OPENBSD) |
| 301 |
|
/* 32-bit quantities, so we must explicitly deal with wraparound. */ |
| 302 |
|
#define MAXVAL 0x100000000LL |
| 311 |
|
#endif |
| 312 |
|
} |
| 313 |
|
|
| 314 |
< |
network_stat_t *get_network_stats_diff(int *entries) { |
| 315 |
< |
VECTOR_DECLARE_STATIC(diff, network_stat_t, 1, |
| 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); |
| 317 |
< |
network_stat_t *src = NULL, *dest; |
| 317 |
> |
sg_network_io_stats *src = NULL, *dest; |
| 318 |
|
int i, j, diff_count, new_count; |
| 319 |
|
|
| 320 |
|
if (network_stats == NULL) { |
| 321 |
|
/* No previous stats, so we can't calculate a difference. */ |
| 322 |
< |
return get_network_stats(entries); |
| 322 |
> |
return sg_get_network_io_stats(entries); |
| 323 |
|
} |
| 324 |
|
|
| 325 |
|
/* Resize the results array to match the previous stats. */ |
| 333 |
|
src = &network_stats[i]; |
| 334 |
|
dest = &diff[i]; |
| 335 |
|
|
| 336 |
< |
if (update_string(&dest->interface_name, |
| 337 |
< |
src->interface_name) == NULL) { |
| 336 |
> |
if (sg_update_string(&dest->interface_name, |
| 337 |
> |
src->interface_name) == NULL) { |
| 338 |
|
return NULL; |
| 339 |
|
} |
| 340 |
|
dest->rx = src->rx; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
/* Get a new set of stats. */ |
| 351 |
< |
if (get_network_stats(&new_count) == NULL) { |
| 351 |
> |
if (sg_get_network_io_stats(&new_count) == NULL) { |
| 352 |
|
return NULL; |
| 353 |
|
} |
| 354 |
|
|
| 388 |
|
|
| 389 |
|
/* NETWORK INTERFACE STATS */ |
| 390 |
|
|
| 391 |
< |
static void network_iface_stat_init(network_iface_stat_t *s) { |
| 391 |
> |
static void network_iface_stat_init(sg_network_iface_stats *s) { |
| 392 |
|
s->interface_name = NULL; |
| 393 |
|
s->speed = 0; |
| 394 |
< |
s->dup = UNKNOWN_DUPLEX; |
| 394 |
> |
s->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 395 |
|
} |
| 396 |
|
|
| 397 |
< |
static void network_iface_stat_destroy(network_iface_stat_t *s) { |
| 397 |
> |
static void network_iface_stat_destroy(sg_network_iface_stats *s) { |
| 398 |
|
free(s->interface_name); |
| 399 |
|
} |
| 400 |
|
|
| 401 |
< |
network_iface_stat_t *get_network_iface_stats(int *entries){ |
| 402 |
< |
VECTOR_DECLARE_STATIC(network_iface_stats, network_iface_stat_t, 5, |
| 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); |
| 404 |
< |
network_iface_stat_t *network_iface_stat_ptr; |
| 404 |
> |
sg_network_iface_stats *network_iface_stat_ptr; |
| 405 |
|
int ifaces = 0; |
| 406 |
|
|
| 407 |
|
#ifdef SOLARIS |
| 451 |
|
network_iface_stat_ptr->up = 0; |
| 452 |
|
} |
| 453 |
|
|
| 454 |
< |
if (update_string(&network_iface_stat_ptr->interface_name, |
| 455 |
< |
net_ptr->ifa_name) == NULL) { |
| 454 |
> |
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
| 455 |
> |
net_ptr->ifa_name) == NULL) { |
| 456 |
|
return NULL; |
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
network_iface_stat_ptr->speed = 0; |
| 460 |
< |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
| 460 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 461 |
|
ifaces++; |
| 462 |
|
|
| 463 |
|
memset(&ifmed, 0, sizeof(struct ifmediareq)); |
| 464 |
< |
strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name)); |
| 464 |
> |
sg_strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name)); |
| 465 |
|
if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){ |
| 466 |
|
/* Not all interfaces support the media ioctls. */ |
| 467 |
|
continue; |
| 514 |
|
} |
| 515 |
|
|
| 516 |
|
if( (ifmed.ifm_active | IFM_FDX) == ifmed.ifm_active ){ |
| 517 |
< |
network_iface_stat_ptr->dup = FULL_DUPLEX; |
| 517 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL; |
| 518 |
|
}else if( (ifmed.ifm_active | IFM_HDX) == ifmed.ifm_active ){ |
| 519 |
< |
network_iface_stat_ptr->dup = HALF_DUPLEX; |
| 519 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF; |
| 520 |
|
}else{ |
| 521 |
< |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
| 521 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
} |
| 553 |
|
network_iface_stat_ptr = network_iface_stats + ifaces; |
| 554 |
|
ifaces++; |
| 555 |
|
|
| 556 |
< |
if (update_string(&network_iface_stat_ptr->interface_name, |
| 557 |
< |
ksp->ks_name) == NULL) { |
| 556 |
> |
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
| 557 |
> |
ksp->ks_name) == NULL) { |
| 558 |
|
return NULL; |
| 559 |
|
} |
| 560 |
|
|
| 570 |
|
network_iface_stat_ptr->speed = 0; |
| 571 |
|
} |
| 572 |
|
|
| 573 |
< |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
| 573 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 574 |
|
if ((knp = kstat_data_lookup(ksp, "link_duplex")) != NULL) { |
| 575 |
|
switch (knp->value.ui32) { |
| 576 |
|
case 1: |
| 577 |
< |
network_iface_stat_ptr->dup = HALF_DUPLEX; |
| 577 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF; |
| 578 |
|
break; |
| 579 |
|
case 2: |
| 580 |
< |
network_iface_stat_ptr->dup = FULL_DUPLEX; |
| 580 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL; |
| 581 |
|
break; |
| 582 |
|
} |
| 583 |
|
} |
| 630 |
|
} |
| 631 |
|
network_iface_stat_ptr = network_iface_stats + ifaces; |
| 632 |
|
|
| 633 |
< |
if (update_string(&network_iface_stat_ptr->interface_name, |
| 634 |
< |
name) == NULL) { |
| 633 |
> |
if (sg_update_string(&network_iface_stat_ptr->interface_name, |
| 634 |
> |
name) == NULL) { |
| 635 |
|
return NULL; |
| 636 |
|
} |
| 637 |
|
if ((ifr.ifr_flags & IFF_UP) != 0) { |
| 650 |
|
|
| 651 |
|
switch (ethcmd.duplex) { |
| 652 |
|
case 0x00: |
| 653 |
< |
network_iface_stat_ptr->dup = FULL_DUPLEX; |
| 653 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_FULL; |
| 654 |
|
break; |
| 655 |
|
case 0x01: |
| 656 |
< |
network_iface_stat_ptr->dup = HALF_DUPLEX; |
| 656 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_HALF; |
| 657 |
|
break; |
| 658 |
|
default: |
| 659 |
< |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
| 659 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 660 |
|
} |
| 661 |
|
} else { |
| 662 |
|
/* Not all interfaces support the ethtool ioctl. */ |
| 663 |
|
network_iface_stat_ptr->speed = 0; |
| 664 |
< |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
| 664 |
> |
network_iface_stat_ptr->dup = SG_IFACE_DUPLEX_UNKNOWN; |
| 665 |
|
} |
| 666 |
|
|
| 667 |
|
ifaces++; |