void conf_print_media_word(FILE *output, int ifmw) { const struct ifmedia_description *desc; int seen_option = 0; fprintf(output, " media %s", get_media_subtype_string(ifmw)); if (IFM_INST(ifmw) != 0) printf(" %llu", IFM_INST(ifmw)); fprintf(output, "\n"); /* Find options. */ for (desc = ifm_option_descriptions; desc->ifmt_string != NULL; desc++) { if (IFM_TYPE_MATCH(desc->ifmt_word, ifmw) && (IFM_OPTIONS(ifmw) & IFM_OPTIONS(desc->ifmt_word)) != 0 && (seen_option & IFM_OPTIONS(desc->ifmt_word)) == 0) { if (seen_option == 0) fprintf(output, " mediaopt "); fprintf(output, "%s%s", seen_option ? "," : "", desc->ifmt_string); seen_option |= IFM_OPTIONS(desc->ifmt_word); } } if (seen_option) fprintf(output, "\n"); }
/* Fill in defaults network values for the selected interface */ static void get_ifinterface_info(void) { struct ifreq ifr; struct ifmediareq ifmr; struct sockaddr_in *sa_in = (void*)&ifr.ifr_addr; int modew; const char *media_opt; const char *sep; if (do_ifreq(&ifr, SIOCGIFADDR) == 0 && sa_in->sin_addr.s_addr != 0) strlcpy(net_ip, inet_ntoa(sa_in->sin_addr), sizeof net_ip); if (do_ifreq(&ifr, SIOCGIFNETMASK) == 0 && sa_in->sin_addr.s_addr != 0) strlcpy(net_mask, inet_ntoa(sa_in->sin_addr), sizeof net_mask); if (do_ifmreq(&ifmr, SIOCGIFMEDIA) == 0) { /* Get the name of the media word */ modew = ifmr.ifm_current; strlcpy(net_media, get_media_subtype_string(modew), sizeof net_media); /* and add any media options */ sep = " mediaopt "; while ((media_opt = get_media_option_string(&modew)) != NULL) { strlcat(net_media, sep, sizeof net_media); strlcat(net_media, media_opt, sizeof net_media); sep = ","; } } }
void print_media_word(uint64_t ifmw, int print_type, int as_syntax) { const struct ifmedia_description *desc; uint64_t seen_option = 0; if (print_type) printf("%s ", get_media_type_string(ifmw)); printf("%s%s", as_syntax ? "media " : "", get_media_subtype_string(ifmw)); if (IFM_INST(ifmw) != 0) printf(" %lld", IFM_INST(ifmw)); /* Find options. */ for (desc = ifm_option_descriptions; desc->ifmt_string != NULL; desc++) { if (IFM_TYPE_MATCH(desc->ifmt_word, ifmw) && (IFM_OPTIONS(ifmw) & IFM_OPTIONS(desc->ifmt_word)) != 0 && (seen_option & IFM_OPTIONS(desc->ifmt_word)) == 0) { if (seen_option == 0) printf("%s", as_syntax ? ", mediaopt " : " "); printf("%s%s", seen_option ? "," : "", desc->ifmt_string); seen_option |= IFM_OPTIONS(desc->ifmt_word); } } }