From brooks@minya.sea.one-eyed-alien.net  Sun May 27 23:11:18 2001
Return-Path: <brooks@minya.sea.one-eyed-alien.net>
Received: from minya.sea.one-eyed-alien.net (minya.sea.one-eyed-alien.net [216.39.168.226])
	by hub.freebsd.org (Postfix) with ESMTP id 37D5637B43C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 27 May 2001 23:11:15 -0700 (PDT)
	(envelope-from brooks@minya.sea.one-eyed-alien.net)
Received: by minya.sea.one-eyed-alien.net (Postfix, from userid 1001)
	id 8678524D23; Sun, 27 May 2001 23:12:56 -0700 (PDT)
Message-Id: <20010528061256.8678524D23@minya.sea.one-eyed-alien.net>
Date: Sun, 27 May 2001 23:12:56 -0700 (PDT)
From: brooks@one-eyed-alien.net
Reply-To: brooks@one-eyed-alien.net
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] ifconfig: supported media looks bad :  wastes space
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27701
>Category:       bin
>Synopsis:       [PATCH] ifconfig: supported media looks bad & wastes space
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 27 23:20:01 PDT 2001
>Closed-Date:    Tue May 29 02:14:01 PDT 2001
>Last-Modified:  Tue May 29 02:15:05 PDT 2001
>Originator:     Brooks Davis
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD minya.sea.one-eyed-alien.net 5.0-CURRENT FreeBSD 5.0-CURRENT #4: Thu May 24 23:05:23 PDT 2001 root@minya.sea.one-eyed-alien.net:/usr/src/sys/compile/MINYA i386

>Description:

When using interfaces that support if_media, the supported media list is
printed on a single, very long, and generally unreadable line.  This
isn't very useful.  It's also really ugly and most of the time you don't
care what media is supported anyway.

>How-To-Repeat:

Type the following on any system with an interface that uses if_media:

$ ifconfig

>Fix:

This patch makes the printing of supported media dependent on the -m
flag and prints the options one per line.  The concept was obtained from
NetBSD (actually, I first saw it on an OpenBSD box, but if_media is a
NetBSD thing and I used their manpages as a refrence.)

Index: ifconfig.8
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.38
diff -u -r1.38 ifconfig.8
--- ifconfig.8	2001/05/26 09:26:01	1.38
+++ ifconfig.8	2001/05/28 06:00:18
@@ -41,6 +41,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl L
+.Op Fl m
 .Ar interface
 .Op Ar address_family
 .Oo
@@ -52,6 +53,7 @@
 .Fl a
 .Op Fl L
 .Op Fl d
+.Op Fl m
 .Op Fl u
 .Op Ar address_family
 .Nm
@@ -62,6 +64,7 @@
 .Nm
 .Op Fl L
 .Op Fl d
+.Op Fl m
 .Op Fl u
 .Sh DESCRIPTION
 .Nm Ifconfig
@@ -530,6 +533,10 @@
 If the driver does supports the media selection system, the supported
 media list will be included in the output.
 .Pp
+If the
+.Fl m
+flag is passed before an interface name, ifconfig will display all
+of the supported media for the specified interface.
 If
 .Fl L
 flag is supplied, address lifetime is displayed for IPv6 addresses,
Index: ifconfig.c
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.61
diff -u -r1.61 ifconfig.c
--- ifconfig.c	2001/05/26 09:26:01	1.61
+++ ifconfig.c	2001/05/28 05:45:19
@@ -134,6 +134,8 @@
 
 struct	afswtch;
 
+int supmedia = 0;
+
 #ifdef INET6
 char	addr_buf[MAXHOSTNAMELEN *2 + 1];	/*for getnameinfo()*/
 #endif
@@ -351,16 +353,16 @@
 	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
 	"usage: ifconfig interface address_family [address [dest_address]]",
 	"                [parameters]",
-	"       ifconfig -a [-d] [-u] [address_family]",
+	"       ifconfig -a [-d] [-m] [-u] [address_family]",
 	"       ifconfig -l [-d] [-u] [address_family]",
-	"       ifconfig [-d] [-u]");
+	"       ifconfig [-d] [-m] [-u]");
 #else
 	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
 	"usage: ifconfig [-L] interface address_family [address [dest_address]]",
 	"                [parameters]",
-	"       ifconfig -a [-L] [-d] [-u] [address_family]",
+	"       ifconfig -a [-L] [-d] [-m] [-u] [address_family]",
 	"       ifconfig -l [-d] [-u] [address_family]",
