ifmedia.c (77217) | ifmedia.c (77385) |
---|---|
1/* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem Exp $ */ | 1/* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem Exp $ */ |
2/* $FreeBSD: head/sbin/ifconfig/ifmedia.c 77217 2001-05-26 09:27:08Z phk $ */ | 2/* $FreeBSD: head/sbin/ifconfig/ifmedia.c 77385 2001-05-29 09:13:44Z phk $ */ |
3 4/* 5 * Copyright (c) 1997 Jason R. Thorpe. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 77 unchanged lines hidden (view full) --- 88#include <unistd.h> 89 90#include "ifconfig.h" 91 92static void domediaopt __P((const char *, int, int)); 93static int get_media_subtype __P((int, const char *)); 94static int get_media_options __P((int, const char *)); 95static int lookup_media_word __P((struct ifmedia_description *, const char *)); | 3 4/* 5 * Copyright (c) 1997 Jason R. Thorpe. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 77 unchanged lines hidden (view full) --- 88#include <unistd.h> 89 90#include "ifconfig.h" 91 92static void domediaopt __P((const char *, int, int)); 93static int get_media_subtype __P((int, const char *)); 94static int get_media_options __P((int, const char *)); 95static int lookup_media_word __P((struct ifmedia_description *, const char *)); |
96static void print_media_word __P((int)); | 96static void print_media_word __P((int, int)); 97static void print_media_word_ifconfig __P((int)); |
97 | 98 |
99static struct ifmedia_description *get_toptype_desc __P((int)); 100static struct ifmedia_type_to_subtype *get_toptype_ttos __P((int)); 101static struct ifmedia_description *get_subtype_desc __P((int, 102 struct ifmedia_type_to_subtype *ttos)); 103 |
|
98void 99media_status(s, info) 100 int s; 101 struct rt_addrinfo *info __unused; 102{ 103 struct ifmediareq ifmr; 104 int *media_list, i; 105 --- 16 unchanged lines hidden (view full) --- 122 if (media_list == NULL) 123 err(1, "malloc"); 124 ifmr.ifm_ulist = media_list; 125 126 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) 127 err(1, "SIOCGIFMEDIA"); 128 129 printf("\tmedia: "); | 104void 105media_status(s, info) 106 int s; 107 struct rt_addrinfo *info __unused; 108{ 109 struct ifmediareq ifmr; 110 int *media_list, i; 111 --- 16 unchanged lines hidden (view full) --- 128 if (media_list == NULL) 129 err(1, "malloc"); 130 ifmr.ifm_ulist = media_list; 131 132 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) 133 err(1, "SIOCGIFMEDIA"); 134 135 printf("\tmedia: "); |
130 print_media_word(ifmr.ifm_current); | 136 print_media_word(ifmr.ifm_current, 1); |
131 if (ifmr.ifm_active != ifmr.ifm_current) { 132 putchar(' '); 133 putchar('('); | 137 if (ifmr.ifm_active != ifmr.ifm_current) { 138 putchar(' '); 139 putchar('('); |
134 print_media_word(ifmr.ifm_active); | 140 print_media_word(ifmr.ifm_active, 0); |
135 putchar(')'); 136 } 137 | 141 putchar(')'); 142 } 143 |
144 putchar('\n'); 145 |
|
138 if (ifmr.ifm_status & IFM_AVALID) { | 146 if (ifmr.ifm_status & IFM_AVALID) { |
139 printf(" status: "); | 147 printf("\tstatus: "); |
140 switch (IFM_TYPE(ifmr.ifm_active)) { 141 case IFM_ETHER: 142 if (ifmr.ifm_status & IFM_ACTIVE) 143 printf("active"); 144 else 145 printf("no carrier"); 146 break; 147 --- 11 unchanged lines hidden (view full) --- 159 else 160 printf("no carrier"); 161 break; 162 } 163 } 164 165 putchar('\n'); 166 | 148 switch (IFM_TYPE(ifmr.ifm_active)) { 149 case IFM_ETHER: 150 if (ifmr.ifm_status & IFM_ACTIVE) 151 printf("active"); 152 else 153 printf("no carrier"); 154 break; 155 --- 11 unchanged lines hidden (view full) --- 167 else 168 printf("no carrier"); 169 break; 170 } 171 } 172 173 putchar('\n'); 174 |
167 if (ifmr.ifm_count > 0) { 168 printf("\tsupported media:"); | 175 if (ifmr.ifm_count > 0 && supmedia) { 176 printf("\tsupported media:\n"); |
169 for (i = 0; i < ifmr.ifm_count; i++) { | 177 for (i = 0; i < ifmr.ifm_count; i++) { |
170 putchar(' '); 171 print_media_word(media_list[i]); | 178 printf("\t\t"); 179 print_media_word_ifconfig(media_list[i]); 180 putchar('\n'); |
172 } | 181 } |
173 putchar('\n'); | |
174 } 175 176 free(media_list); 177} 178 179void 180setmedia(val, d, s, afp) 181 const char *val; --- 309 unchanged lines hidden (view full) --- 491 492 for (; desc->ifmt_string != NULL; desc++) 493 if (strcasecmp(desc->ifmt_string, val) == 0) 494 return (desc->ifmt_word); 495 496 return (-1); 497} 498 | 182 } 183 184 free(media_list); 185} 186 187void 188setmedia(val, d, s, afp) 189 const char *val; --- 309 unchanged lines hidden (view full) --- 499 500 for (; desc->ifmt_string != NULL; desc++) 501 if (strcasecmp(desc->ifmt_string, val) == 0) 502 return (desc->ifmt_word); 503 504 return (-1); 505} 506 |
499static void 500print_media_word(ifmw) | 507static struct ifmedia_description *get_toptype_desc(ifmw) |
501 int ifmw; 502{ 503 struct ifmedia_description *desc; | 508 int ifmw; 509{ 510 struct ifmedia_description *desc; |
511 512 for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++) 513 if (IFM_TYPE(ifmw) == desc->ifmt_word) 514 break; 515 516 return desc; 517} 518 519static struct ifmedia_type_to_subtype *get_toptype_ttos(ifmw) 520 int ifmw; 521{ 522 struct ifmedia_description *desc; |
|
504 struct ifmedia_type_to_subtype *ttos; | 523 struct ifmedia_type_to_subtype *ttos; |
505 int seen_option = 0, i; | |
506 | 524 |
507 /* Find the top-level interface type. */ | |
508 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 509 desc->ifmt_string != NULL; desc++, ttos++) 510 if (IFM_TYPE(ifmw) == desc->ifmt_word) 511 break; | 525 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 526 desc->ifmt_string != NULL; desc++, ttos++) 527 if (IFM_TYPE(ifmw) == desc->ifmt_word) 528 break; |
529 530 return ttos; 531} 532 533static struct ifmedia_description *get_subtype_desc(ifmw, ttos) 534 int ifmw; 535 struct ifmedia_type_to_subtype *ttos; 536{ 537 int i; 538 struct ifmedia_description *desc; 539 540 for (i = 0; ttos->subtypes[i].desc != NULL; i++) { 541 if (ttos->subtypes[i].alias) 542 continue; 543 for (desc = ttos->subtypes[i].desc; 544 desc->ifmt_string != NULL; desc++) { 545 if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) 546 return desc; 547 } 548 } 549 550 return NULL; 551} 552 553static void 554print_media_word(ifmw, print_toptype) 555 int ifmw; 556 int print_toptype; 557{ 558 struct ifmedia_description *desc; 559 struct ifmedia_type_to_subtype *ttos; 560 int seen_option = 0, i; 561 562 /* Find the top-level interface type. */ 563 desc = get_toptype_desc(ifmw); 564 ttos = get_toptype_ttos(ifmw); |
|
512 if (desc->ifmt_string == NULL) { 513 printf("<unknown type>"); 514 return; | 565 if (desc->ifmt_string == NULL) { 566 printf("<unknown type>"); 567 return; |
568 } else if (print_toptype) { 569 printf("%s", desc->ifmt_string); |
|
515 } 516 517 /* 518 * Don't print the top-level type; it's not like we can 519 * change it, or anything. 520 */ 521 522 /* Find subtype. */ | 570 } 571 572 /* 573 * Don't print the top-level type; it's not like we can 574 * change it, or anything. 575 */ 576 577 /* Find subtype. */ |
523 for (i = 0; ttos->subtypes[i].desc != NULL; i++) { 524 if (ttos->subtypes[i].alias) 525 continue; 526 for (desc = ttos->subtypes[i].desc; 527 desc->ifmt_string != NULL; desc++) { 528 if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) 529 goto got_subtype; 530 } 531 } | 578 desc = get_subtype_desc(ifmw, ttos); 579 if (desc != NULL) 580 goto got_subtype; |
532 533 /* Falling to here means unknown subtype. */ 534 printf("<unknown subtype>"); 535 return; 536 537 got_subtype: | 581 582 /* Falling to here means unknown subtype. */ 583 printf("<unknown subtype>"); 584 return; 585 586 got_subtype: |
587 if (print_toptype) 588 putchar(' '); 589 |
|
538 printf("%s", desc->ifmt_string); 539 540 /* Find options. */ 541 for (i = 0; ttos->options[i].desc != NULL; i++) { 542 if (ttos->options[i].alias) 543 continue; 544 for (desc = ttos->options[i].desc; 545 desc->ifmt_string != NULL; desc++) { 546 if (ifmw & desc->ifmt_word) { 547 if (seen_option == 0) 548 printf(" <"); 549 printf("%s%s", seen_option++ ? "," : "", 550 desc->ifmt_string); 551 } 552 } 553 } 554 printf("%s", seen_option ? ">" : ""); 555} 556 | 590 printf("%s", desc->ifmt_string); 591 592 /* Find options. */ 593 for (i = 0; ttos->options[i].desc != NULL; i++) { 594 if (ttos->options[i].alias) 595 continue; 596 for (desc = ttos->options[i].desc; 597 desc->ifmt_string != NULL; desc++) { 598 if (ifmw & desc->ifmt_word) { 599 if (seen_option == 0) 600 printf(" <"); 601 printf("%s%s", seen_option++ ? "," : "", 602 desc->ifmt_string); 603 } 604 } 605 } 606 printf("%s", seen_option ? ">" : ""); 607} 608 |
609static void 610print_media_word_ifconfig(ifmw) 611 int ifmw; 612{ 613 struct ifmedia_description *desc; 614 struct ifmedia_type_to_subtype *ttos; 615 int i; 616 617 /* Find the top-level interface type. */ 618 desc = get_toptype_desc(ifmw); 619 ttos = get_toptype_ttos(ifmw); 620 if (desc->ifmt_string == NULL) { 621 printf("<unknown type>"); 622 return; 623 } 624 625 /* 626 * Don't print the top-level type; it's not like we can 627 * change it, or anything. 628 */ 629 630 /* Find subtype. */ 631 desc = get_subtype_desc(ifmw, ttos); 632 if (desc != NULL) 633 goto got_subtype; 634 635 /* Falling to here means unknown subtype. */ 636 printf("<unknown subtype>"); 637 return; 638 639 got_subtype: 640 printf("media %s", desc->ifmt_string); 641 642 /* Find options. */ 643 for (i = 0; ttos->options[i].desc != NULL; i++) { 644 if (ttos->options[i].alias) 645 continue; 646 for (desc = ttos->options[i].desc; 647 desc->ifmt_string != NULL; desc++) { 648 if (ifmw & desc->ifmt_word) { 649 printf(" mediaopt %s", desc->ifmt_string); 650 } 651 } 652 } 653} 654 |
|
557/********************************************************************** 558 * ...until here. 559 **********************************************************************/ | 655/********************************************************************** 656 * ...until here. 657 **********************************************************************/ |