Home | History | Annotate | Line # | Download | only in route
show.c revision 1.42.2.1
      1  1.42.2.1    bouyer /*	$NetBSD: show.c,v 1.42.2.1 2011/02/08 16:19:06 bouyer Exp $	*/
      2       1.1       gwr 
      3       1.1       gwr /*
      4       1.1       gwr  * Copyright (c) 1983, 1988, 1993
      5       1.1       gwr  *	The Regents of the University of California.  All rights reserved.
      6       1.1       gwr  *
      7       1.1       gwr  * Redistribution and use in source and binary forms, with or without
      8       1.1       gwr  * modification, are permitted provided that the following conditions
      9       1.1       gwr  * are met:
     10       1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     11       1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     12       1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     14       1.1       gwr  *    documentation and/or other materials provided with the distribution.
     15      1.21       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.1       gwr  *    may be used to endorse or promote products derived from this software
     17       1.1       gwr  *    without specific prior written permission.
     18       1.1       gwr  *
     19       1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1       gwr  * SUCH DAMAGE.
     30       1.1       gwr  */
     31       1.1       gwr 
     32       1.4     lukem #include <sys/cdefs.h>
     33       1.1       gwr #ifndef lint
     34       1.1       gwr #if 0
     35       1.1       gwr static char sccsid[] = "from: @(#)route.c	8.3 (Berkeley) 3/9/94";
     36       1.1       gwr #else
     37  1.42.2.1    bouyer __RCSID("$NetBSD: show.c,v 1.42.2.1 2011/02/08 16:19:06 bouyer Exp $");
     38       1.1       gwr #endif
     39       1.1       gwr #endif /* not lint */
     40       1.1       gwr 
     41       1.1       gwr #include <sys/param.h>
     42       1.1       gwr #include <sys/protosw.h>
     43       1.1       gwr #include <sys/socket.h>
     44       1.1       gwr #include <sys/mbuf.h>
     45       1.1       gwr 
     46      1.41    kefren #include <arpa/inet.h>
     47       1.1       gwr #include <net/if.h>
     48       1.1       gwr #include <net/if_dl.h>
     49       1.1       gwr #include <net/if_types.h>
     50       1.1       gwr #include <net/route.h>
     51       1.1       gwr #include <netinet/in.h>
     52      1.41    kefren #include <netmpls/mpls.h>
     53       1.1       gwr 
     54       1.1       gwr #include <sys/sysctl.h>
     55       1.1       gwr 
     56       1.1       gwr #include <netdb.h>
     57      1.36    dyoung #include <stdbool.h>
     58       1.1       gwr #include <stdio.h>
     59       1.1       gwr #include <stdlib.h>
     60       1.1       gwr #include <string.h>
     61       1.1       gwr #include <unistd.h>
     62       1.5  christos #include <err.h>
     63       1.1       gwr 
     64      1.26  ginsbach #include "keywords.h"
     65       1.2  christos #include "extern.h"
     66      1.42     pooka #include "prog_ops.h"
     67       1.1       gwr 
     68      1.12    itojun 
     69       1.1       gwr /*
     70       1.1       gwr  * Definitions for showing gateway flags.
     71       1.1       gwr  */
     72       1.1       gwr struct bits {
     73       1.1       gwr 	short	b_mask;
     74       1.1       gwr 	char	b_val;
     75       1.1       gwr };
     76       1.1       gwr static const struct bits bits[] = {
     77       1.1       gwr 	{ RTF_UP,	'U' },
     78       1.1       gwr 	{ RTF_GATEWAY,	'G' },
     79       1.1       gwr 	{ RTF_HOST,	'H' },
     80       1.1       gwr 	{ RTF_REJECT,	'R' },
     81       1.1       gwr 	{ RTF_DYNAMIC,	'D' },
     82       1.1       gwr 	{ RTF_MODIFIED,	'M' },
     83       1.1       gwr 	{ RTF_DONE,	'd' }, /* Completed -- for routing messages only */
     84       1.1       gwr 	{ RTF_MASK,	'm' }, /* Mask Present -- for routing messages only */
     85       1.1       gwr 	{ RTF_CLONING,	'C' },
     86       1.1       gwr 	{ RTF_XRESOLVE,	'X' },
     87       1.1       gwr 	{ RTF_LLINFO,	'L' },
     88       1.1       gwr 	{ RTF_STATIC,	'S' },
     89      1.16    itojun 	{ RTF_BLACKHOLE, 'B' },
     90      1.17    itojun 	{ RTF_CLONED,	'c' },
     91       1.1       gwr 	{ RTF_PROTO1,	'1' },
     92       1.1       gwr 	{ RTF_PROTO2,	'2' },
     93      1.35  christos 	{ 0, '\0' }
     94       1.1       gwr };
     95       1.1       gwr 
     96      1.23  ginsbach static void pr_rthdr(int);
     97      1.22   xtraeme static void p_rtentry(struct rt_msghdr *);
     98      1.22   xtraeme static void pr_family(int);
     99      1.22   xtraeme static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int );
    100      1.22   xtraeme static void p_flags(int);
    101       1.1       gwr 
    102      1.33    dyoung void
    103      1.38    dyoung parse_show_opts(int argc, char * const *argv, int *afp, int *flagsp,
    104      1.36    dyoung     const char **afnamep, bool nolink)
    105      1.33    dyoung {
    106      1.33    dyoung 	const char *afname = "unspec";
    107      1.33    dyoung 	int af, flags;
    108      1.33    dyoung 
    109      1.33    dyoung 	flags = 0;
    110      1.33    dyoung 	af = AF_UNSPEC;
    111      1.33    dyoung 	for (; argc >= 2; argc--) {
    112      1.33    dyoung 		if (*argv[argc - 1] != '-')
    113      1.33    dyoung 			goto bad;
    114      1.33    dyoung 		switch (keyword(argv[argc - 1] + 1)) {
    115      1.33    dyoung 		case K_HOST:
    116      1.33    dyoung 			flags |= RTF_HOST;
    117      1.33    dyoung 			break;
    118      1.33    dyoung 		case K_LLINFO:
    119      1.33    dyoung 			flags |= RTF_LLINFO;
    120      1.33    dyoung 			break;
    121      1.33    dyoung 		case K_INET:
    122      1.33    dyoung 			af = AF_INET;
    123      1.33    dyoung 			afname = argv[argc - 1] + 1;
    124      1.33    dyoung 			break;
    125      1.33    dyoung #ifdef INET6
    126      1.33    dyoung 		case K_INET6:
    127      1.33    dyoung 			af = AF_INET6;
    128      1.33    dyoung 			afname = argv[argc - 1] + 1;
    129      1.33    dyoung 			break;
    130      1.33    dyoung #endif
    131      1.33    dyoung #ifndef SMALL
    132      1.33    dyoung 		case K_ATALK:
    133      1.33    dyoung 			af = AF_APPLETALK;
    134      1.33    dyoung 			afname = argv[argc - 1] + 1;
    135      1.33    dyoung 			break;
    136      1.33    dyoung 		case K_ISO:
    137      1.33    dyoung 		case K_OSI:
    138      1.33    dyoung 			af = AF_ISO;
    139      1.33    dyoung 			afname = argv[argc - 1] + 1;
    140      1.33    dyoung 			break;
    141      1.41    kefren 		case K_MPLS:
    142      1.41    kefren 			af = AF_MPLS;
    143      1.41    kefren 			afname = argv[argc - 1] + 1;
    144      1.41    kefren 			break;
    145      1.33    dyoung #endif /* SMALL */
    146      1.33    dyoung 		case K_LINK:
    147      1.33    dyoung 			if (nolink)
    148      1.33    dyoung 				goto bad;
    149      1.33    dyoung 			af = AF_LINK;
    150      1.33    dyoung 			afname = argv[argc - 1] + 1;
    151      1.33    dyoung 			break;
    152      1.33    dyoung 		default:
    153      1.33    dyoung 			goto bad;
    154      1.33    dyoung 		}
    155      1.33    dyoung 	}
    156      1.33    dyoung 	switch (argc) {
    157      1.33    dyoung 	case 1:
    158      1.33    dyoung 	case 0:
    159      1.33    dyoung 		break;
    160      1.33    dyoung 	default:
    161      1.33    dyoung 	bad:
    162      1.33    dyoung 		usage(argv[argc - 1]);
    163      1.33    dyoung 	}
    164      1.33    dyoung 	if (afnamep != NULL)
    165      1.33    dyoung 		*afnamep = afname;
    166      1.33    dyoung 	*afp = af;
    167      1.33    dyoung 	*flagsp = flags;
    168      1.33    dyoung }
    169      1.33    dyoung 
    170       1.1       gwr /*
    171       1.1       gwr  * Print routing tables.
    172       1.1       gwr  */
    173       1.1       gwr void
    174      1.38    dyoung show(int argc, char *const *argv)
    175       1.1       gwr {
    176       1.1       gwr 	size_t needed;
    177      1.33    dyoung 	int af, flags, mib[6];
    178       1.1       gwr 	char *buf, *next, *lim;
    179       1.4     lukem 	struct rt_msghdr *rtm;
    180      1.26  ginsbach 	struct sockaddr *sa;
    181       1.1       gwr 
    182      1.36    dyoung 	parse_show_opts(argc, argv, &af, &flags, NULL, true);
    183       1.1       gwr 	mib[0] = CTL_NET;
    184       1.1       gwr 	mib[1] = PF_ROUTE;
    185       1.1       gwr 	mib[2] = 0;
    186       1.1       gwr 	mib[3] = 0;
    187       1.1       gwr 	mib[4] = NET_RT_DUMP;
    188       1.1       gwr 	mib[5] = 0;
    189      1.42     pooka 	if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
    190      1.37    dyoung 		err(EXIT_FAILURE, "route-sysctl-estimate");
    191      1.27  ginsbach 	buf = lim = NULL;
    192      1.27  ginsbach 	if (needed) {
    193      1.27  ginsbach 		if ((buf = malloc(needed)) == 0)
    194      1.37    dyoung 			err(EXIT_FAILURE, "malloc");
    195      1.42     pooka 		if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
    196      1.37    dyoung 			err(EXIT_FAILURE, "sysctl of routing table");
    197      1.27  ginsbach 		lim  = buf + needed;
    198      1.27  ginsbach 	}
    199       1.1       gwr 
    200      1.26  ginsbach 	printf("Routing table%s\n", (af == AF_UNSPEC)? "s" : "");
    201       1.1       gwr 
    202      1.27  ginsbach 	if (needed) {
    203       1.1       gwr 		for (next = buf; next < lim; next += rtm->rtm_msglen) {
    204       1.1       gwr 			rtm = (struct rt_msghdr *)next;
    205      1.26  ginsbach 			sa = (struct sockaddr *)(rtm + 1);
    206      1.33    dyoung 			if ((rtm->rtm_flags & flags) != flags)
    207      1.33    dyoung 				continue;
    208      1.26  ginsbach 			if (af == AF_UNSPEC || af == sa->sa_family)
    209      1.26  ginsbach 				p_rtentry(rtm);
    210       1.1       gwr 		}
    211      1.27  ginsbach 		free(buf);
    212       1.1       gwr 	}
    213       1.1       gwr }
    214       1.1       gwr 
    215       1.1       gwr 
    216       1.1       gwr /* column widths; each followed by one space */
    217      1.23  ginsbach #ifndef INET6
    218      1.23  ginsbach #define	WID_DST(af)	18	/* width of destination column */
    219      1.23  ginsbach #define	WID_GW(af)	18	/* width of gateway column */
    220      1.23  ginsbach #else
    221      1.23  ginsbach /* width of destination/gateway column */
    222      1.23  ginsbach #if 1
    223      1.23  ginsbach /* strlen("fe80::aaaa:bbbb:cccc:dddd@gif0") == 30, strlen("/128") == 4 */
    224      1.23  ginsbach #define	WID_DST(af)	((af) == AF_INET6 ? (nflag ? 34 : 18) : 18)
    225      1.23  ginsbach #define	WID_GW(af)	((af) == AF_INET6 ? (nflag ? 30 : 18) : 18)
    226      1.23  ginsbach #else
    227      1.23  ginsbach /* strlen("fe80::aaaa:bbbb:cccc:dddd") == 25, strlen("/128") == 4 */
    228      1.23  ginsbach #define	WID_DST(af)	((af) == AF_INET6 ? (nflag ? 29 : 18) : 18)
    229      1.23  ginsbach #define	WID_GW(af)	((af) == AF_INET6 ? (nflag ? 25 : 18) : 18)
    230      1.23  ginsbach #endif
    231      1.23  ginsbach #endif /* INET6 */
    232       1.1       gwr 
    233       1.1       gwr /*
    234       1.1       gwr  * Print header for routing table columns.
    235       1.1       gwr  */
    236       1.1       gwr static void
    237      1.23  ginsbach pr_rthdr(int af)
    238       1.1       gwr {
    239       1.1       gwr 
    240       1.1       gwr 	printf("%-*.*s %-*.*s %-6.6s\n",
    241      1.23  ginsbach 		WID_DST(af), WID_DST(af), "Destination",
    242      1.23  ginsbach 		WID_GW(af), WID_GW(af), "Gateway",
    243       1.1       gwr 		"Flags");
    244       1.1       gwr }
    245       1.1       gwr 
    246       1.1       gwr 
    247       1.1       gwr /*
    248       1.1       gwr  * Print a routing table entry.
    249       1.1       gwr  */
    250       1.1       gwr static void
    251      1.22   xtraeme p_rtentry(struct rt_msghdr *rtm)
    252       1.1       gwr {
    253       1.4     lukem 	struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
    254       1.1       gwr #ifdef notdef
    255       1.1       gwr 	static int masks_done, banner_printed;
    256       1.1       gwr #endif
    257       1.1       gwr 	static int old_af;
    258      1.34     pooka 	int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST |
    259      1.34     pooka 	    RTF_REJECT | RTF_LLINFO;
    260       1.1       gwr 
    261       1.1       gwr #ifdef notdef
    262       1.1       gwr 	/* for the moment, netmasks are skipped over */
    263       1.1       gwr 	if (!banner_printed) {
    264       1.1       gwr 		printf("Netmasks:\n");
    265       1.1       gwr 		banner_printed = 1;
    266       1.1       gwr 	}
    267       1.1       gwr 	if (masks_done == 0) {
    268       1.1       gwr 		if (rtm->rtm_addrs != RTA_DST ) {
    269       1.1       gwr 			masks_done = 1;
    270       1.1       gwr 			af = sa->sa_family;
    271       1.1       gwr 		}
    272       1.1       gwr 	} else
    273       1.1       gwr #endif
    274       1.1       gwr 		af = sa->sa_family;
    275       1.1       gwr 	if (old_af != af) {
    276       1.1       gwr 		old_af = af;
    277       1.1       gwr 		pr_family(af);
    278      1.23  ginsbach 		pr_rthdr(af);
    279       1.1       gwr 	}
    280       1.1       gwr 	if (rtm->rtm_addrs == RTA_DST)
    281      1.23  ginsbach 		p_sockaddr(sa, NULL, 0, WID_DST(af) + 1 + WID_GW(af) + 1);
    282       1.1       gwr 	else {
    283      1.19    atatat 		struct sockaddr *nm;
    284      1.19    atatat 
    285      1.19    atatat 		if ((rtm->rtm_addrs & RTA_NETMASK) == 0)
    286      1.19    atatat 			nm = NULL;
    287      1.19    atatat 		else {
    288      1.19    atatat 			/* skip to gateway */
    289      1.19    atatat 			nm = (struct sockaddr *)
    290  1.42.2.1    bouyer 			    (RT_ROUNDUP(sa->sa_len) + (char *)sa);
    291      1.19    atatat 			/* skip over gateway to netmask */
    292      1.19    atatat 			nm = (struct sockaddr *)
    293  1.42.2.1    bouyer 			    (RT_ROUNDUP(nm->sa_len) + (char *)nm);
    294      1.19    atatat 		}
    295      1.19    atatat 
    296      1.23  ginsbach 		p_sockaddr(sa, nm, rtm->rtm_flags, WID_DST(af));
    297  1.42.2.1    bouyer 		sa = (struct sockaddr *)(RT_ROUNDUP(sa->sa_len) + (char *)sa);
    298      1.23  ginsbach 		p_sockaddr(sa, NULL, 0, WID_GW(af));
    299       1.1       gwr 	}
    300      1.15        is 	p_flags(rtm->rtm_flags & interesting);
    301       1.1       gwr 	putchar('\n');
    302       1.1       gwr }
    303       1.1       gwr 
    304       1.1       gwr 
    305       1.1       gwr /*
    306       1.1       gwr  * Print address family header before a section of the routing table.
    307       1.1       gwr  */
    308       1.1       gwr static void
    309      1.22   xtraeme pr_family(int af)
    310       1.1       gwr {
    311      1.24  christos 	const char *afname;
    312       1.1       gwr 
    313       1.1       gwr 	switch (af) {
    314       1.1       gwr 	case AF_INET:
    315       1.1       gwr 		afname = "Internet";
    316       1.1       gwr 		break;
    317       1.9    itojun #ifdef INET6
    318       1.9    itojun 	case AF_INET6:
    319       1.9    itojun 		afname = "Internet6";
    320       1.9    itojun 		break;
    321       1.9    itojun #endif /* INET6 */
    322      1.28  ginsbach #ifndef SMALL
    323       1.1       gwr 	case AF_ISO:
    324       1.1       gwr 		afname = "ISO";
    325       1.1       gwr 		break;
    326      1.41    kefren 	case AF_MPLS:
    327      1.41    kefren 		afname = "MPLS";
    328      1.41    kefren 		break;
    329       1.8     lukem #endif /* SMALL */
    330       1.6    kleink 	case AF_APPLETALK:
    331       1.6    kleink 		afname = "AppleTalk";
    332       1.1       gwr 		break;
    333       1.1       gwr 	default:
    334       1.1       gwr 		afname = NULL;
    335       1.1       gwr 		break;
    336       1.1       gwr 	}
    337       1.1       gwr 	if (afname)
    338       1.1       gwr 		printf("\n%s:\n", afname);
    339       1.1       gwr 	else
    340       1.1       gwr 		printf("\nProtocol Family %d:\n", af);
    341       1.1       gwr }
    342       1.1       gwr 
    343       1.1       gwr 
    344       1.1       gwr static void
    345      1.22   xtraeme p_sockaddr(struct sockaddr *sa, struct sockaddr *nm, int flags, int width)
    346       1.1       gwr {
    347      1.24  christos 	char workbuf[128];
    348      1.24  christos 	const char *cp;
    349       1.1       gwr 
    350       1.1       gwr 	switch(sa->sa_family) {
    351       1.1       gwr 
    352       1.1       gwr 	case AF_LINK:
    353      1.18     bjh21 		if (getnameinfo(sa, sa->sa_len, workbuf, sizeof(workbuf),
    354      1.18     bjh21 		    NULL, 0, NI_NUMERICHOST) != 0)
    355      1.20    itojun 			strlcpy(workbuf, "invalid", sizeof(workbuf));
    356      1.18     bjh21 		cp = workbuf;
    357       1.1       gwr 		break;
    358       1.1       gwr 
    359       1.1       gwr 	case AF_INET:
    360      1.19    atatat 		cp = routename(sa, nm, flags);
    361       1.1       gwr 		break;
    362       1.1       gwr 
    363       1.9    itojun #ifdef INET6
    364       1.9    itojun 	case AF_INET6:
    365      1.19    atatat 		cp = routename(sa, nm, flags);
    366      1.11    itojun 		/* make sure numeric address is not truncated */
    367      1.39     lukem 		if (strchr(cp, ':') != NULL && (int)strlen(cp) > width)
    368      1.11    itojun 			width = strlen(cp);
    369       1.9    itojun 		break;
    370       1.9    itojun #endif /* INET6 */
    371       1.9    itojun 
    372      1.28  ginsbach #ifndef SMALL
    373      1.41    kefren 	case AF_MPLS:
    374      1.41    kefren 		{
    375      1.41    kefren 		struct sockaddr_mpls *smpls = (struct sockaddr_mpls *)sa;
    376      1.41    kefren 		union mpls_shim ms;
    377      1.41    kefren 
    378      1.41    kefren 		ms.s_addr = ntohl(smpls->smpls_addr.s_addr);
    379      1.41    kefren 
    380      1.41    kefren 		snprintf(workbuf, sizeof(workbuf), "%u",
    381      1.41    kefren 			ms.shim.label);
    382      1.41    kefren 		cp = workbuf;
    383      1.41    kefren 		}
    384      1.41    kefren 		break;
    385      1.40        is 	case AF_APPLETALK:
    386      1.40        is 		if (getnameinfo(sa, sa->sa_len, workbuf, sizeof(workbuf),
    387      1.40        is 		    NULL, 0, NI_NUMERICHOST) != 0)
    388      1.40        is 			strlcpy(workbuf, "invalid", sizeof(workbuf));
    389      1.40        is 		cp = workbuf;
    390      1.40        is 		break;
    391      1.40        is 
    392       1.1       gwr #endif /* SMALL */
    393       1.1       gwr 
    394       1.1       gwr 	default:
    395       1.1       gwr 	    {
    396       1.4     lukem 		u_char *s = (u_char *)sa->sa_data, *slim;
    397      1.24  christos 		char *wp = workbuf, *wplim;
    398       1.1       gwr 
    399      1.25  ginsbach 		slim = sa->sa_len + (u_char *)sa;
    400      1.24  christos 		wplim = wp + sizeof(workbuf) - 6;
    401      1.24  christos 		wp += snprintf(wp, wplim - wp, "(%d)", sa->sa_family);
    402      1.24  christos 		while (s < slim && wp < wplim) {
    403      1.24  christos 			wp += snprintf(wp, wplim - wp, " %02x", *s++);
    404       1.1       gwr 			if (s < slim)
    405      1.24  christos 			    wp += snprintf(wp, wplim - wp, "%02x", *s++);
    406       1.1       gwr 		}
    407       1.1       gwr 		cp = workbuf;
    408       1.1       gwr 	    }
    409       1.1       gwr 	}
    410       1.1       gwr 	if (width < 0 )
    411       1.1       gwr 		printf("%s ", cp);
    412       1.1       gwr 	else {
    413       1.1       gwr 		if (nflag)
    414       1.1       gwr 			printf("%-*s ", width, cp);
    415       1.1       gwr 		else
    416       1.1       gwr 			printf("%-*.*s ", width, width, cp);
    417       1.1       gwr 	}
    418       1.1       gwr }
    419       1.1       gwr 
    420       1.1       gwr static void
    421      1.22   xtraeme p_flags(int f)
    422       1.1       gwr {
    423       1.1       gwr 	char name[33], *flags;
    424       1.4     lukem 	const struct bits *p = bits;
    425       1.1       gwr 
    426       1.1       gwr 	for (flags = name; p->b_mask; p++)
    427       1.1       gwr 		if (p->b_mask & f)
    428       1.1       gwr 			*flags++ = p->b_val;
    429      1.29  christos 		else if (Sflag)
    430      1.29  christos 			*flags++ = ' ';
    431       1.1       gwr 	*flags = '\0';
    432      1.15        is 	printf("%-6.6s ", name);
    433       1.1       gwr }
    434       1.1       gwr 
    435