| 561 | } |
| 562 | |
| 563 | static int |
| 564 | get_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 | |
| 605 | static int |
| 606 | lookup_media_word(struct ifmedia_description *desc, const char *val) |
no test coverage detected