network: handle multiple addresses on same interface.
This commit is contained in:
parent
3c2b50adea
commit
ff4a80bd87
|
@ -54,8 +54,8 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned long incoming;
|
uint64_t incoming;
|
||||||
unsigned long outgoing;
|
uint64_t outgoing;
|
||||||
} network_t;
|
} network_t;
|
||||||
|
|
||||||
typedef struct Sys_Info Sys_Info;
|
typedef struct Sys_Info Sys_Info;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
#if defined(__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
static void
|
static void
|
||||||
_freebsd_generic_network_status(unsigned long int *in,
|
_freebsd_generic_network_status(uint64_t *in,
|
||||||
unsigned long int *out)
|
uint64_t *out)
|
||||||
{
|
{
|
||||||
struct ifmibdata *ifmd;
|
struct ifmibdata *ifmd;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -50,8 +50,8 @@ _freebsd_generic_network_status(unsigned long int *in,
|
||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
static void
|
static void
|
||||||
_openbsd_generic_network_status(unsigned long int *in,
|
_openbsd_generic_network_status(uint64_t *in,
|
||||||
unsigned long int *out)
|
uint64_t *out)
|
||||||
{
|
{
|
||||||
struct ifaddrs *interfaces, *ifa;
|
struct ifaddrs *interfaces, *ifa;
|
||||||
|
|
||||||
|
@ -66,12 +66,21 @@ _openbsd_generic_network_status(unsigned long int *in,
|
||||||
struct ifreq ifreq;
|
struct ifreq ifreq;
|
||||||
struct if_data if_data;
|
struct if_data if_data;
|
||||||
|
|
||||||
|
// TBC: Interfaces can have multiple addresses.
|
||||||
|
// Using this netmask check we should be obtaining
|
||||||
|
// the overall interface data across addresses.
|
||||||
|
|
||||||
|
if (ifa->ifa_netmask != 0) continue;
|
||||||
|
|
||||||
ifreq.ifr_data = (void *)&if_data;
|
ifreq.ifr_data = (void *)&if_data;
|
||||||
strncpy(ifreq.ifr_name, ifa->ifa_name, IFNAMSIZ - 1);
|
strncpy(ifreq.ifr_name, ifa->ifa_name, IFNAMSIZ - 1);
|
||||||
if (ioctl(sock, SIOCGIFDATA, &ifreq) < 0)
|
if (ioctl(sock, SIOCGIFDATA, &ifreq) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct if_data *const ifi = &if_data;
|
const struct if_data *ifi = &if_data;
|
||||||
|
if (!LINK_STATE_IS_UP(ifi->ifi_link_state))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (ifi->ifi_type == IFT_ETHER ||
|
if (ifi->ifi_type == IFT_ETHER ||
|
||||||
ifi->ifi_type == IFT_FASTETHER ||
|
ifi->ifi_type == IFT_FASTETHER ||
|
||||||
ifi->ifi_type == IFT_GIGABITETHERNET ||
|
ifi->ifi_type == IFT_GIGABITETHERNET ||
|
||||||
|
@ -92,8 +101,8 @@ _openbsd_generic_network_status(unsigned long int *in,
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
static void
|
static void
|
||||||
_linux_generic_network_status(unsigned long int *in,
|
_linux_generic_network_status(uint64_t *in,
|
||||||
unsigned long int *out)
|
uint64_t *out)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char buf[4096], dummy_s[256];
|
char buf[4096], dummy_s[256];
|
||||||
|
@ -123,8 +132,8 @@ _linux_generic_network_status(unsigned long int *in,
|
||||||
void
|
void
|
||||||
system_network_transfer_get(network_t *usage)
|
system_network_transfer_get(network_t *usage)
|
||||||
{
|
{
|
||||||
unsigned long first_in = 0, first_out = 0;
|
uint64_t first_in = 0, first_out = 0;
|
||||||
unsigned long last_in = 0, last_out = 0;
|
uint64_t last_in = 0, last_out = 0;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
_linux_generic_network_status(&first_in, &first_out);
|
_linux_generic_network_status(&first_in, &first_out);
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
|
|
Loading…
Reference in New Issue