From c8fe052e748f9d4e961db07ad8d4fc657c1d8d12 Mon Sep 17 00:00:00 2001 From: roy Date: Wed, 14 Sep 2016 11:46:43 +0000 Subject: [PATCH] Don't bail if SIOGIFMEDIA doesn't return any media lists because we can still report link status. --- sbin/ifconfig/media.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/sbin/ifconfig/media.c b/sbin/ifconfig/media.c index b945cb3489a0..bde79daf26e9 100644 --- a/sbin/ifconfig/media.c +++ b/sbin/ifconfig/media.c @@ -1,6 +1,6 @@ #include #ifndef lint -__RCSID("$NetBSD: media.c,v 1.6 2011/08/29 14:35:00 joerg Exp $"); +__RCSID("$NetBSD: media.c,v 1.7 2016/09/14 11:46:43 roy Exp $"); #endif /* not lint */ #include @@ -371,27 +371,27 @@ media_status(prop_dictionary_t env, prop_dictionary_t oenv) return; } - if (ifmr.ifm_count == 0) { - warnx("%s: no media types?", ifname); - return; - } + /* Interface link status is queried through SIOCGIFMEDIA. + * Not all interfaces have actual media. */ + if (ifmr.ifm_count != 0) { + media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); + if (media_list == NULL) + err(EXIT_FAILURE, "malloc"); + ifmr.ifm_ulist = media_list; - media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); - if (media_list == NULL) - err(EXIT_FAILURE, "malloc"); - ifmr.ifm_ulist = media_list; + if (prog_ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) + err(EXIT_FAILURE, "SIOCGIFMEDIA"); - if (prog_ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) - err(EXIT_FAILURE, "SIOCGIFMEDIA"); - - printf("\tmedia: %s ", get_media_type_string(ifmr.ifm_current)); - print_media_word(ifmr.ifm_current, " "); - if (ifmr.ifm_active != ifmr.ifm_current) { - printf(" ("); - print_media_word(ifmr.ifm_active, " "); - printf(")"); - } - printf("\n"); + printf("\tmedia: %s ", get_media_type_string(ifmr.ifm_current)); + print_media_word(ifmr.ifm_current, " "); + if (ifmr.ifm_active != ifmr.ifm_current) { + printf(" ("); + print_media_word(ifmr.ifm_active, " "); + printf(")"); + } + printf("\n"); + } else + media_list = NULL; if (ifmr.ifm_status & IFM_STATUS_VALID) { const struct ifmedia_status_description *ifms;