1/*
2 * usage.c - usage functions for lsof
3 */
4
5
6/*
7 * Copyright 1998 Purdue Research Foundation, West Lafayette, Indiana
8 * 47907.  All rights reserved.
9 *
10 * Written by Victor A. Abell
11 *
12 * This software is not subject to any license of the American Telephone
13 * and Telegraph Company or the Regents of the University of California.
14 *
15 * Permission is granted to anyone to use this software for any purpose on
16 * any computer system, and to alter it and redistribute it freely, subject
17 * to the following restrictions:
18 *
19 * 1. Neither the authors nor Purdue University are responsible for any
20 *    consequences of the use of this software.
21 *
22 * 2. The origin of this software must not be misrepresented, either by
23 *    explicit claim or by omission.  Credit to the authors and Purdue
24 *    University must appear in documentation and sources.
25 *
26 * 3. Altered versions must be plainly marked as such, and must not be
27 *    misrepresented as being the original software.
28 *
29 * 4. This notice may not be removed or altered.
30 */
31
32#ifndef lint
33static char copyright[] =
34"@(#) Copyright 1998 Purdue Research Foundation.\nAll rights reserved.\n";
35static char *rcsid = "$Id: usage.c,v 1.31 2013/01/02 17:14:59 abe Exp $";
36#endif
37
38
39#include "lsof.h"
40#include "version.h"
41
42
43/*
44 * Local function prototypes
45 */
46
47_PROTOTYPE(static char *isnullstr,(char *s));
48_PROTOTYPE(static int print_in_col,(int col, char *cp));
49_PROTOTYPE(static void report_HASDCACHE,(int type, char *ttl, char *det));
50_PROTOTYPE(static void report_HASKERNIDCK,(char *pfx, char *verb));
51_PROTOTYPE(static void report_SECURITY,(char *pfx, char *punct));
52_PROTOTYPE(static void report_WARNDEVACCESS,(char *pfx, char *verb,
53					     char *punct));
54
55
56/*
57 * isnullstr() - is it a null string?
58 */
59
60static char *
61isnullstr(s)
62	char *s;			/* string pointer */
63{
64	if (!s)
65		return((char *)NULL);
66	while (*s) {
67		if (*s != ' ')
68			return(s);
69		s++;
70	}
71	return((char *)NULL);
72}
73
74
75/*
76 * print_in_col() -- print character string in help column
77 */
78
79static int
80print_in_col(col, cp)
81	int col;				/* column number */
82	char *cp;				/* what to print */
83{
84	if (cp && *cp) {
85	    switch (col) {
86	    case 1:
87		(void) fprintf(stderr, "  %-23.23s", cp);
88		break;
89	    case 2:
90		(void) fprintf(stderr, "  %-25.25s", cp);
91		break;
92	    default:
93		(void) fprintf(stderr, "  %s\n", cp);
94		col = 0;
95	    }
96	    col++;
97	}
98	return(col);
99}
100
101
102/*
103 * report_HASDCACHE() -- report device cache file state
104 */
105
106static void
107report_HASDCACHE(type, ttl, det)
108	int type;				/* type: 0 == read path report
109						 *       1 == full report */
110	char *ttl;				/* title lines prefix
111						 * (NULL if none) */
112	char *det;				/* detail lines prefix
113						 * (NULL if none) */
114{
115
116#if	defined(HASDCACHE)
117	char *cp;
118	int dx;
119
120# if	defined(WILLDROPGID)
121	int saved_Setgid = Setgid;
122
123	Setgid = 0;
124# endif	/* defined(WILLDROPGID) */
125
126	if (type) {
127
128	/*
129	 * Report full device cache information.
130	 */
131	    (void) fprintf(stderr, "%sDevice cache file read-only paths:\n",
132		ttl ? ttl : "");
133	    if ((dx = dcpath(1, 0)) < 0)
134		(void) fprintf(stderr, "%snone\n", det ? det : "");
135	    else {
136		(void) fprintf(stderr, "%sNamed via -D: %s\n",
137		    det ? det : "",
138		    DCpath[0] ? DCpath[0] : "none");
139
140# if	defined(HASENVDC)
141		(void) fprintf(stderr,
142		    "%sNamed in environment variable %s: %s\n",
143		    det ? det : "",
144		    HASENVDC, DCpath[1] ? DCpath[1] : "none");
145# endif	/* defined(HASENVDC) */
146
147# if	defined(HASSYSDC)
148		if (DCpath[2])
149		    (void) fprintf(stderr,
150			"%sSystem-wide device cache: %s\n",
151			det ? det : "",
152			DCpath[2]);
153# endif	/* defined(HASSYSDC) */
154
155# if	defined(HASPERSDC)
156		(void) fprintf(stderr,
157		    "%sPersonal path format (HASPERSDC): \"%s\"\n",
158		    det ? det : "",
159		    HASPERSDC);
160#  if	defined(HASPERSDCPATH)
161		(void) fprintf(stderr,
162		    "%sModified personal path environment variable: %s\n",
163		    det ? det : "",
164		    HASPERSDCPATH);
165		cp = getenv(HASPERSDCPATH);
166		(void) fprintf(stderr, "%s%s value: %s\n",
167		    det ? det : "",
168		    HASPERSDCPATH, cp ? cp : "none");
169#  endif	/* defined(HASPERSDCPATH) */
170		(void) fprintf(stderr, "%sPersonal path: %s\n",
171		    det ? det : "",
172		    DCpath[3] ? DCpath[3] : "none");
173# endif	/* defined(HASPERSDC) */
174	    }
175	    (void) fprintf(stderr, "%sDevice cache file write paths:\n",
176		ttl ? ttl : "");
177	    if ((dx = dcpath(2, 0)) < 0)
178		(void) fprintf(stderr, "%snone\n", det ? det : "");
179	    else {
180		(void) fprintf(stderr, "%sNamed via -D: %s\n",
181		    det ? det : "",
182		    DCstate == 2 ? "none"
183				 : DCpath[0] ? DCpath[0] : "none");
184
185# if	defined(HASENVDC)
186		(void) fprintf(stderr,
187		    "%sNamed in environment variable %s: %s\n",
188		    det ? det : "",
189		    HASENVDC, DCpath[1] ? DCpath[1] : "none");
190# endif	/* defined(HASENVDC) */
191
192# if	defined(HASPERSDC)
193		(void) fprintf(stderr,
194		    "%sPersonal path format (HASPERSDC): \"%s\"\n",
195		    det ? det : "",
196		    HASPERSDC);
197#  if	defined(HASPERSDCPATH)
198		(void) fprintf(stderr,
199		    "%sModified personal path environment variable: %s\n",
200		    det ? det : "",
201		    HASPERSDCPATH);
202		cp = getenv(HASPERSDCPATH);
203		(void) fprintf(stderr, "%s%s value: %s\n",
204		    det ? det : "",
205		    HASPERSDCPATH, cp ? cp : "none");
206#  endif	/* defined(HASPERSDCPATH) */
207		 (void) fprintf(stderr, "%sPersonal path: %s\n",
208		    det ? det : "",
209		    DCpath[3] ? DCpath[3] : "none");
210# endif	/* defined(HASPERSDC) */
211	    }
212	} else {
213
214	/*
215	 * Report device cache read file path.
216	 */
217
218# if	defined(HASENVDC) || defined(HASPERSDC) || defined(HASSYSDC)
219	    cp = NULL;
220#  if	defined(HASENVDC)
221	    if ((dx = dcpath(1, 0)) >= 0)
222		cp = DCpath[1];
223#  endif	/* defined(HASENVDC) */
224#  if	defined(HASSYSDC)
225	    if (!cp)
226		cp = HASSYSDC;
227#  endif	/* defined(HASSYSDC) */
228#  if	defined(HASPERSDC)
229	    if (!cp && dx != -1 && (dx = dcpath(1, 0)) >= 0)
230		cp = DCpath[3];
231#  endif	/* defined(HASPERSDC) */
232	    if (cp)
233		(void) fprintf(stderr,
234		    "%s%s is the default device cache file read path.\n",
235		    ttl ? ttl : "",
236		    cp
237		);
238# endif    /* defined(HASENVDC) || defined(HASPERSDC) || defined(HASSYSDC) */
239	}
240
241# if	defined(WILLDROPGID)
242	Setgid = saved_Setgid;
243# endif	/* defined(WILLDROPGID) */
244
245#endif	/* defined(HASDCACHE) */
246
247}
248
249
250/*
251 * report_HASKERNIDCK() -- report HASKERNIDCK state
252 */
253
254static void
255report_HASKERNIDCK(pfx, verb)
256	char *pfx;				/* prefix (NULL if none) */
257	char *verb;				/* verb (NULL if none) */
258{
259	(void) fprintf(stderr, "%sernel ID check %s%s%s.\n",
260	    pfx ? pfx : "",
261	    verb ? verb : "",
262	    verb ? " " : "",
263
264#if	defined(HASKERNIDCK)
265		"enabled"
266#else	/* !defined(HASKERNIDCK) */
267		"disabled"
268#endif	/* defined(HASKERNIDCK) */
269
270	    );
271}
272
273
274/*
275 * report_SECURITY() -- report *SECURITY states
276 */
277
278static void
279report_SECURITY(pfx, punct)
280	char *pfx;				/* prefix (NULL if none) */
281	char *punct;				/* short foem punctuation
282						 * (NULL if none) */
283{
284	fprintf(stderr, "%s%s can list all files%s",
285	    pfx ? pfx : "",
286
287#if	defined(HASSECURITY)
288	    "Only root",
289# if	defined(HASNOSOCKSECURITY)
290	    ", but anyone can list socket files.\n"
291# else	/* !defined(HASNOSOCKSECURITY) */
292	    punct ? punct : ""
293# endif	/* defined(HASNOSOCKSECURITY) */
294#else	/* !defined(HASSECURITY) */
295	    "Anyone",
296	    punct ? punct : ""
297#endif	/* defined(HASSECURITY) */
298
299	);
300}
301
302
303/*
304 * report_WARNDEVACCESS() -- report WEARNDEVACCESS state
305 */
306
307static void
308report_WARNDEVACCESS(pfx, verb, punct)
309	char *pfx;				/* prefix (NULL if none) */
310	char *verb;				/* verb (NULL if none) */
311	char *punct;				/* punctuation */
312{
313	(void) fprintf(stderr, "%s/dev warnings %s%s%s%s",
314	    pfx ? pfx : "",
315	    verb ? verb : "",
316	    verb ? " " : "",
317
318#if	defined(WARNDEVACCESS)
319	    "enabled",
320#else	/* !defined(WARNDEVACCESS) */
321	    "disabled",
322#endif	/* defined(WARNDEVACCESS) */
323
324	    punct);
325}
326
327
328/*
329 * usage() - display usage and exit
330 */
331
332void
333usage(xv, fh, version)
334	int xv;				/* exit value */
335	int fh;				/* ``-F ?'' status */
336	int version;			/* ``-v'' status */
337{
338	char buf[MAXPATHLEN+1], *cp, *cp1, *cp2;
339	int col, i;
340
341	if (Fhelp || xv) {
342	    (void) fprintf(stderr, "%s %s\n latest revision: %s\n",
343		Pn, LSOF_VERSION, LSOF_URL);
344	    (void) fprintf(stderr, " latest FAQ: %sFAQ\n", LSOF_URL);
345	    (void) fprintf(stderr, " latest man page: %slsof_man\n", LSOF_URL);
346	    (void) fprintf(stderr,
347		" usage: [-?ab%sh%slnNoOP%s%stUvV%s]",
348
349#if	defined(HASNCACHE)
350		"C",
351#else	/* !defined(HASNCACHE) */
352		"",
353#endif	/* defined(HASNCACHE) */
354
355#if	defined(HASTASKS)
356		"K",
357#else	/* !defined(HASTASKS) */
358		"",
359#endif	/* defined(HASTASKS) */
360
361#if	defined(HASPPID)
362		"R",
363#else	/* !defined(HASPPID) */
364		"",
365#endif	/* defined(HASPPID) */
366
367#if	defined(HASTCPUDPSTATE)
368		"",
369#else	/* !defined(HASTCPUDPSTATE) */
370		"s",
371#endif	/* defined(HASTCPUDPSTATE) */
372
373#if	defined(HASXOPT)
374# if	defined(HASXOPT_ROOT)
375		(Myuid == 0) ? "X" : ""
376# else	/* !defined(HASXOPT_ROOT) */
377		"X"
378# endif	/* defined(HASXOPT_ROOT) */
379#else	/* !defined(HASXOPT) */
380		""
381#endif	/* defined(HASXOPT) */
382
383	    );
384
385#if	defined(HAS_AFS) && defined(HASAOPT)
386	    (void) fprintf(stderr, " [-A A]");
387#endif	/* defined(HAS_AFS) && defined(HASAOPT) */
388
389	    (void) fprintf(stderr, " [+|-c c] [+|-d s] [+%sD D]",
390
391#if	defined(HASDCACHE)
392		"|-"
393#else	/* !defined(HASDCACHE) */
394		""
395#endif	/* defined(HASDCACHE) */
396
397		);
398
399	    (void) fprintf(stderr,
400		" [+|-f%s%s%s%s%s%s]%s\n [-F [f]] [-g [s]] [-i [i]]",
401
402#if	defined(HASFSTRUCT)
403		"[",
404
405# if	defined(HASNOFSCOUNT)
406		"",
407# else	/* !defined(HASNOFSCOUNT) */
408		"c",
409# endif	/* defined(HASNOFSCOUNT) */
410
411# if	defined(HASNOFSADDR)
412		"",
413# else	/* !defined(HASNOFSADDR) */
414		"f",
415# endif	/* defined(HASNOFSADDR) */
416
417# if	defined(HASNOFSFLAGS)
418		"",
419# else	/* !defined(HASNOFSFLAGS) */
420		"gG",
421# endif	/* defined(HASNOFSFLAGS) */
422
423# if	defined(HASNOFSNADDR)
424		"",
425# else	/* !defined(HASNOFSNADDR) */
426		"n",
427# endif	/* defined(HASNOFSNADDR) */
428
429		"]",
430#else	/* !defined(HASFSTRUCT) */
431		"", "", "", "", "", "",
432#endif	/* defined(HASFSTRUCT) */
433
434#if	defined(HASEOPT)
435		" [+|-e s]"
436#else	/* !defined(HASEOPT) */
437		""
438#endif	/* defined(HASEOPT) */
439
440		);
441
442#if	defined(HASKOPT)
443	    (void) fprintf(stderr, " [-k k]");
444#endif	/* defined(HASKOPT) */
445
446	    (void) fprintf(stderr, " [+|-L [l]]");
447
448#if	defined(HASMOPT) || defined(HASMNTSUP)
449	    (void) fprintf(stderr,
450# if	defined(HASMOPT)
451#  if	defined(HASMNTSUP)
452		" [+|-m [m]]"
453#  else	/* !defined(HASMNTSUP) */
454		" [-m m]"
455#  endif	/* defined(HASMNTSUP) */
456# else	/* !defined(HASMOPT) */
457		" [+m [m]]"
458# endif	/* defined(HASMOPT) */
459		);
460#endif	/* defined(HASMOPT) || defined(HASMNTSUP) */
461
462#if	!defined(HASNORPC_H)
463	    (void) fprintf(stderr, " [+|-M]");
464#endif	/* !defined(HASNORPC_H) */
465
466	    (void) fprintf(stderr,
467		" [-o [o]] [-p s]\n[+|-r [t]]%s [-S [t]] [-T [t]]",
468
469#if	defined(HASTCPUDPSTATE)
470		" [-s [p:s]]"
471#else	/* !defined(HASTCPUDPSTATE) */
472		""
473#endif	/* defined(HASTCPUDPSTATE) */
474
475		);
476	    (void) fprintf(stderr, " [-u s] [+|-w] [-x [fl]]");
477
478#if	defined(HASZONES)
479	    (void) fprintf(stderr, " [-z [z]]");
480#else	/* !defined(HASZONES) */
481# if	defined(HASSELINUX)
482	    if (CntxStatus)
483		(void) fprintf(stderr, " [-Z [Z]]");
484# endif	/* defined(HASSELINUX) */
485#endif	/* defined(HASZONES) */
486
487	    (void) fprintf(stderr, " [--] [names]\n");
488	}
489	if (xv && !Fhelp) {
490	    (void) fprintf(stderr,
491		"Use the ``-h'' option to get more help information.\n");
492	    if (!fh)
493    		Exit(xv);
494	}
495	if (Fhelp) {
496	    (void) fprintf(stderr,
497		"Defaults in parentheses; comma-separated set (s) items;");
498	    (void) fprintf(stderr, " dash-separated ranges.\n");
499	    col = print_in_col(1, "-?|-h list help");
500	    col = print_in_col(col, "-a AND selections (OR)");
501	    col = print_in_col(col, "-b avoid kernel blocks");
502	    col = print_in_col(col,  "-c c  cmd c ^c /c/[bix]");
503	    (void) snpf(buf, sizeof(buf), "+c w  COMMAND width (%d)", CMDL);
504	    col = print_in_col(col, buf);
505
506#if	defined(HASNCACHE)
507	   col = print_in_col(col, "-C no kernel name cache");
508#endif	/* defined(HASNCACHE) */
509
510	    col = print_in_col(col, "+d s  dir s files");
511	    col = print_in_col(col,  "-d s  select by FD set");
512	    col = print_in_col(col,  "+D D  dir D tree *SLOW?*");
513
514#if	defined(HASDCACHE)
515	    if (Setuidroot)
516		cp = "?|i|r";
517
518# if	!defined(WILLDROPGID)
519	    else if (Myuid)
520		cp = "?|i|r<path>";
521# endif	/* !defined(WILLDROPGID) */
522
523	    else
524		cp = "?|i|b|r|u[path]";
525	    (void) snpf(buf, sizeof(buf), "-D D  %s", cp);
526#else	/* !defined(HASDCACHE) */
527	    buf[0] = '\0';
528#endif	/* defined(HASDCACHE) */
529
530	    col = print_in_col(col, buf);
531
532#if	defined(HASEOPT)
533	    col = print_in_col(col, "+|-e s  exempt s *RISKY*");
534#endif	/* defined(HASEOPT) */
535
536	    (void) snpf(buf, sizeof(buf), "-i select IPv%s files",
537
538#if	defined(HASIPv6)
539			  "[46]"
540#else	/* !defined(HASIPv6) */
541			  "4"
542#endif	/* defined(HASIPv6) */
543
544			  );
545	    col = print_in_col(col, buf);
546
547#if	defined(HASTASKS)
548	    col = print_in_col(col, "-K list tasKs (threads)");
549#endif	/* defined(HASTASKS) */
550
551	    col = print_in_col(col, "-l list UID numbers");
552	    col = print_in_col(col, "-n no host names");
553	    col = print_in_col(col, "-N select NFS files");
554	    col = print_in_col(col, "-o list file offset");
555	    col = print_in_col(col, "-O no overhead *RISKY*");
556	    col = print_in_col(col, "-P no port names");
557
558#if	defined(HASPPID)
559	     col = print_in_col(col, "-R list paRent PID");
560#endif	/* defined(HASPPID) */
561
562	    col = print_in_col(col,  "-s list file size");
563	    col = print_in_col(col,  "-t terse listing");
564	    col = print_in_col(col,  "-T disable TCP/TPI info");
565	    col = print_in_col(col,  "-U select Unix socket");
566	    col = print_in_col(col,  "-v list version info");
567	    col = print_in_col(col,  "-V verbose search");
568	    (void) snpf(buf, sizeof(buf), "+|-w  Warnings (%s)",
569
570#if	defined(WARNINGSTATE)
571		"-");
572#else	/* !defined(WARNINGSTATE) */
573		"+");
574#endif	/* defined(WARNINGSTATE) */
575
576	    col = print_in_col(col, buf);
577
578#if	defined(HASXOPT)
579# if	defined(HASXOPT_ROOT)
580	    if (Myuid == 0)
581		(void) snpf(buf, sizeof(buf), "-X %s", HASXOPT);
582	    else
583		buf[0] = '\0';
584# else	/* !defined(HASXOPT_ROOT) */
585	    (void) snpf(buf, sizeof(buf), "-X %s", HASXOPT);
586# endif	/* defined(HASXOPT_ROOT) */
587# else	/* !defined(HASXOPT) */
588	    buf[0] = '\0';
589#endif	/* defined(HASXOPT) */
590
591	    col = print_in_col(col, buf);
592
593#if	defined(HASZONES)
594	    col = print_in_col(col, "-z z  zone [z]");
595#endif	/* defined(HASZONES) */
596
597#if	defined(HASSELINUX)
598	    col = print_in_col(col, "-Z Z  context [Z]");
599#endif	/* defined(HASSELINUX) */
600
601	    col = print_in_col(col, "-- end option scan");
602	    if (col != 1)
603		(void) fprintf(stderr, "\n");
604	    (void) fprintf(stderr, "  %-36.36s",
605		"+f|-f  +filesystem or -file names");
606
607#if	defined(HASFSTRUCT)
608	    (void) fprintf(stderr,
609		"  +|-f[%s%s%s%s]%s%s%s%s %s%s%s%s%s%s%s\n",
610
611# if	defined(HASNOFSCOUNT)
612		"",
613# else	/* !defined(HASNOFSCOUNT) */
614		"c",
615# endif	/* defined(HASNOFSCOUNT) */
616
617# if	defined(HASNOFSADDR)
618		"",
619# else	/* !defined(HASNOFSADDR) */
620		"f",
621# endif	/* defined(HASNOFSADDR) */
622
623# if	defined(HASNOFSFLAGS)
624		"",
625# else	/* !defined(HASNOFSFLAGS) */
626		"gG",
627# endif	/* defined(HASNOFSFLAGS) */
628
629# if	defined(HASNOFSNADDR)
630		"",
631# else	/* !defined(HASNOFSNADDR) */
632		"n",
633# endif	/* defined(HASNOFSNADDR) */
634
635# if	defined(HASNOFSCOUNT)
636		"",
637# else	/* !defined(HASNOFSCOUNT) */
638		" Ct",
639# endif	/* defined(HASNOFSCOUNT) */
640
641# if	defined(HASNOFSADDR)
642		"",
643# else	/* !defined(HASNOFSADDR) */
644		" Fstr",
645# endif	/* defined(HASNOFSADDR) */
646
647# if	defined(HASNOFSFLAGS)
648		"",
649# else	/* !defined(HASNOFSFLAGS) */
650		" flaGs",
651# endif	/* defined(HASNOFSFLAGS) */
652
653# if	defined(HASNOFSNADDR)
654		"",
655# else	/* !defined(HASNOFSNADDR) */
656		" Node",
657# endif	/* defined(HASNOFSNADDR) */
658
659		Fsv ? "(" : "",
660		(Fsv & FSV_CT) ? "C" : "",
661		(Fsv & FSV_FA) ? "F" : "",
662		((Fsv & FSV_FG) && FsvFlagX)  ? "g" : "",
663		((Fsv & FSV_FG) && !FsvFlagX) ? "G" : "",
664		(Fsv & FSV_NI) ? "N" : "",
665		Fsv ? ")" : "");
666#else	/* !defined(HASFSTRUCT) */
667	    putc('\n', stderr);
668#endif	/* defined(HASFSTRUCT) */
669
670	    (void) fprintf(stderr, "  %-36.36s",
671		"-F [f] select fields; -F? for help");
672
673#if	defined(HASKOPT)
674	    (void) fprintf(stderr,
675		"  -k k   kernel symbols (%s)\n",
676		Nmlst ? Nmlst
677# if	defined(N_UNIX)
678		      : N_UNIX
679# else	/* !defined(N_UNIX) */
680		      : (Nmlst = get_nlist_path(1)) ? Nmlst
681						    : "none found"
682# endif	/* defined(N_UNIX) */
683
684	    );
685#else	/* !defined(HASKOPT) */
686	    putc('\n', stderr);
687#endif	/* defined(HASKOPT) */
688
689	    (void) fprintf(stderr,
690		"  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)\n");
691
692#if	defined(HASMOPT) || defined(HASMNTSUP)
693# if	defined(HASMOPT)
694	    (void) snpf(buf, sizeof(buf), "-m m   kernel memory (%s)", KMEM);
695# else	/* !defined(HASMOPT) */
696	    buf[0] = '\0';
697# endif	/* defined(HASMOPT) */
698
699	    (void) fprintf(stderr, "  %-36.36s", buf);
700
701# if	defined(HASMNTSUP)
702	    (void) fprintf(stderr, "  +m [m] use|create mount supplement\n");
703# else	/* !defined(HASMNTSUP) */
704	    (void) fprintf(stderr, "\n");
705# endif	/* defined(HASMNTSUP) */
706#endif	/* defined(HASMOPT) || defined(HASMNTSUP) */
707
708#if	!defined(HASNORPC_H)
709	    (void) snpf(buf, sizeof(buf), "+|-M   portMap registration (%s)",
710
711# if	defined(HASPMAPENABLED)
712		"+"
713# else	/* !defined(HASPMAPENABLED) */
714		"-"
715# endif	/* defined(HASPMAPENABLED) */
716
717	    );
718#else	/* defined(HASNORPC_H) */
719	    buf[0] = '\0';
720#endif	/* !defined(HASNORPC_H) */
721
722	    (void) fprintf(stderr, "  %-36.36s", buf);
723	    (void) snpf(buf, sizeof(buf), "-o o   o 0t offset digits (%d)",
724		OFFDECDIG);
725	    (void) fprintf(stderr, "  %s\n", buf);
726	    (void) fprintf(stderr, "  %-36.36s",
727		"-p s   exclude(^)|select PIDs");
728	    (void) fprintf(stderr, "  -S [t] t second stat timeout (%d)\n",
729		TMLIMIT);
730	    (void) snpf(buf, sizeof(buf),
731		"-T %s%ss%s TCP/TPI %s%sSt%s (s) info",
732
733#if	defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)
734		"f",
735#else	/* !defined(HASSOOPT) && !defined(HASSOSTATE) && !defined(HASTCPOPT)*/
736		"",
737#endif	/* defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)*/
738
739#if 	defined(HASTCPTPIQ)
740		"q",
741#else	/* !defined(HASTCPTPIQ) */
742		" ",
743#endif	/* defined(HASTCPTPIQ) */
744
745#if 	defined(HASTCPTPIW)
746		"w",
747#else	/* !defined(HASTCPTPIW) */
748		"",
749#endif	/* defined(HASTCPTPIW) */
750
751#if	defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)
752		"Fl,",
753#else	/* !defined(HASSOOPT) && !defined(HASSOSTATE) && !defined(HASTCPOPT)*/
754		"",
755#endif	/* defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)*/
756
757#if 	defined(HASTCPTPIQ)
758		"Q,",
759#else	/* !defined(HASTCPTPIQ) */
760		"",
761#endif	/* defined(HASTCPTPIQ) */
762
763#if 	defined(HASTCPTPIW)
764		",Win"
765#else	/* !defined(HASTCPTPIW) */
766		""
767#endif	/* defined(HASTCPTPIW) */
768
769	    );
770	    (void) fprintf(stderr, "  %s\n", buf);
771
772#if	defined(HAS_AFS) && defined(HASAOPT)
773	    (void) fprintf(stderr,
774		"  -A A   AFS name list file (%s)\n", AFSAPATHDEF);
775#endif	/* defined(HAS_AFS) && defined(HASAOPT) */
776
777	    (void) fprintf(stderr,
778		"  -g [s] exclude(^)|select and print process group IDs\n");
779	    (void) fprintf(stderr, "  -i i   select by IPv%s address:",
780
781#if	defined(HASIPv6)
782			  "[46]"
783#else	/* !defined(HASIPv6) */
784			  "4"
785#endif	/* defined(HASIPv6) */
786
787			  );
788	    (void) fprintf(stderr,
789		" [%s][proto][@host|addr][:svc_list|port_list]\n",
790
791#if	defined(HASIPv6)
792		"46"
793#else	/* !defined(HASIPv6) */
794		"4"
795#endif	/* defined(HASIPv6) */
796
797		);
798
799	    (void) fprintf(stderr,
800		"  +|-r [%s] repeat every t seconds (%d); %s",
801
802#if	defined(HAS_STRFTIME)
803		"t[m<fmt>]",
804#else	/* !defined(has_STRFTIME) */
805		"t",
806#endif	/* defined(HAS_STRFTIME) */
807
808		RPTTM,
809		" + until no files, - forever.\n");
810
811#if	defined(HAS_STRFTIME)
812	    (void) fprintf(stderr,
813		"       An optional suffix to t is m<fmt>; m must separate %s",
814		"t from <fmt> and\n");
815	    (void) fprintf(stderr, "      <fmt> is an strftime(3) format %s",
816		"for the marker line.\n");
817#endif	/* defined(HAS_STRFTIME) */
818
819#if	defined(HASTCPUDPSTATE)
820	    (void) fprintf(stderr,
821		"  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states");
822	    (void) fprintf(stderr, " by name(s).\n");
823#endif	/* defined(HASTCPUDPSTATE) */
824
825	    (void) fprintf(stderr,
826		"  -u s   exclude(^)|select login|UID set s\n");
827	    (void) fprintf(stderr,
828		"  -x [fl] cross over +d|+D File systems or symbolic Links\n");
829	    (void) fprintf(stderr,
830		"  names  select named files or files on named file systems\n");
831	    (void) report_SECURITY(NULL, "; ");
832	    (void) report_WARNDEVACCESS(NULL, NULL, ";");
833	    (void) report_HASKERNIDCK(" k", NULL);
834	    (void) report_HASDCACHE(0, NULL, NULL);
835
836#if	defined(DIALECT_WARNING)
837	    (void) fprintf(stderr, "WARNING: %s\n", DIALECT_WARNING);
838#endif	/* defined(DIALECT_WARNING) */
839
840	}
841	if (fh) {
842	    (void) fprintf(stderr, "%s:\tID    field description\n", Pn);
843	    for (i = 0; FieldSel[i].nm; i++) {
844
845#if	!defined(HASPPID)
846		if (FieldSel[i].id == LSOF_FID_PPID)
847		    continue;
848#endif	/* !defined(HASPPID) */
849
850#if	!defined(HASFSTRUCT)
851		if (FieldSel[i].id == LSOF_FID_FA
852		||  FieldSel[i].id == LSOF_FID_CT
853		||  FieldSel[i].id == LSOF_FID_FG
854		||  FieldSel[i].id == LSOF_FID_NI)
855		    continue;
856#else	/* defined(HASFSTRUCT) */
857# if	defined(HASNOFSADDR)
858		if (FieldSel[i].id == LSOF_FID_FA)
859		    continue;
860# endif	/* defined(HASNOFSADDR) */
861
862# if	defined(HASNOFSCOUNT)
863		if (FieldSel[i].id == LSOF_FID_CT)
864		    continue;
865# endif	/* !defined(HASNOFSCOUNT) */
866
867# if	defined(HASNOFSFLAGS)
868		if (FieldSel[i].id == LSOF_FID_FG)
869		    continue;
870# endif	/* defined(HASNOFSFLAGS) */
871
872# if	defined(HASNOFSNADDR)
873		if (FieldSel[i].id == LSOF_FID_NI)
874		    continue;
875# endif	/* defined(HASNOFSNADDR) */
876#endif	/* !defined(HASFSTRUCT) */
877
878#if	!defined(HASZONES)
879		if (FieldSel[i].id == LSOF_FID_ZONE)
880		    continue;
881#endif	/* !defined(HASZONES) */
882
883#if	defined(HASSELINUX)
884		if ((FieldSel[i].id == LSOF_FID_CNTX) && !CntxStatus)
885		    continue;
886#else	/* !defined(HASSELINUX) */
887		if (FieldSel[i].id == LSOF_FID_CNTX)
888		    continue;
889#endif	/* !defined(HASSELINUX) */
890
891		(void) fprintf(stderr, "\t %c    %s\n",
892		    FieldSel[i].id, FieldSel[i].nm);
893	    }
894	}
895
896#if	defined(HASDCACHE)
897	if (DChelp)
898	    report_HASDCACHE(1, NULL, "    ");
899#endif	/* defined(HASDCACHE) */
900
901	if (version) {
902
903	/*
904	 * Display version information in reponse to ``-v''.
905	 */
906	    (void) fprintf(stderr, "%s version information:\n", Pn);
907	    (void) fprintf(stderr, "    revision: %s\n", LSOF_VERSION);
908	    (void) fprintf(stderr, "    latest revision: %s\n", LSOF_URL);
909	    (void) fprintf(stderr, "    latest FAQ: %sFAQ\n",
910		LSOF_URL);
911	    (void) fprintf(stderr, "    latest man page: %slsof_man\n",
912		LSOF_URL);
913
914#if	defined(LSOF_CINFO)
915	    if ((cp = isnullstr(LSOF_CINFO)))
916		(void) fprintf(stderr, "    configuration info: %s\n", cp);
917#endif	/* defined(LSOF_CINFO) */
918
919	    if ((cp = isnullstr(LSOF_CCDATE)))
920		(void) fprintf(stderr, "    constructed: %s\n", cp);
921	    cp = isnullstr(LSOF_HOST);
922	    if (!(cp1 = isnullstr(LSOF_LOGNAME)))
923		cp1 = isnullstr(LSOF_USER);
924	    if (cp || cp1) {
925		if (cp && cp1)
926		    cp2 = "by and on";
927		else if (cp)
928		    cp2 = "on";
929		else
930		    cp2 = "by";
931		(void) fprintf(stderr, "    constructed %s: %s%s%s\n",
932		    cp2,
933		    cp1 ? cp1 : "",
934		    (cp && cp1) ? "@" : "",
935		    cp  ? cp  : ""
936		);
937	    }
938
939#if	defined(LSOF_BLDCMT)
940	    if ((cp = isnullstr(LSOF_BLDCMT)))
941		(void) fprintf(stderr, "    builder's comment: %s\n", cp);
942#endif	/* defined(LSOF_BLDCMT) */
943
944	    if ((cp = isnullstr(LSOF_CC)))
945		(void) fprintf(stderr, "    compiler: %s\n", cp);
946	    if ((cp = isnullstr(LSOF_CCV)))
947		(void) fprintf(stderr, "    compiler version: %s\n", cp);
948	    if ((cp = isnullstr(LSOF_CCFLAGS)))
949		(void) fprintf(stderr, "    compiler flags: %s\n", cp);
950	    if ((cp = isnullstr(LSOF_LDFLAGS)))
951		(void) fprintf(stderr, "    loader flags: %s\n", cp);
952	    if ((cp = isnullstr(LSOF_SYSINFO)))
953		(void) fprintf(stderr, "    system info: %s\n", cp);
954	    (void) report_SECURITY("    ", ".\n");
955	    (void) report_WARNDEVACCESS("    ", "are", ".\n");
956	    (void) report_HASKERNIDCK("    K", "is");
957
958#if	defined(DIALECT_WARNING)
959	    (void) fprintf(stderr, "    WARNING: %s\n", DIALECT_WARNING);
960#endif	/* defined(DIALECT_WARNING) */
961
962	    (void) report_HASDCACHE(1, "    ", "\t");
963	}
964	Exit(xv);
965}
966