sg_get_network_iface_stats(3)
π
sg_get_network_iface_stats(3) β network interface stats, bestie π
okay so this page is literally all about peeking at your network interfaces: their speed, their duplex vibe, and whether they're up. it's giving network detective energy π΅οΈββοΈβ¨
π NAME π
sg_get_network_iface_stats, sg_get_network_iface_stats_r, sg_free_network_iface_stats, sg_network_iface_compare_name β get network interface statistics π
β¨ SYNOPSIS β¨
#include <statgrab.h>
sg_network_iface_stats *sg_get_network_iface_stats (size_t *entries);
sg_network_iface_stats *sg_get_network_iface_stats_r (size_t *entries);
sg_error sg_free_network_iface_stats (sg_network_iface_stats *data);
int sg_network_iface_compare_name (const void *va, const void *vb);
π¦ DESCRIPTION π¦
so the functions sg_get_network_iface_stats() and sg_get_network_iface_stats_r() return statistics about the network interfaces in the machine. specifically, they return the speed of the interface, the duplex state, and whether it is currently up. both functions take an optional entries parameter, which points (when given) to a size_t to take the number of returned vector entries. π
π API Shortcut π
sg_get_network_iface_statsβ returnssg_network_iface_stats *, data owner: libstatgrab (thread local) β¨sg_get_network_iface_stats_rβ returnssg_network_iface_stats *, data owner: caller π
the sg_network_iface_stats vectors received from sg_get_network_iface_stats_r() must be freed using sg_free_network_iface_stats() when not needed any more. the caller is responsible for doing it β yes bestie, that means you π«Ά
additionally a support function for qsort(3) in available: sg_network_iface_compare_name(). (yes, that's what the page says β keep it cute and keep it exact π)
π§ Sort Example π§
size_t entries;
sg_network_iface_stats *network_iface_stats = NULL;
while( NULL != ( network_iface_stats = sg_get_network_iface_stats(&entries) ) ) {
/* order entries alphabetically using the mountpoint */
qsort( network_iface_stats, entries, sizeof(network_iface_stats[0]), &sg_network_iface_compare_name );
show_network_iface_stats( network_iface_stats );
}
π₯ RETURN VALUES π₯
the sg_get_network_iface_stats returns a pointer to a structure of type sg_network_iface_stats.
typedef enum{
SG_IFACE_DUPLEX_FULL,
SG_IFACE_DUPLEX_HALF,
SG_IFACE_DUPLEX_UNKNOWN
}sg_iface_duplex;
note: the SG_IFACE_DUPLEX_UNKNOWN value could mean that duplex hasn't been negotiated yet. π
typedef struct {
char *interface_name;
int speed;
sg_iface_duplex duplex;
int up;
time_t systime;
} sg_network_iface_stats;
interface_nameβ the name known to the operating system. (eg. on linux it might beeth0) π§speedβ the speed of the interface, in megabits/sec. β‘duplexβ the duplex state the interface is in. seesg_iface_duplexfor permitted values. πupβ whether the interface is up. βsystimeβ the timestamp when the above stats where collected in seconds since epoch β°
π BUGS π
getting specific details may require elevated privileges, eg. on Linux the interface speed isn't visible to non-privileged processes. so if speed is acting mysterious, that's why π
the compare functions exist rather for backward compatibility than for functionality enhancements. limited flexibility (e.g. reverse order) and lack of optimising opportunities for the compiler leads to the recommendation to implement the required compare routines locally. ngl, bestie, just roll your own compare routine if you need fancy stuff π
π SEE ALSO π
π WEBSITE π
that's the whole page, bestie π this cutie ships with libstatgrab, dated 2019-03-08 β mwah πβ¨
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms