MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_media_options

Function get_media_options

tools/ifconfig/ifmedia.c:563–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561}
562
563static int
564get_media_options(int type, const char *val)
565{
566 struct ifmedia_description *desc;
567 struct ifmedia_type_to_subtype *ttos;
568 char *optlist, *optptr;
569 int option, i, rval = 0;
570
571 /* We muck with the string, so copy it. */
572 optlist = strdup(val);
573 if (optlist == NULL)
574 err(1, "strdup");
575
576 /* Find the top-level interface type. */
577 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
578 desc->ifmt_string != NULL; desc++, ttos++)
579 if (type == desc->ifmt_word)
580 break;
581 if (desc->ifmt_string == NULL)
582 errx(1, "unknown media type 0x%x", type);
583
584 /*
585 * Look up the options in the user-provided comma-separated
586 * list.
587 */
588 optptr = optlist;
589 for (; (optptr = strtok(optptr, ",")) != NULL; optptr = NULL) {
590 option = -1;
591 for (i = 0; ttos->options[i].desc != NULL; i++) {
592 option = lookup_media_word(ttos->options[i].desc, optptr);
593 if (option != -1)
594 break;
595 }
596 if (option == -1)
597 errx(1, "unknown option: %s", optptr);
598 rval |= option;
599 }
600
601 free(optlist);
602 return (rval);
603}
604
605static int
606lookup_media_word(struct ifmedia_description *desc, const char *val)

Callers 1

domediaoptFunction · 0.85

Calls 4

strdupFunction · 0.85
strtokFunction · 0.85
lookup_media_wordFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected