@@ -567,58 +567,104 @@ int
567567do_show (int argc , char * * argv )
568568{
569569 ni_dbus_object_t * root_object ;
570+ ni_dbus_object_t * list_object ;
570571 ni_dbus_object_t * object ;
572+ enum { OPT_HELP , };
573+ static struct option options [] = {
574+ { "help" , no_argument , NULL , OPT_HELP },
575+ { NULL }
576+ };
577+ const char * ifname = NULL ;
578+ int c , rv = 1 ;
571579
572- if (argc != 1 && argc != 2 ) {
573- ni_error ("wicked show: missing interface name" );
574- return 1 ;
580+ optind = 1 ;
581+ while ((c = getopt_long (argc , argv , "" , options , NULL )) != EOF ) {
582+ switch (c ) {
583+ default :
584+ case OPT_HELP :
585+ usage :
586+ fprintf (stderr ,
587+ "wicked [options] show [ifname]\n"
588+ "\nSupported options:\n"
589+ " --help\n"
590+ " Show this help text.\n"
591+ );
592+ return (c == OPT_HELP ? 0 : 1 );
593+ }
594+ }
595+
596+ if (optind < argc ) {
597+ ifname = argv [optind ++ ];
598+ if (ni_string_eq (ifname , "all" ))
599+ ifname = NULL ;
575600 }
576601
602+ if (optind != argc )
603+ goto usage ;
604+
577605 if (!(root_object = ni_call_create_client ()))
578606 return 1 ;
579607
580- if (argc == 1 ) {
581- object = get_netif_list_object ();
582- if (!object )
583- return 1 ;
608+ if (!(list_object = get_netif_list_object ()))
609+ return 1 ;
584610
585- for (object = object -> children ; object ; object = object -> next ) {
586- ni_netdev_t * ifp = object -> handle ;
587- ni_address_t * ap ;
588- ni_route_table_t * tab ;
589- ni_route_t * rp ;
590- unsigned int i ;
591-
592- printf ("%-12s %-10s %-10s" ,
593- ifp -> name ,
594- (ifp -> link .ifflags & NI_IFF_NETWORK_UP )? "up" :
595- (ifp -> link .ifflags & NI_IFF_LINK_UP )? "link-up" :
596- (ifp -> link .ifflags & NI_IFF_DEVICE_UP )? "device-up" : "down" ,
597- ni_linktype_type_to_name (ifp -> link .type ));
598- printf ("\n" );
611+ for (object = list_object -> children ; object ; object = object -> next ) {
612+ ni_netdev_t * ifp = object -> handle ;
613+ ni_address_t * ap ;
614+ ni_route_table_t * tab ;
615+ ni_route_t * rp ;
616+ unsigned int i ;
599617
600- for (ap = ifp -> addrs ; ap ; ap = ap -> next )
601- printf (" addr: %s/%u\n" , ni_sockaddr_print (& ap -> local_addr ), ap -> prefixlen );
618+ if (ifname && !ni_string_eq (ifname , ifp -> name ))
619+ continue ;
620+
621+ if (rv == 0 )
622+ printf ("\n" );
623+ rv = 0 ;
602624
603- for ( tab = ifp -> routes ; tab ; tab = tab -> next ) {
604- for ( i = 0 ; i < tab -> routes . count ; ++ i ) {
605- ni_stringbuf_t buf = NI_STRINGBUF_INIT_DYNAMIC ;
606- rp = tab -> routes . data [ i ] ;
625+ printf ( "%d: %-16s %s\n" , ifp -> link . ifindex , ifp -> name ,
626+ ( ifp -> link . ifflags & NI_IFF_NETWORK_UP )? "up" :
627+ ( ifp -> link . ifflags & NI_IFF_LINK_UP )? "link-up" :
628+ ( ifp -> link . ifflags & NI_IFF_DEVICE_UP )? "device-up" : "down" ) ;
607629
608- ni_route_print (& buf , rp );
609- printf (" route: %s\n" , buf .string );
610- ni_stringbuf_destroy (& buf );
611- }
630+ printf (" %-8s %s" , "link:" , ni_linktype_type_to_name (ifp -> link .type ));
631+ if (ifp -> link .hwaddr .len ) {
632+ printf (" addr %s" , ni_link_address_print (& ifp -> link .hwaddr ));
633+ }
634+ if (ifp -> link .mtu > 0 ) {
635+ printf (" mtu %d" , ifp -> link .mtu );
636+ }
637+ if (!ni_string_empty (ifp -> link .alias )) {
638+ printf (" alias %s" , ifp -> link .alias );
639+ }
640+ printf ("\n" );
641+
642+ for (ap = ifp -> addrs ; ap ; ap = ap -> next ) {
643+ printf (" %-8s %s %s/%u" , "addr:" ,
644+ ni_addrfamily_type_to_name (ap -> family ),
645+ ni_sockaddr_print (& ap -> local_addr ), ap -> prefixlen );
646+ if (!ni_string_empty (ap -> label ) && !ni_string_eq (ap -> label , ifp -> name )) {
647+ printf (" label %s" , ap -> label );
612648 }
649+ printf ("\n" );
613650 }
614- } else {
615- const char * ifname = argv [1 ];
616651
617- object = get_netif_object (ifname );
618- if (!object )
619- return 1 ;
652+ for (tab = ifp -> routes ; tab ; tab = tab -> next ) {
653+ for (i = 0 ; i < tab -> routes .count ; ++ i ) {
654+ ni_stringbuf_t buf = NI_STRINGBUF_INIT_DYNAMIC ;
655+ rp = tab -> routes .data [i ];
656+
657+ ni_route_print (& buf , rp );
658+ printf (" %-8s %s\n" , "route:" , buf .string );
659+ ni_stringbuf_destroy (& buf );
660+ }
661+ }
620662 }
621663
664+ if (ifname && rv != 0 ) {
665+ ni_error ("%s: unknown network interface" , ifname );
666+ return rv ;
667+ }
622668 return 0 ;
623669}
624670
0 commit comments