diff options
author | Ryan Moeller <freqlabs@FreeBSD.org> | 2021-03-02 10:29:17 +0000 |
---|---|---|
committer | Ryan Moeller <freqlabs@FreeBSD.org> | 2021-03-19 13:00:19 +0000 |
commit | 534e161747f80d6c972577a24b8ad22f6a5d60c4 (patch) | |
tree | 3ebcbc115c2ad480fbc7ddd24626ee1ac8f2e04a /share/examples/libifconfig | |
parent | 6bbca5ca3a6634fc10b93da203df2ae92cf60b61 (diff) |
libifconfig: Overhaul ifconfig_media_* interfaces
Define an ifmedia_t type to use for ifmedia words.
Add ifconfig_media_lookup_* functions to lookup ifmedia words by name.
Get media options as an array of option names rather than formatting it
as a comma-delimited list into a buffer.
Sprinkle const on static the static description tables for peace of
mind.
Don't need to zero memory allocated by calloc.
Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D29029
(cherry picked from commit c4ba4aa547184ab401204096cdad9def4ab37964)
Diffstat (limited to 'share/examples/libifconfig')
-rw-r--r-- | share/examples/libifconfig/status.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/share/examples/libifconfig/status.c b/share/examples/libifconfig/status.c index 62fd3f35c8de..114cf7e87a68 100644 --- a/share/examples/libifconfig/status.c +++ b/share/examples/libifconfig/status.c @@ -406,7 +406,6 @@ print_media(ifconfig_handle_t *lifh, struct ifaddrs *ifa) * tables, finding an entry with the right media subtype */ struct ifmediareq *ifmr; - char opts[80]; if (ifconfig_media_get_mediareq(lifh, ifa->ifa_name, &ifmr) != 0) { if (ifconfig_err_errtype(lifh) != OK) { @@ -419,14 +418,19 @@ print_media(ifconfig_handle_t *lifh, struct ifaddrs *ifa) printf("\tmedia: %s %s", ifconfig_media_get_type(ifmr->ifm_current), ifconfig_media_get_subtype(ifmr->ifm_current)); if (ifmr->ifm_active != ifmr->ifm_current) { + const char **options; + printf(" (%s", ifconfig_media_get_subtype(ifmr->ifm_active)); - ifconfig_media_get_options_string(ifmr->ifm_active, opts, - sizeof(opts)); - if (opts[0] != '\0') { - printf(" <%s>)\n", opts); + options = ifconfig_media_get_options(ifmr->ifm_active); + if (options != NULL && options[0] != NULL) { + printf(" <%s", options[0]); + for (size_t i = 1; options[i] != NULL; ++i) + printf(",%s", options[i]); + printf(">)\n"); } else { printf(")\n"); } + free(options); } else { printf("\n"); } @@ -438,15 +442,20 @@ print_media(ifconfig_handle_t *lifh, struct ifaddrs *ifa) printf("\tsupported media:\n"); for (i = 0; i < ifmr->ifm_count; i++) { + const char **options; + printf("\t\tmedia %s", ifconfig_media_get_subtype(ifmr->ifm_ulist[i])); - ifconfig_media_get_options_string(ifmr->ifm_ulist[i], opts, - sizeof(opts)); - if (opts[0] != '\0') { - printf(" mediaopt %s\n", opts); + options = ifconfig_media_get_options(ifmr->ifm_ulist[i]); + if (options != NULL && options[0] != NULL) { + printf(" mediaopt %s", options[0]); + for (size_t i = 1; options[i] != NULL; ++i) + printf(",%s", options[i]); + printf("\n"); } else { printf("\n"); } + free(options); } free(ifmr); } |