48 |
|
typedef __uint8_t u8; |
49 |
|
typedef __uint16_t u16; |
50 |
|
typedef __uint32_t u32; |
51 |
+ |
typedef __uint64_t u64; |
52 |
|
#include <linux/ethtool.h> |
53 |
|
#include <linux/sockios.h> |
54 |
|
#include <unistd.h> |
412 |
|
} |
413 |
|
network_iface_stat_ptr = network_iface_stats + ifaces; |
414 |
|
|
415 |
+ |
memset(&ifr, 0, sizeof(ifr)); |
416 |
+ |
strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name)); |
417 |
+ |
|
418 |
+ |
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){ |
419 |
+ |
continue; |
420 |
+ |
} |
421 |
+ |
if((ifr.ifr_flags & IFF_UP) != 0){ |
422 |
+ |
network_iface_stat_ptr->up = 1; |
423 |
+ |
}else{ |
424 |
+ |
network_iface_stat_ptr->up = 0; |
425 |
+ |
} |
426 |
+ |
|
427 |
+ |
if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name); |
428 |
+ |
network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name); |
429 |
+ |
if (network_iface_stat_ptr->interface_name == NULL) return NULL; |
430 |
+ |
|
431 |
+ |
network_iface_stat_ptr->speed = 0; |
432 |
+ |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
433 |
+ |
ifaces++; |
434 |
+ |
|
435 |
|
memset(&ifmed, 0, sizeof(struct ifmediareq)); |
436 |
|
strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name)); |
437 |
|
if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){ |
438 |
+ |
/* Not all interfaces support the media ioctls. */ |
439 |
|
continue; |
440 |
|
} |
441 |
|
|
445 |
|
continue; |
446 |
|
} |
447 |
|
|
426 |
– |
if(network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name); |
427 |
– |
network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name); |
428 |
– |
if(network_iface_stat_ptr->interface_name == NULL) return NULL; |
429 |
– |
|
448 |
|
/* Only intrested in the first 4 bits) - Assuming only ETHER devices */ |
449 |
|
x = ifmed.ifm_active & 0x0f; |
450 |
|
switch(x){ |
490 |
|
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
491 |
|
} |
492 |
|
|
475 |
– |
memset(&ifr, 0, sizeof(ifr)); |
476 |
– |
strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name)); |
477 |
– |
|
478 |
– |
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){ |
479 |
– |
continue; |
480 |
– |
} |
481 |
– |
if((ifr.ifr_flags & IFF_UP) != 0){ |
482 |
– |
network_iface_stat_ptr->up = 1; |
483 |
– |
}else{ |
484 |
– |
network_iface_stat_ptr->up = 0; |
485 |
– |
} |
486 |
– |
|
487 |
– |
ifaces++; |
493 |
|
} |
494 |
|
freeifaddrs(net); |
495 |
|
close(sock); |
519 |
|
continue; |
520 |
|
} |
521 |
|
/* Solaris has 1 for up, and 0 for not. As we do too */ |
522 |
< |
network_iface_stat_ptr->up = value.ui32; |
522 |
> |
network_iface_stat_ptr->up = knp->value.ui32; |
523 |
|
|
524 |
|
if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){ |
525 |
|
/* Not a network interface, so skip to the next entry */ |