-	"       ifconfig [-L] [-d] [-u]");
+	"       ifconfig [-L] [-d] [-m] [-u]");
 #endif
 	exit(1);
 }
@@ -410,7 +412,7 @@
 			uponly++;
 			break;
 		case 'm':	/* show media choices in status */
-			/* ignored for compatibility */
+			supmedia = 1;
 			break;
 		default:
 			usage();
@@ -421,7 +423,7 @@
 	argv += optind;
 
 	/* -l cannot be used with -a or -m */
-	if (namesonly && all)
+	if (namesonly && (all || supmedia))
 		usage();
 
 	/* nonsense.. */
Index: ifconfig.h
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.h,v
retrieving revision 1.6
diff -u -r1.6 ifconfig.h
--- ifconfig.h	2001/05/26 09:26:01	1.6
+++ ifconfig.h	2001/05/28 05:39:35
@@ -38,6 +38,7 @@
 
 extern char name[32];	/* name of interface */
 extern int allmedia;
+extern int supmedia;
 struct afswtch;
 
 extern void setmedia(const char *, int, int, const struct afswtch *rafp);
Index: ifmedia.c
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifmedia.c,v
retrieving revision 1.7
diff -u -r1.7 ifmedia.c
--- ifmedia.c	2001/05/26 09:26:01	1.7
+++ ifmedia.c	2001/05/28 05:42:09
@@ -164,13 +164,13 @@
 
 	putchar('\n');
 
