411 |
|
} |
412 |
|
network_iface_stat_ptr = network_iface_stats + ifaces; |
413 |
|
|
414 |
+ |
memset(&ifr, 0, sizeof(ifr)); |
415 |
+ |
strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name)); |
416 |
+ |
|
417 |
+ |
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){ |
418 |
+ |
continue; |
419 |
+ |
} |
420 |
+ |
if((ifr.ifr_flags & IFF_UP) != 0){ |
421 |
+ |
network_iface_stat_ptr->up = 1; |
422 |
+ |
}else{ |
423 |
+ |
network_iface_stat_ptr->up = 0; |
424 |
+ |
} |
425 |
+ |
|
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 |
+ |
|
430 |
+ |
network_iface_stat_ptr->speed = 0; |
431 |
+ |
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
432 |
+ |
ifaces++; |
433 |
+ |
|
434 |
|
memset(&ifmed, 0, sizeof(struct ifmediareq)); |
435 |
|
strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name)); |
436 |
|
if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){ |
437 |
+ |
/* Not all interfaces support the media ioctls. */ |
438 |
|
continue; |
439 |
|
} |
440 |
|
|
444 |
|
continue; |
445 |
|
} |
446 |
|
|
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 |
– |
|
447 |
|
/* Only intrested in the first 4 bits) - Assuming only ETHER devices */ |
448 |
|
x = ifmed.ifm_active & 0x0f; |
449 |
|
switch(x){ |
489 |
|
network_iface_stat_ptr->dup = UNKNOWN_DUPLEX; |
490 |
|
} |
491 |
|
|
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++; |
492 |
|
} |
493 |
|
freeifaddrs(net); |
494 |
|
close(sock); |