From c204b5ccda4e15217b5928abdf0c51961b2b3403 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 3 Sep 2007 03:00:22 +0000 Subject: [PATCH] add net_interface_flags_to_string --- include/sigar_format.h | 2 ++ src/sigar_format.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/sigar_format.h b/include/sigar_format.h index 31b4d538..c9f0dc31 100644 --- a/include/sigar_format.h +++ b/include/sigar_format.h @@ -40,5 +40,7 @@ SIGAR_DECLARE(const char *)sigar_net_connection_type_get(int type); SIGAR_DECLARE(const char *)sigar_net_connection_state_get(int state); +SIGAR_DECLARE(char *) sigar_net_interface_flags_to_string(sigar_uint64_t flags, char *buf); + #endif diff --git a/src/sigar_format.c b/src/sigar_format.c index 99ecc609..22f1d9f3 100644 --- a/src/sigar_format.c +++ b/src/sigar_format.c @@ -478,3 +478,44 @@ SIGAR_DECLARE(const char *)sigar_net_connection_state_get(int state) } } +SIGAR_DECLARE(char *) sigar_net_interface_flags_to_string(sigar_uint64_t flags, char *buf) +{ + if (flags == 0) { + strcat(buf, "[NO FLAGS] "); + } + if (flags & SIGAR_IFF_UP) { + strcat(buf, "UP "); + } + if (flags & SIGAR_IFF_BROADCAST) { + strcat(buf, "BROADCAST "); + } + if (flags & SIGAR_IFF_DEBUG) { + strcat(buf, "DEBUG "); + } + if (flags & SIGAR_IFF_LOOPBACK) { + strcat(buf, "LOOPBACK "); + } + if (flags & SIGAR_IFF_POINTOPOINT) { + strcat(buf, "POINTOPOINT "); + } + if (flags & SIGAR_IFF_NOTRAILERS) { + strcat(buf, "NOTRAILERS "); + } + if (flags & SIGAR_IFF_RUNNING) { + strcat(buf, "RUNNING "); + } + if (flags & SIGAR_IFF_NOARP) { + strcat(buf, "NOARP "); + } + if (flags & SIGAR_IFF_PROMISC) { + strcat(buf, "PROMISC "); + } + if (flags & SIGAR_IFF_ALLMULTI) { + strcat(buf, "ALLMULTI "); + } + if (flags & SIGAR_IFF_MULTICAST) { + strcat(buf, "MULTICAST "); + } + + return buf; +}