ifmedia.c (86407) | ifmedia.c (95005) |
---|---|
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 86407 2001-11-15 16:55:39Z asmodai $ */ | 2/* $FreeBSD: head/sbin/ifconfig/ifmedia.c 95005 2002-04-18 17:14:09Z imp $ */ |
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: --- 73 unchanged lines hidden (view full) --- 84#include <fcntl.h> 85#include <stdio.h> 86#include <stdlib.h> 87#include <string.h> 88#include <unistd.h> 89 90#include "ifconfig.h" 91 | 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: --- 73 unchanged lines hidden (view full) --- 84#include <fcntl.h> 85#include <stdio.h> 86#include <stdlib.h> 87#include <string.h> 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, int)); 97static void print_media_word_ifconfig __P((int)); | 92static void domediaopt(const char *, int, int); 93static int get_media_subtype(int, const char *); 94static int get_media_options(int, const char *); 95static int lookup_media_word(struct ifmedia_description *, const char *); 96static void print_media_word(int, int); 97static void print_media_word_ifconfig(int); |
98 | 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)); | 99static struct ifmedia_description *get_toptype_desc(int); 100static struct ifmedia_type_to_subtype *get_toptype_ttos(int); 101static struct ifmedia_description *get_subtype_desc(int, 102 struct ifmedia_type_to_subtype *ttos); |
103 104void | 103 104void |
105media_status(s, info) 106 int s; 107 struct rt_addrinfo *info __unused; | 105media_status(int s, struct rt_addrinfo *info __unused) |
108{ 109 struct ifmediareq ifmr; 110 int *media_list, i; 111 112 (void) memset(&ifmr, 0, sizeof(ifmr)); 113 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 114 115 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { --- 63 unchanged lines hidden (view full) --- 179 putchar('\n'); 180 } 181 } 182 183 free(media_list); 184} 185 186void | 106{ 107 struct ifmediareq ifmr; 108 int *media_list, i; 109 110 (void) memset(&ifmr, 0, sizeof(ifmr)); 111 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 112 113 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { --- 63 unchanged lines hidden (view full) --- 177 putchar('\n'); 178 } 179 } 180 181 free(media_list); 182} 183 184void |
187setmedia(val, d, s, afp) 188 const char *val; 189 int d; 190 int s; 191 const struct afswtch *afp; | 185setmedia(const char *val, int d, int s, const struct afswtch *afp) |
192{ 193 struct ifmediareq ifmr; 194 int first_type, subtype; 195 196 (void) memset(&ifmr, 0, sizeof(ifmr)); 197 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 198 199 ifmr.ifm_count = 1; --- 25 unchanged lines hidden (view full) --- 225 ifr.ifr_media = (ifmr.ifm_current & ~(IFM_NMASK|IFM_TMASK)) | 226 IFM_TYPE(first_type) | subtype; 227 228 if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0) 229 err(1, "SIOCSIFMEDIA"); 230} 231 232void | 186{ 187 struct ifmediareq ifmr; 188 int first_type, subtype; 189 190 (void) memset(&ifmr, 0, sizeof(ifmr)); 191 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 192 193 ifmr.ifm_count = 1; --- 25 unchanged lines hidden (view full) --- 219 ifr.ifr_media = (ifmr.ifm_current & ~(IFM_NMASK|IFM_TMASK)) | 220 IFM_TYPE(first_type) | subtype; 221 222 if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0) 223 err(1, "SIOCSIFMEDIA"); 224} 225 226void |
233setmediaopt(val, d, s, afp) 234 const char *val; 235 int d; 236 int s; 237 const struct afswtch *afp; | 227setmediaopt(const char *val, int d, int s, const struct afswtch *afp) |
238{ 239 240 domediaopt(val, 0, s); 241} 242 243void | 228{ 229 230 domediaopt(val, 0, s); 231} 232 233void |
244unsetmediaopt(val, d, s, afp) 245 const char *val; 246 int d; 247 int s; 248 const struct afswtch *afp; | 234unsetmediaopt(const char *val, int d, int s, const struct afswtch *afp) |
249{ 250 251 domediaopt(val, 1, s); 252} 253 254static void | 235{ 236 237 domediaopt(val, 1, s); 238} 239 240static void |
255domediaopt(val, clear, s) 256 const char *val; 257 int clear; 258 int s; | 241domediaopt(const char *val, int clear, int s) |
259{ 260 struct ifmediareq ifmr; 261 int *mwords, options; 262 263 (void) memset(&ifmr, 0, sizeof(ifmr)); 264 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 265 266 /* --- 150 unchanged lines hidden (view full) --- 417 { &ifm_shared_option_descriptions[0], 0 }, 418 { &ifm_subtype_ieee80211_option_descriptions[0], 0 }, 419 { NULL, 0 }, 420 }, 421 }, 422}; 423 424static int | 242{ 243 struct ifmediareq ifmr; 244 int *mwords, options; 245 246 (void) memset(&ifmr, 0, sizeof(ifmr)); 247 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 248 249 /* --- 150 unchanged lines hidden (view full) --- 400 { &ifm_shared_option_descriptions[0], 0 }, 401 { &ifm_subtype_ieee80211_option_descriptions[0], 0 }, 402 { NULL, 0 }, 403 }, 404 }, 405}; 406 407static int |
425get_media_subtype(type, val) 426 int type; 427 const char *val; | 408get_media_subtype(int type, const char *val) |
428{ 429 struct ifmedia_description *desc; 430 struct ifmedia_type_to_subtype *ttos; 431 int rval, i; 432 433 /* Find the top-level interface type. */ 434 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 435 desc->ifmt_string != NULL; desc++, ttos++) --- 7 unchanged lines hidden (view full) --- 443 if (rval != -1) 444 return (rval); 445 } 446 errx(1, "unknown media subtype: %s", val); 447 /* NOTREACHED */ 448} 449 450static int | 409{ 410 struct ifmedia_description *desc; 411 struct ifmedia_type_to_subtype *ttos; 412 int rval, i; 413 414 /* Find the top-level interface type. */ 415 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 416 desc->ifmt_string != NULL; desc++, ttos++) --- 7 unchanged lines hidden (view full) --- 424 if (rval != -1) 425 return (rval); 426 } 427 errx(1, "unknown media subtype: %s", val); 428 /* NOTREACHED */ 429} 430 431static int |
451get_media_options(type, val) 452 int type; 453 const char *val; | 432get_media_options(int type, const char *val) |
454{ 455 struct ifmedia_description *desc; 456 struct ifmedia_type_to_subtype *ttos; 457 char *optlist, *optptr; 458 int option = 0, i, rval = 0; 459 460 /* We muck with the string, so copy it. */ 461 optlist = strdup(val); --- 24 unchanged lines hidden (view full) --- 486 rval |= option; 487 } 488 489 free(optlist); 490 return (rval); 491} 492 493static int | 433{ 434 struct ifmedia_description *desc; 435 struct ifmedia_type_to_subtype *ttos; 436 char *optlist, *optptr; 437 int option = 0, i, rval = 0; 438 439 /* We muck with the string, so copy it. */ 440 optlist = strdup(val); --- 24 unchanged lines hidden (view full) --- 465 rval |= option; 466 } 467 468 free(optlist); 469 return (rval); 470} 471 472static int |
494lookup_media_word(desc, val) 495 struct ifmedia_description *desc; 496 const char *val; | 473lookup_media_word(struct ifmedia_description *desc, const char *val) |
497{ 498 499 for (; desc->ifmt_string != NULL; desc++) 500 if (strcasecmp(desc->ifmt_string, val) == 0) 501 return (desc->ifmt_word); 502 503 return (-1); 504} 505 | 474{ 475 476 for (; desc->ifmt_string != NULL; desc++) 477 if (strcasecmp(desc->ifmt_string, val) == 0) 478 return (desc->ifmt_word); 479 480 return (-1); 481} 482 |
506static struct ifmedia_description *get_toptype_desc(ifmw) 507 int ifmw; | 483static struct ifmedia_description *get_toptype_desc(int ifmw) |
508{ 509 struct ifmedia_description *desc; 510 511 for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++) 512 if (IFM_TYPE(ifmw) == desc->ifmt_word) 513 break; 514 515 return desc; 516} 517 | 484{ 485 struct ifmedia_description *desc; 486 487 for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++) 488 if (IFM_TYPE(ifmw) == desc->ifmt_word) 489 break; 490 491 return desc; 492} 493 |
518static struct ifmedia_type_to_subtype *get_toptype_ttos(ifmw) 519 int ifmw; | 494static struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw) |
520{ 521 struct ifmedia_description *desc; 522 struct ifmedia_type_to_subtype *ttos; 523 524 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 525 desc->ifmt_string != NULL; desc++, ttos++) 526 if (IFM_TYPE(ifmw) == desc->ifmt_word) 527 break; 528 529 return ttos; 530} 531 | 495{ 496 struct ifmedia_description *desc; 497 struct ifmedia_type_to_subtype *ttos; 498 499 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; 500 desc->ifmt_string != NULL; desc++, ttos++) 501 if (IFM_TYPE(ifmw) == desc->ifmt_word) 502 break; 503 504 return ttos; 505} 506 |
532static struct ifmedia_description *get_subtype_desc(ifmw, ttos) 533 int ifmw; 534 struct ifmedia_type_to_subtype *ttos; | 507static struct ifmedia_description *get_subtype_desc(int ifmw, 508 struct ifmedia_type_to_subtype *ttos) |
535{ 536 int i; 537 struct ifmedia_description *desc; 538 539 for (i = 0; ttos->subtypes[i].desc != NULL; i++) { 540 if (ttos->subtypes[i].alias) 541 continue; 542 for (desc = ttos->subtypes[i].desc; 543 desc->ifmt_string != NULL; desc++) { 544 if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) 545 return desc; 546 } 547 } 548 549 return NULL; 550} 551 552static void | 509{ 510 int i; 511 struct ifmedia_description *desc; 512 513 for (i = 0; ttos->subtypes[i].desc != NULL; i++) { 514 if (ttos->subtypes[i].alias) 515 continue; 516 for (desc = ttos->subtypes[i].desc; 517 desc->ifmt_string != NULL; desc++) { 518 if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) 519 return desc; 520 } 521 } 522 523 return NULL; 524} 525 526static void |
553print_media_word(ifmw, print_toptype) 554 int ifmw; 555 int print_toptype; | 527print_media_word(int ifmw, int print_toptype) |
556{ 557 struct ifmedia_description *desc; 558 struct ifmedia_type_to_subtype *ttos; 559 int seen_option = 0, i; 560 561 /* Find the top-level interface type. */ 562 desc = get_toptype_desc(ifmw); 563 ttos = get_toptype_ttos(ifmw); --- 37 unchanged lines hidden (view full) --- 601 desc->ifmt_string); 602 } 603 } 604 } 605 printf("%s", seen_option ? ">" : ""); 606} 607 608static void | 528{ 529 struct ifmedia_description *desc; 530 struct ifmedia_type_to_subtype *ttos; 531 int seen_option = 0, i; 532 533 /* Find the top-level interface type. */ 534 desc = get_toptype_desc(ifmw); 535 ttos = get_toptype_ttos(ifmw); --- 37 unchanged lines hidden (view full) --- 573 desc->ifmt_string); 574 } 575 } 576 } 577 printf("%s", seen_option ? ">" : ""); 578} 579 580static void |
609print_media_word_ifconfig(ifmw) 610 int ifmw; | 581print_media_word_ifconfig(int ifmw) |
611{ 612 struct ifmedia_description *desc; 613 struct ifmedia_type_to_subtype *ttos; 614 int i; 615 616 /* Find the top-level interface type. */ 617 desc = get_toptype_desc(ifmw); 618 ttos = get_toptype_ttos(ifmw); --- 38 unchanged lines hidden --- | 582{ 583 struct ifmedia_description *desc; 584 struct ifmedia_type_to_subtype *ttos; 585 int i; 586 587 /* Find the top-level interface type. */ 588 desc = get_toptype_desc(ifmw); 589 ttos = get_toptype_ttos(ifmw); --- 38 unchanged lines hidden --- |