-	if (ifmr.ifm_count > 0) {
-		printf("\tsupported media:");
+	if (ifmr.ifm_count > 0 && supmedia) {
+		printf("\tsupported media:\n");
 		for (i = 0; i < ifmr.ifm_count; i++) {
-			putchar(' ');
+			printf("\t\t");
 			print_media_word(media_list[i]);
+			putchar('\n');
 		}
-		putchar('\n');
 	}
 
 	free(media_list);
>Release-Note:
>Audit-Trail:

From: Brooks Davis <brooks@one-eyed-alien.net>
To: brooks@one-eyed-alien.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/27701: [PATCH] ifconfig: supported media looks bad :  wastes space
Date: Sun, 27 May 2001 23:25:04 -0700

 --Dxnq1zWXvFF0Q93v
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Oops, I just realized that I didn't complete the formatting upgrade in
 that patch.  The following extra snipit finishes it:
 
 
 --- ifmedia.c.orig	Sun May 27 23:23:16 2001
 +++ ifmedia.c	Sun May 27 23:22:32 2001
 @@ -502,7 +502,7 @@
  {
  	struct ifmedia_description *desc;
  	struct ifmedia_type_to_subtype *ttos;
 -	int seen_option =3D 0, i;
 +	int i;
 =20
  	/* Find the top-level interface type. */
  	for (desc =3D ifm_type_descriptions, ttos =3D ifmedia_types_to_subtypes;
 @@ -535,7 +535,7 @@
  	return;
 =20
   got_subtype:
 -	printf("%s", desc->ifmt_string);
 +	printf("media %s", desc->ifmt_string);
 =20
  	/* Find options. */
  	for (i =3D 0; ttos->options[i].desc !=3D NULL; i++) {
 @@ -544,14 +544,10 @@
  		for (desc =3D ttos->options[i].desc;
  		    desc->ifmt_string !=3D NULL; desc++) {
  			if (ifmw & desc->ifmt_word) {
 -				if (seen_option =3D=3D 0)
 -					printf(" <");
 -				printf("%s%s", seen_option++ ? "," : "",
 -				    desc->ifmt_string);
 +				printf(" mediaopt %s", desc->ifmt_string);
  			}
  		}
  	}
 -	printf("%s", seen_option ? ">" : "");
  }
 =20
  /**********************************************************************
 
 --=20
 Any statement of the form "X is the one, true Y" is FALSE.
 PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
 
 --Dxnq1zWXvFF0Q93v
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.4 (GNU/Linux)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE7Ee9AXY6L6fI4GtQRAvrwAKCb+ZoVDK+byqYdLfH/Z9Oo9AmiOACfcEpL
 eXeSY56RGOWuYaSImQRHcDw=
 =mDuq
 -----END PGP SIGNATURE-----
 
 --Dxnq1zWXvFF0Q93v--
State-Changed-From-To: open->feedback 
State-Changed-By: phk 
State-Changed-When: Mon May 28 13:37:56 PDT 2001 
State-Changed-Why:  
Patch suffers from formatting problems. 
Waiting for improved patch from originator. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27701 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: brooks@one-eyed-alien.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/27701: [PATCH] ifconfig: supported media looks bad : wastes space 
Date: Mon, 28 May 2001 22:37:38 +0200

 I tried to apply your patch, but it seems to screw up the formatting,
 even with your 2nd patch, can you try to produce a fixed patch ?
 
 I think Ideally I would like it to look something like this for ifconfig -m:
 
 fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
         inet 212.242.86.142 netmask 0xffffffe0 broadcast 212.242.86.159
         ether 00:e0:81:01:9d:2c 
         media: autoselect(100baseTX) mediaopt (full-duplex) status: active
 # The () values on the media: line being actual values shown only
 # if different from configured values.
         supported media:
                 autoselect {full-duplex,half-duplex}
 # don't show flag0... which can be set on all interfaces.
                 100baseTX {full-duplex,half-duplex}
                 100baseTX {full-duplex,half-duplex}
                 10baseT/UTP {full-duplex,half-duplex}
                 10baseT/UTP {full-duplex,half-duplex}
                 100baseTX {full-duplex,half-duplex}
 
 
 -- 
 Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
 phk@FreeBSD.ORG         | TCP/IP since RFC 956
 FreeBSD committer       | BSD since 4.3-tahoe    
 Never attribute to malice what can adequately be explained by incompetence.

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/27701: [PATCH] ifconfig: supported media looks bad : wastes space
Date: Mon, 28 May 2001 18:26:40 -0700

 --BOKacYhQ+x31HxR3
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Mon, May 28, 2001 at 10:37:38PM +0200, Poul-Henning Kamp wrote:
 >=20
 > I tried to apply your patch, but it seems to screw up the formatting,
 > even with your 2nd patch, can you try to produce a fixed patch ?
 
 I've attached an updated patch below.  The flaw in the previous one was
 using the same code to print both supported and current media types.
 The new output looks like this:
 
 tx0: flags=3D8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
         inet 216.39.168.226 netmask 0xfffffff0 broadcast 216.39.168.239
         ether 00:e0:29:27:50:95
 # The () part is only displayed if the settings differ (that should have
 # been the case before.)  Following the example of the OpenBSD box I've
 # been using as an example, I added the disply of the top level media
 # type.
         media: Ethernet autoselect (100baseTX <full-duplex>)
         status: active
 # Net and OpenBSD display the supported options this way rather then in
 # the older "mediatype <option1,option2> style.  I think it's more
 # useful since it gives the administrator something to copy and paste.
         supported media:
                 media autoselect
                 media 100baseTX mediaopt full-duplex
                 media 100baseTX
                 media 10baseT/UTP mediaopt full-duplex
                 media 10baseT/UTP
 
 -- Brooks
 
 --=20
 Any statement of the form "X is the one, true Y" is FALSE.
 PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
 
 Index: ifconfig.8
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.8,v
 retrieving revision 1.38
 diff -u -r1.38 ifconfig.8
 --- ifconfig.8	2001/05/26 09:26:01	1.38
 +++ ifconfig.8	2001/05/29 00:28:09
 @@ -41,6 +41,7 @@
  .Sh SYNOPSIS
  .Nm
  .Op Fl L
 +.Op Fl m
  .Ar interface
  .Op Ar address_family
  .Oo
 @@ -52,6 +53,7 @@
  .Fl a
  .Op Fl L
  .Op Fl d
 +.Op Fl m
  .Op Fl u
  .Op Ar address_family
  .Nm
 @@ -62,6 +64,7 @@
  .Nm
  .Op Fl L
  .Op Fl d
 +.Op Fl m
  .Op Fl u
  .Sh DESCRIPTION
  .Nm Ifconfig
 @@ -530,6 +533,10 @@
  If the driver does supports the media selection system, the supported
  media list will be included in the output.
  .Pp
 +If the
 +.Fl m
 +flag is passed before an interface name, ifconfig will display all
 +of the supported media for the specified interface.
  If
  .Fl L
  flag is supplied, address lifetime is displayed for IPv6 addresses,
 Index: ifconfig.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
 retrieving revision 1.61
 diff -u -r1.61 ifconfig.c
 --- ifconfig.c	2001/05/26 09:26:01	1.61
 +++ ifconfig.c	2001/05/29 00:28:09
 @@ -134,6 +134,8 @@
 =20
  struct	afswtch;
 =20
 +int supmedia =3D 0;
 +
  #ifdef INET6
  char	addr_buf[MAXHOSTNAMELEN *2 + 1];	/*for getnameinfo()*/
  #endif
 @@ -351,16 +353,16 @@
  	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  	"usage: ifconfig interface address_family [address [dest_address]]",
  	"                [parameters]",
 -	"       ifconfig -a [-d] [-u] [address_family]",
 +	"       ifconfig -a [-d] [-m] [-u] [address_family]",
  	"       ifconfig -l [-d] [-u] [address_family]",
 -	"       ifconfig [-d] [-u]");
 +	"       ifconfig [-d] [-m] [-u]");
  #else
  	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  	"usage: ifconfig [-L] interface address_family [address [dest_address]]",
  	"                [parameters]",
 -	"       ifconfig -a [-L] [-d] [-u] [address_family]",
 +	"       ifconfig -a [-L] [-d] [-m] [-u] [address_family]",
  	"       ifconfig -l [-d] [-u] [address_family]",
 -	"       ifconfig [-L] [-d] [-u]");
 +	"       ifconfig [-L] [-d] [-m] [-u]");
  #endif
  	exit(1);
  }
 @@ -410,7 +412,7 @@
  			uponly++;
  			break;
  		case 'm':	/* show media choices in status */
 -			/* ignored for compatibility */
 +			supmedia =3D 1;
  			break;
  		default:
  			usage();
 @@ -421,7 +423,7 @@
  	argv +=3D optind;
 =20
  	/* -l cannot be used with -a or -m */
 -	if (namesonly && all)
 +	if (namesonly && (all || supmedia))
  		usage();
 =20
  	/* nonsense.. */
 Index: ifconfig.h
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.h,v
 retrieving revision 1.6
 diff -u -r1.6 ifconfig.h
 --- ifconfig.h	2001/05/26 09:26:01	1.6
 +++ ifconfig.h	2001/05/29 00:28:09
 @@ -38,6 +38,7 @@
 =20
  extern char name[32];	/* name of interface */
  extern int allmedia;
 +extern int supmedia;
  struct afswtch;
 =20
  extern void setmedia(const char *, int, int, const struct afswtch *rafp);
 Index: ifmedia.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /home/ncvs/src/sbin/ifconfig/ifmedia.c,v
 retrieving revision 1.7
 diff -u -r1.7 ifmedia.c
 --- ifmedia.c	2001/05/26 09:26:01	1.7
 +++ ifmedia.c	2001/05/29 01:15:21
 @@ -93,8 +93,14 @@
  static int	get_media_subtype __P((int, const char *));
  static int	get_media_options __P((int, const char *));
  static int	lookup_media_word __P((struct ifmedia_description *, const char=
  *));
 -static void	print_media_word __P((int));
 +static void	print_media_word __P((int, int));
 +static void	print_media_word_ifconfig __P((int));
 =20
 +static struct ifmedia_description *get_toptype_desc __P((int));
 +static struct ifmedia_type_to_subtype *get_toptype_ttos __P((int));
 +static struct ifmedia_description *get_subtype_desc __P((int,
 +    struct ifmedia_type_to_subtype *ttos));
 +
  void
  media_status(s, info)
  	int s;
 @@ -127,16 +133,18 @@
  		err(1, "SIOCGIFMEDIA");
 =20
  	printf("\tmedia: ");
 -	print_media_word(ifmr.ifm_current);
 +	print_media_word(ifmr.ifm_current, 1);
  	if (ifmr.ifm_active !=3D ifmr.ifm_current) {
  		putchar(' ');
  		putchar('(');
 -		print_media_word(ifmr.ifm_active);
 +		print_media_word(ifmr.ifm_active, 0);
  		putchar(')');
  	}
 =20
 +	putchar('\n');
 +
  	if (ifmr.ifm_status & IFM_AVALID) {
 -		printf(" status: ");
 +		printf("\tstatus: ");
  		switch (IFM_TYPE(ifmr.ifm_active)) {
  		case IFM_ETHER:
  			if (ifmr.ifm_status & IFM_ACTIVE)
 @@ -164,13 +172,13 @@
 =20
  	putchar('\n');
 =20
 -	if (ifmr.ifm_count > 0) {
 -		printf("\tsupported media:");
 +	if (ifmr.ifm_count > 0 && supmedia) {
 +		printf("\tsupported media:\n");
  		for (i =3D 0; i < ifmr.ifm_count; i++) {
 -			putchar(' ');
 -			print_media_word(media_list[i]);
 +			printf("\t\t");
 +			print_media_word_ifconfig(media_list[i]);
 +			putchar('\n');
  		}
 -		putchar('\n');
  	}
 =20
  	free(media_list);
 @@ -496,22 +504,69 @@
  	return (-1);
  }
 =20
 -static void
 -print_media_word(ifmw)
 +static struct ifmedia_description *get_toptype_desc(ifmw)
  	int ifmw;
  {
  	struct ifmedia_description *desc;
 +
 +	for (desc =3D ifm_type_descriptions; desc->ifmt_string !=3D NULL; desc++)
 +		if (IFM_TYPE(ifmw) =3D=3D desc->ifmt_word)
 +			break;
 +
 +	return desc;
 +}
 +
 +static struct ifmedia_type_to_subtype *get_toptype_ttos(ifmw)
 +	int ifmw;
 +{
 +	struct ifmedia_description *desc;
  	struct ifmedia_type_to_subtype *ttos;
 -	int seen_option =3D 0, i;
 =20
 -	/* Find the top-level interface type. */
  	for (desc =3D ifm_type_descriptions, ttos =3D ifmedia_types_to_subtypes;
  	    desc->ifmt_string !=3D NULL; desc++, ttos++)
  		if (IFM_TYPE(ifmw) =3D=3D desc->ifmt_word)
  			break;
 +
 +	return ttos;
 +}
 +
 +static struct ifmedia_description *get_subtype_desc(ifmw, ttos)
 +	int ifmw;
 +	struct ifmedia_type_to_subtype *ttos;
 +{
 +	int i;
 +	struct ifmedia_description *desc;
 +
 +	for (i =3D 0; ttos->subtypes[i].desc !=3D NULL; i++) {
 +		if (ttos->subtypes[i].alias)
 +			continue;
 +		for (desc =3D ttos->subtypes[i].desc;
 +		    desc->ifmt_string !=3D NULL; desc++) {
 +			if (IFM_SUBTYPE(ifmw) =3D=3D desc->ifmt_word)
 +				return desc;
 +		}
 +	}
 +
 +	return NULL;
 +}
 +
 +static void
 +print_media_word(ifmw, print_toptype)
 +	int ifmw;
 +	int print_toptype;
 +{
 +	struct ifmedia_description *desc;
 +	struct ifmedia_type_to_subtype *ttos;
 +	int seen_option =3D 0, i;
 +
 +	/* Find the top-level interface type. */
 +	desc =3D get_toptype_desc(ifmw);
 +	ttos =3D get_toptype_ttos(ifmw);
  	if (desc->ifmt_string =3D=3D NULL) {
  		printf("<unknown type>");
  		return;
 +	} else if (print_toptype) {
 +		printf("%s", desc->ifmt_string);
  	}
 =20
  	/*
 @@ -520,21 +575,18 @@
  	 */
 =20
  	/* Find subtype. */
 -	for (i =3D 0; ttos->subtypes[i].desc !=3D NULL; i++) {
 -		if (ttos->subtypes[i].alias)
 -			continue;
 -		for (desc =3D ttos->subtypes[i].desc;
 -		    desc->ifmt_string !=3D NULL; desc++) {
 -			if (IFM_SUBTYPE(ifmw) =3D=3D desc->ifmt_word)
 -				goto got_subtype;
 -		}
 -	}
 +	desc =3D get_subtype_desc(ifmw, ttos);
 +	if (desc !=3D NULL)
 +		goto got_subtype;
 =20
  	/* Falling to here means unknown subtype. */
  	printf("<unknown subtype>");
  	return;
 =20
   got_subtype:
 +	if (print_toptype)
 +		putchar(' ');
 +
  	printf("%s", desc->ifmt_string);
 =20
  	/* Find options. */
 @@ -552,6 +604,52 @@
  		}
  	}
  	printf("%s", seen_option ? ">" : "");
 +}
 +
 +static void
 +print_media_word_ifconfig(ifmw)
 +	int ifmw;
 +{
 +	struct ifmedia_description *desc;
 +	struct ifmedia_type_to_subtype *ttos;
 +	int i;
 +
 +	/* Find the top-level interface type. */
 +	desc =3D get_toptype_desc(ifmw);
 +	ttos =3D get_toptype_ttos(ifmw);
 +	if (desc->ifmt_string =3D=3D NULL) {
 +		printf("<unknown type>");
 +		return;
 +	}
 +
 +	/*
 +	 * Don't print the top-level type; it's not like we can
 +	 * change it, or anything.
 +	 */
 +
 +	/* Find subtype. */
 +	desc =3D get_subtype_desc(ifmw, ttos);
 +	if (desc !=3D NULL)
 +		goto got_subtype;
 +
 +	/* Falling to here means unknown subtype. */
 +	printf("<unknown subtype>");
 +	return;
 +
 + got_subtype:
 +	printf("media %s", desc->ifmt_string);
 +
 +	/* Find options. */
 +	for (i =3D 0; ttos->options[i].desc !=3D NULL; i++) {
 +		if (ttos->options[i].alias)
 +			continue;
 +		for (desc =3D ttos->options[i].desc;
 +		    desc->ifmt_string !=3D NULL; desc++) {
 +			if (ifmw & desc->ifmt_word) {
 +				printf(" mediaopt %s", desc->ifmt_string);
 +			}
 +		}
 +	}
  }
 =20
  /**********************************************************************
 
 --BOKacYhQ+x31HxR3
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.4 (GNU/Linux)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE7EvrPXY6L6fI4GtQRAoyoAKDXiqZrZ/7On0m8ymDao3tk0ANnzwCgyHPJ
 3c4TB3gcdodZDtUmBeFThzo=
 =bGDT
 -----END PGP SIGNATURE-----
 
 --BOKacYhQ+x31HxR3--

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc: brooks@one-eyed-alien.net, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/27701: [PATCH] ifconfig: supported media looks bad : wastes space
Date: Mon, 28 May 2001 18:32:29 -0700

 Hmm, it looks like gnats doesn't like signed mail.  Here's an unsigned
 message with the patch.
 
 
 Index: ifconfig.8
 ===================================================================
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.8,v
 retrieving revision 1.38
 diff -u -r1.38 ifconfig.8
 --- ifconfig.8	2001/05/26 09:26:01	1.38
 +++ ifconfig.8	2001/05/29 00:28:09
 @@ -41,6 +41,7 @@
  .Sh SYNOPSIS
  .Nm
  .Op Fl L
 +.Op Fl m
  .Ar interface
  .Op Ar address_family
  .Oo
 @@ -52,6 +53,7 @@
  .Fl a
  .Op Fl L
  .Op Fl d
 +.Op Fl m
  .Op Fl u
  .Op Ar address_family
  .Nm
 @@ -62,6 +64,7 @@
  .Nm
  .Op Fl L
  .Op Fl d
 +.Op Fl m
  .Op Fl u
  .Sh DESCRIPTION
  .Nm Ifconfig
 @@ -530,6 +533,10 @@
  If the driver does supports the media selection system, the supported
  media list will be included in the output.
  .Pp
 +If the
 +.Fl m
 +flag is passed before an interface name, ifconfig will display all
 +of the supported media for the specified interface.
  If
  .Fl L
  flag is supplied, address lifetime is displayed for IPv6 addresses,
 Index: ifconfig.c
 ===================================================================
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
 retrieving revision 1.61
 diff -u -r1.61 ifconfig.c
 --- ifconfig.c	2001/05/26 09:26:01	1.61
 +++ ifconfig.c	2001/05/29 00:28:09
 @@ -134,6 +134,8 @@
  
  struct	afswtch;
  
 +int supmedia = 0;
 +
  #ifdef INET6
  char	addr_buf[MAXHOSTNAMELEN *2 + 1];	/*for getnameinfo()*/
  #endif
 @@ -351,16 +353,16 @@
  	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  	"usage: ifconfig interface address_family [address [dest_address]]",
  	"                [parameters]",
 -	"       ifconfig -a [-d] [-u] [address_family]",
 +	"       ifconfig -a [-d] [-m] [-u] [address_family]",
  	"       ifconfig -l [-d] [-u] [address_family]",
 -	"       ifconfig [-d] [-u]");
 +	"       ifconfig [-d] [-m] [-u]");
  #else
  	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  	"usage: ifconfig [-L] interface address_family [address [dest_address]]",
  	"                [parameters]",
 -	"       ifconfig -a [-L] [-d] [-u] [address_family]",
 +	"       ifconfig -a [-L] [-d] [-m] [-u] [address_family]",
  	"       ifconfig -l [-d] [-u] [address_family]",
 -	"       ifconfig [-L] [-d] [-u]");
 +	"       ifconfig [-L] [-d] [-m] [-u]");
  #endif
  	exit(1);
  }
 @@ -410,7 +412,7 @@
  			uponly++;
  			break;
  		case 'm':	/* show media choices in status */
 -			/* ignored for compatibility */
 +			supmedia = 1;
  			break;
  		default:
  			usage();
 @@ -421,7 +423,7 @@
  	argv += optind;
  
  	/* -l cannot be used with -a or -m */
 -	if (namesonly && all)
 +	if (namesonly && (all || supmedia))
  		usage();
  
  	/* nonsense.. */
 Index: ifconfig.h
 ===================================================================
 RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.h,v
 retrieving revision 1.6
 diff -u -r1.6 ifconfig.h
 --- ifconfig.h	2001/05/26 09:26:01	1.6
 +++ ifconfig.h	2001/05/29 00:28:09
 @@ -38,6 +38,7 @@
  
  extern char name[32];	/* name of interface */
  extern int allmedia;
 +extern int supmedia;
  struct afswtch;
  
  extern void setmedia(const char *, int, int, const struct afswtch *rafp);
 Index: ifmedia.c
 ===================================================================
 RCS file: /home/ncvs/src/sbin/ifconfig/ifmedia.c,v
 retrieving revision 1.7
 diff -u -r1.7 ifmedia.c
 --- ifmedia.c	2001/05/26 09:26:01	1.7
 +++ ifmedia.c	2001/05/29 01:15:21
 @@ -93,8 +93,14 @@
  static int	get_media_subtype __P((int, const char *));
  static int	get_media_options __P((int, const char *));
  static int	lookup_media_word __P((struct ifmedia_description *, const char *));
 -static void	print_media_word __P((int));
 +static void	print_media_word __P((int, int));
 +static void	print_media_word_ifconfig __P((int));
  
 +static struct ifmedia_description *get_toptype_desc __P((int));
 +static struct ifmedia_type_to_subtype *get_toptype_ttos __P((int));
 +static struct ifmedia_description *get_subtype_desc __P((int,
 +    struct ifmedia_type_to_subtype *ttos));
 +
  void
  media_status(s, info)
  	int s;
 @@ -127,16 +133,18 @@
  		err(1, "SIOCGIFMEDIA");
  
  	printf("\tmedia: ");
 -	print_media_word(ifmr.ifm_current);
 +	print_media_word(ifmr.ifm_current, 1);
  	if (ifmr.ifm_active != ifmr.ifm_current) {
  		putchar(' ');
  		putchar('(');
 -		print_media_word(ifmr.ifm_active);
 +		print_media_word(ifmr.ifm_active, 0);
  		putchar(')');
  	}
  
 +	putchar('\n');
 +
  	if (ifmr.ifm_status & IFM_AVALID) {
 -		printf(" status: ");
 +		printf("\tstatus: ");
  		switch (IFM_TYPE(ifmr.ifm_active)) {
  		case IFM_ETHER:
  			if (ifmr.ifm_status & IFM_ACTIVE)
 @@ -164,13 +172,13 @@
  
  	putchar('\n');
  
 -	if (ifmr.ifm_count > 0) {
 -		printf("\tsupported media:");
 +	if (ifmr.ifm_count > 0 && supmedia) {
 +		printf("\tsupported media:\n");
  		for (i = 0; i < ifmr.ifm_count; i++) {
 -			putchar(' ');
 -			print_media_word(media_list[i]);
 +			printf("\t\t");
 +			print_media_word_ifconfig(media_list[i]);
 +			putchar('\n');
  		}
 -		putchar('\n');
  	}
  
  	free(media_list);
 @@ -496,22 +504,69 @@
  	return (-1);
  }
  
 -static void
 -print_media_word(ifmw)
 +static struct ifmedia_description *get_toptype_desc(ifmw)
  	int ifmw;
  {
  	struct ifmedia_description *desc;
 +
 +	for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++)
 +		if (IFM_TYPE(ifmw) == desc->ifmt_word)
 +			break;
 +
 +	return desc;
 +}
 +
 +static struct ifmedia_type_to_subtype *get_toptype_ttos(ifmw)
 +	int ifmw;
 +{
 +	struct ifmedia_description *desc;
  	struct ifmedia_type_to_subtype *ttos;
 -	int seen_option = 0, i;
  
 -	/* Find the top-level interface type. */
  	for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
  	    desc->ifmt_string != NULL; desc++, ttos++)
  		if (IFM_TYPE(ifmw) == desc->ifmt_word)
  			break;
 +
 +	return ttos;
 +}
 +
 +static struct ifmedia_description *get_subtype_desc(ifmw, ttos)
 +	int ifmw;
 +	struct ifmedia_type_to_subtype *ttos;
 +{
 +	int i;
 +	struct ifmedia_description *desc;
 +
 +	for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
 +		if (ttos->subtypes[i].alias)
 +			continue;
 +		for (desc = ttos->subtypes[i].desc;
 +		    desc->ifmt_string != NULL; desc++) {
 +			if (IFM_SUBTYPE(ifmw) == desc->ifmt_word)
 +				return desc;
 +		}
 +	}
 +
 +	return NULL;
 +}
 +
 +static void
 +print_media_word(ifmw, print_toptype)
 +	int ifmw;
 +	int print_toptype;
 +{
 +	struct ifmedia_description *desc;
 +	struct ifmedia_type_to_subtype *ttos;
 +	int seen_option = 0, i;
 +
 +	/* Find the top-level interface type. */
 +	desc = get_toptype_desc(ifmw);
 +	ttos = get_toptype_ttos(ifmw);
  	if (desc->ifmt_string == NULL) {
  		printf("<unknown type>");
  		return;
 +	} else if (print_toptype) {
 +		printf("%s", desc->ifmt_string);
  	}
  
  	/*
 @@ -520,21 +575,18 @@
  	 */
  
  	/* Find subtype. */
 -	for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
 -		if (ttos->subtypes[i].alias)
 -			continue;
 -		for (desc = ttos->subtypes[i].desc;
 -		    desc->ifmt_string != NULL; desc++) {
 -			if (IFM_SUBTYPE(ifmw) == desc->ifmt_word)
 -				goto got_subtype;
 -		}
 -	}
 +	desc = get_subtype_desc(ifmw, ttos);
 +	if (desc != NULL)
 +		goto got_subtype;
  
  	/* Falling to here means unknown subtype. */
  	printf("<unknown subtype>");
  	return;
  
   got_subtype:
 +	if (print_toptype)
 +		putchar(' ');
 +
  	printf("%s", desc->ifmt_string);
  
  	/* Find options. */
 @@ -552,6 +604,52 @@
  		}
  	}
  	printf("%s", seen_option ? ">" : "");
 +}
 +
 +static void
 +print_media_word_ifconfig(ifmw)
 +	int ifmw;
 +{
 +	struct ifmedia_description *desc;
 +	struct ifmedia_type_to_subtype *ttos;
 +	int i;
 +
 +	/* Find the top-level interface type. */
 +	desc = get_toptype_desc(ifmw);
 +	ttos = get_toptype_ttos(ifmw);
 +	if (desc->ifmt_string == NULL) {
 +		printf("<unknown type>");
 +		return;
 +	}
 +
 +	/*
 +	 * Don't print the top-level type; it's not like we can
 +	 * change it, or anything.
 +	 */
 +
 +	/* Find subtype. */
 +	desc = get_subtype_desc(ifmw, ttos);
 +	if (desc != NULL)
 +		goto got_subtype;
 +
 +	/* Falling to here means unknown subtype. */
 +	printf("<unknown subtype>");
 +	return;
 +
 + got_subtype:
 +	printf("media %s", desc->ifmt_string);
 +
 +	/* Find options. */
 +	for (i = 0; ttos->options[i].desc != NULL; i++) {
 +		if (ttos->options[i].alias)
 +			continue;
 +		for (desc = ttos->options[i].desc;
 +		    desc->ifmt_string != NULL; desc++) {
 +			if (ifmw & desc->ifmt_word) {
 +				printf(" mediaopt %s", desc->ifmt_string);
 +			}
 +		}
 +	}
  }
  
  /**********************************************************************
 
 --
 Any statement of the form "X is the one, true Y" is FALSE.
 PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
State-Changed-From-To: feedback->closed 
State-Changed-By: phk 
State-Changed-When: Tue May 29 02:14:01 PDT 2001 
State-Changed-Why:  
Committed, thanks! 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27701 
>Unformatted:
