diff options
author | Jasper Lievisse Adriaanse <jasper@humppa.nl> | 2012-10-08 22:13:47 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-10-10 08:24:04 +0200 |
commit | 11c4ab9870174505786696b0da0331d53067fe1f (patch) | |
tree | 7f146aba1baf06d1d4339fc1b10c593e6348b852 /src/print_eth_info.c | |
parent | 8da0452d2c51826fd871520f7a8ba7a43a59401c (diff) |
Implement %speed for Ethernet on OpenBSD.
Diffstat (limited to 'src/print_eth_info.c')
-rw-r--r-- | src/print_eth_info.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/print_eth_info.c b/src/print_eth_info.c index 941b465..d09873e 100644 --- a/src/print_eth_info.c +++ b/src/print_eth_info.c @@ -25,7 +25,11 @@ (IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t))) #define PART_ETHSPEED "E: %s (%s)" +#endif +#if defined(__OpenBSD__) +#include <errno.h> +#include <net/if_media.h> #endif static int print_eth_speed(char *outwalk, const char *interface) { @@ -65,6 +69,38 @@ static int print_eth_speed(char *outwalk, const char *interface) { } ethspeed = (desc->ifmt_string != NULL ? desc->ifmt_string : "?"); return sprintf(outwalk, "%s", ethspeed); +#elif defined(__OpenBSD__) + char *ethspeed; + struct ifmediareq ifmr; + + (void) memset(&ifmr, 0, sizeof(ifmr)); + (void) strlcpy(ifmr.ifm_name, interface, sizeof(ifmr.ifm_name)); + + if (ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { + if (errno != E2BIG) + return sprintf(outwalk, "?"); + } + + struct ifmedia_description *desc; + struct ifmedia_description ifm_subtype_descriptions[] = + IFM_SUBTYPE_DESCRIPTIONS; + + for (desc = ifm_subtype_descriptions; desc->ifmt_string != NULL; desc++) { + /* + * Skip these non-informative values and go right ahead to the + * actual speeds. + */ + if (strncmp(desc->ifmt_string, "autoselect", strlen("autoselect")) == 0 || + strncmp(desc->ifmt_string, "auto", strlen("auto")) == 0) + continue; + + if (IFM_TYPE_MATCH(desc->ifmt_word, ifmr.ifm_active) && + IFM_SUBTYPE(desc->ifmt_word) == IFM_SUBTYPE(ifmr.ifm_active)) + break; + } + ethspeed = (desc->ifmt_string != NULL ? desc->ifmt_string : "?"); + return sprintf(outwalk, "%s", ethspeed); + #else return sprintf(outwalk, "?"); #endif |