#ifndef lint
static char copyright[] =
"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n";
static char *rcsid = "$Id: print.c,v 1.50 2008/10/21 16:21:41 abe Exp $";
#endif
#include "lsof.h"
#define HCINC 64
#define PORTHASHBUCKETS 128
#define PORTTABTHRESH 10
struct hostcache {
unsigned char a[MAX_AF_ADDR];
int af;
char *name;
};
struct porttab {
int port;
MALLOC_S nl;
int ss;
char *name;
struct porttab *next;
};
static struct porttab **Pth[4] = { NULL, NULL, NULL, NULL };
#define HASHPORT(p) (((((int)(p)) * 31415) >> 3) & (PORTHASHBUCKETS - 1))
_PROTOTYPE(static void fill_portmap,(void));
_PROTOTYPE(static void fill_porttab,(void));
_PROTOTYPE(static char *lkup_port,(int p, int pr, int src));
_PROTOTYPE(static char *lkup_svcnam,(int h, int p, int pr, int ss));
_PROTOTYPE(static int printinaddr,(void));
_PROTOTYPE(static void update_portmap,(struct porttab *pt, char *pn));
char *
endnm(sz)
size_t *sz;
{
register char *s;
register size_t tsz;
for (s = Namech, tsz = Namechl; *s; s++, tsz--)
;
*sz = tsz;
return(s);
}
static void
fill_portmap()
{
char buf[128], *cp, *nm;
CLIENT *c;
int h, port, pr;
MALLOC_S nl;
struct pmaplist *p = (struct pmaplist *)NULL;
struct porttab *pt;
struct rpcent *r;
struct TIMEVAL_LSOF tm;
#if !defined(CAN_USE_CLNT_CREATE)
struct hostent *he;
struct sockaddr_in ia;
int s = RPC_ANYSOCK;
#endif
#if !defined(CAN_USE_CLNT_CREATE)
zeromem(&ia, sizeof(ia));
ia.sin_family = AF_INET;
if ((he = gethostbyname("localhost")))
MEMMOVE((caddr_t)&ia.sin_addr, he->h_addr, he->h_length);
ia.sin_port = htons(PMAPPORT);
#endif
tm.tv_sec = 60;
tm.tv_usec = 0;
#if defined(CAN_USE_CLNT_CREATE)
if (!(c = clnt_create("localhost", PMAPPROG, PMAPVERS, "tcp")))
#else
if (!(c = clnttcp_create(&ia, PMAPPROG, PMAPVERS, &s, 0, 0)))
#endif
return;
if (clnt_call(c, PMAPPROC_DUMP, XDR_VOID, NULL, XDR_PMAPLIST,
(caddr_t)&p, tm)
!= RPC_SUCCESS) {
clnt_destroy(c);
return;
}
for (; p; p = p->pml_next) {
if (p->pml_map.pm_prot == IPPROTO_TCP)
pr = 2;
else if (p->pml_map.pm_prot == IPPROTO_UDP)
pr = 3;
else
continue;
h = HASHPORT((port = (int)p->pml_map.pm_port));
for (pt = Pth[pr][h]; pt; pt = pt->next) {
if (pt->port == port)
break;
}
if (pt)
continue;
cp = (char *)NULL;
if ((r = (struct rpcent *)getrpcbynumber(p->pml_map.pm_prog))) {
if (r->r_name && strlen(r->r_name))
cp = r->r_name;
}
if (!cp) {
(void) snpf(buf, sizeof(buf), "%lu",
(unsigned long)p->pml_map.pm_prog);
cp = buf;
}
if (!strlen(cp))
continue;
if (!(nm = mkstrcpy(cp, &nl))) {
(void) fprintf(stderr,
"%s: can't allocate space for portmap entry: ", Pn);
safestrprt(cp, stderr, 1);
Exit(1);
}
if (!nl) {
(void) free((FREE_P *)nm);
continue;
}
if (!(pt = (struct porttab *)malloc(sizeof(struct porttab)))) {
(void) fprintf(stderr,
"%s: can't allocate porttab entry for portmap: ", Pn);
safestrprt(nm, stderr, 1);
Exit(1);
}
pt->name = nm;
pt->nl = nl;
pt->port = port;
pt->next = Pth[pr][h];
pt->ss = 0;
Pth[pr][h] = pt;
}
clnt_destroy(c);
}
static void
fill_porttab()
{
int h, p, pr;
MALLOC_S nl;
char *nm;
struct porttab *pt;
struct servent *se;
(void) endservent();
(void) setservent(1);
while ((se = getservent())) {
if (!se->s_name || !se->s_proto)
continue;
if (strcasecmp(se->s_proto, "TCP") == 0)
pr = 0;
else if (strcasecmp(se->s_proto, "UDP") == 0)
pr = 1;
else
continue;
if (!se->s_name || !strlen(se->s_name))
continue;
p = ntohs(se->s_port);
h = HASHPORT(p);
for (pt = Pth[pr][h]; pt; pt = pt->next) {
if (pt->port == p)
break;
}
if (pt)
continue;
if (!(nm = mkstrcpy(se->s_name, &nl))) {
(void) fprintf(stderr,
"%s: can't allocate %d bytes for port %d name: %s\n",
Pn, (int)(nl + 1), p, se->s_name);
Exit(1);
}
if (!nl) {
(void) free((FREE_P *)nm);
continue;
}
if (!(pt = (struct porttab *)malloc(sizeof(struct porttab)))) {
(void) fprintf(stderr,
"%s: can't allocate porttab entry for port %d: %s\n",
Pn, p, se->s_name);
Exit(1);
}
pt->name = nm;
pt->nl = nl - 1;
pt->port = p;
pt->next = Pth[pr][h];
pt->ss = 0;
Pth[pr][h] = pt;
}
(void) endservent();
}
char *
gethostnm(ia, af)
unsigned char *ia;
int af;
{
int al = MIN_AF_ADDR;
char hbuf[256];
static struct hostcache *hc = (struct hostcache *)NULL;
static int hcx = 0;
char *hn, *np;
struct hostent *he = (struct hostent *)NULL;
int i, j;
MALLOC_S len;
static int nhc = 0;
#if defined(HASIPv6)
if (af == AF_INET6)
al = MAX_AF_ADDR;
#endif
for (i = 0; i < hcx; i++) {
if (af != hc[i].af)
continue;
for (j = 0; j < al; j++) {
if (ia[j] != hc[i].a[j])
break;
}
if (j >= al)
return(hc[i].name);
}
if (Fhost)
he = gethostbyaddr((char *)ia, al, af);
if (!he || !he->h_name) {
#if defined(HASIPv6)
if (af == AF_INET6) {
hbuf[0] = '[';
if (!inet_ntop(af, ia, hbuf + 1, sizeof(hbuf) - 3)) {
(void) snpf(&hbuf[1], (sizeof(hbuf) - 1),
"can't format IPv6 address]");
} else {
len = strlen(hbuf);
(void) snpf(&hbuf[len], sizeof(hbuf) - len, "]");
}
} else
#endif
if (af == AF_INET)
(void) snpf(hbuf, sizeof(hbuf), "%u.%u.%u.%u", ia[0], ia[1],
ia[2], ia[3]);
else
(void) snpf(hbuf, sizeof(hbuf), "(unknown AF value: %d)", af);
hn = hbuf;
} else
hn = (char *)he->h_name;
if (!(np = mkstrcpy(hn, (MALLOC_S *)NULL))) {
(void) fprintf(stderr, "%s: no space for host name: ", Pn);
safestrprt(hn, stderr, 1);
Exit(1);
}
if (hcx >= nhc) {
nhc += HCINC;
len = (MALLOC_S)(nhc * sizeof(struct hostcache));
if (!hc)
hc = (struct hostcache *)malloc(len);
else
hc = (struct hostcache *)realloc((MALLOC_P *)hc, len);
if (!hc) {
(void) fprintf(stderr, "%s: no space for host cache\n", Pn);
Exit(1);
}
}
hc[hcx].af = af;
for (i = 0; i < al; i++) {
hc[hcx].a[i] = ia[i];
}
hc[hcx++].name = np;
return(np);
}
static char *
lkup_port(p, pr, src)
int p;
int pr;
int src;
{
int h, nh;
MALLOC_S nl;
char *nm, *pn;
static char pb[128];
static int pm = 0;
struct porttab *pt;
if (!Pth[0]) {
nh = FportMap ? 4 : 2;
for (h = 0; h < nh; h++) {
if (!(Pth[h] = (struct porttab **)calloc(PORTHASHBUCKETS,
sizeof(struct porttab *))))
{
(void) fprintf(stderr,
"%s: can't allocate %d bytes for %s %s hash buckets\n",
Pn,
(int)(2 * (PORTHASHBUCKETS * sizeof(struct porttab *))),
(h & 1) ? "UDP" : "TCP",
(h > 1) ? "portmap" : "port");
Exit(1);
}
}
}
if (FportMap && !pm) {
(void) fill_portmap();
pm++;
}
h = HASHPORT(p);
if (!src && FportMap) {
for (pt = Pth[pr+2][h]; pt; pt = pt->next) {
if (pt->port != p)
continue;
if (!pt->ss) {
pn = Fport ? lkup_svcnam(h, p, pr, 0) : (char *)NULL;
if (!pn) {
(void) snpf(pb, sizeof(pb), "%d", p);
pn = pb;
}
(void) update_portmap(pt, pn);
}
return(pt->name);
}
}
for (pt = Pth[pr][h]; pt; pt = pt->next) {
if (pt->port == p)
return(pt->name);
}
pn = Fport ? lkup_svcnam(h, p, pr, 1) : (char *)NULL;
if (!pn || !strlen(pn)) {
if (p) {
(void) snpf(pb, sizeof(pb), "%d", p);
return(pb);
} else
return("*");
}
if (!(pt = (struct porttab *)malloc(sizeof(struct porttab)))) {
(void) fprintf(stderr,
"%s: can't allocate porttab entry for port %d\n", Pn, p);
Exit(1);
}
if (!(nm = mkstrcpy(pn, &nl))) {
(void) fprintf(stderr,
"%s: can't allocate space for port name: ", Pn);
safestrprt(pn, stderr, 1);
Exit(1);
}
pt->name = nm;
pt->nl = nl;
pt->port = p;
pt->next = Pth[pr][h];
pt->ss = 0;
Pth[pr][h] = pt;
return(nm);
}
static char *
lkup_svcnam(h, p, pr, ss)
int h;
int p;
int pr;
int ss;
{
static int fl[PORTTABTHRESH];
static int fln = 0;
static int gsbp = 0;
int i;
struct porttab *pt;
static int ptf = 0;
struct servent *se;
if (!Fport)
return((char *)NULL);
for (;;) {
if (!ss) {
for (pt = Pth[pr][h]; pt; pt = pt->next) {
if (pt->port == p)
return(pt->name);
}
}
if (ptf)
break;
if (gsbp < PORTTABTHRESH) {
for (i = 0; i < fln; i++) {
if (fl[i] == p)
return((char *)NULL);
}
gsbp++;
if ((se = getservbyport(htons(p), pr ? "udp" : "tcp")))
return(se->s_name);
if (fln < PORTTABTHRESH)
fl[fln++] = p;
return((char *)NULL);
}
(void) fill_porttab();
ptf++;
ss = 0;
}
return((char *)NULL);
}
void
print_file()
{
char buf[128];
char *cp = (char *)NULL;
dev_t dev;
int devs, len;
if (PrPass && !Hdr) {
(void) printf("%-*.*s %*s", CmdColW, CmdColW, CMDTTL, PidColW,
PIDTTL);
#if defined(HASZONES)
if (Fzone)
(void) printf(" %-*s", ZoneColW, ZONETTL);
#endif
#if defined(HASSELINUX)
if (Fcntx)
(void) printf(" %-*s", CntxColW, CNTXTTL);
#endif
#if defined(HASPPID)
if (Fppid)
(void) printf(" %*s", PpidColW, PPIDTTL);
#endif
if (Fpgid)
(void) printf(" %*s", PgidColW, PGIDTTL);
(void) printf(" %*s %*s %*s",
UserColW, USERTTL,
FdColW - 2, FDTTL,
TypeColW, TYPETTL);
#if defined(HASFSTRUCT)
if (Fsv) {
# if !defined(HASNOFSADDR)
if (Fsv & FSV_FA)
(void) printf(" %*s", FsColW, FSTTL);
# endif
# if !defined(HASNOFSCOUNT)
if (Fsv & FSV_CT)
(void) printf(" %*s", FcColW, FCTTL);
# endif
# if !defined(HASNOFSFLAGS)
if (Fsv & FSV_FG)
(void) printf(" %*s", FgColW, FGTTL);
# endif
# if !defined(HASNOFSNADDR)
if (Fsv & FSV_NI)
(void) printf(" %*s", NiColW, NiTtl);
# endif
}
#endif
(void) printf(" %*s", DevColW, DEVTTL);
if (Foffset)
(void) printf(" %*s", SzOffColW, OFFTTL);
else if (Fsize)
(void) printf(" %*s", SzOffColW, SZTTL);
else
(void) printf(" %*s", SzOffColW, SZOFFTTL);
if (Fnlink)
(void) printf(" %*s", NlColW, NLTTL);
(void) printf(" %*s %s\n", NodeColW, NODETTL, NMTTL);
Hdr++;
}
cp = (Lp->cmd && *Lp->cmd != '\0') ? Lp->cmd : "(unknown)";
if (!PrPass) {
len = safestrlen(cp, 2);
if (CmdLim && (len > CmdLim))
len = CmdLim;
if (len > CmdColW)
CmdColW = len;
} else
safestrprtn(cp, CmdColW, stdout, 2);
if (!PrPass) {
(void) snpf(buf, sizeof(buf), "%d", Lp->pid);
if ((len = strlen(buf)) > PidColW)
PidColW = len;
} else
(void) printf(" %*d", PidColW, Lp->pid);
#if defined(HASZONES)
if (Fzone) {
if (!PrPass) {
if (Lp->zn) {
if ((len = strlen(Lp->zn)) > ZoneColW)
ZoneColW = len;
}
} else
(void) printf(" %-*s", ZoneColW, Lp->zn ? Lp->zn : "");
}
#endif
#if defined(HASSELINUX)
if (Fcntx) {
if (!PrPass) {
if (Lp->cntx) {
if ((len = strlen(Lp->cntx)) > CntxColW)
CntxColW = len;
}
} else
(void) printf(" %-*s", CntxColW, Lp->cntx ? Lp->cntx : "");
}
#endif
#if defined(HASPPID)
if (Fppid) {
if (!PrPass) {
(void) snpf(buf, sizeof(buf), "%d", Lp->ppid);
if ((len = strlen(buf)) > PpidColW)
PpidColW = len;
} else
(void) printf(" %*d", PpidColW, Lp->ppid);
}
#endif
if (Fpgid) {
if (!PrPass) {
(void) snpf(buf, sizeof(buf), "%d", Lp->pgid);
if ((len = strlen(buf)) > PgidColW)
PgidColW = len;
} else
(void) printf(" %*d", PgidColW, Lp->pgid);
}
if (!PrPass) {
if ((len = strlen(printuid((UID_ARG)Lp->uid, NULL))) > UserColW)
UserColW = len;
} else
(void) printf(" %*.*s", UserColW, UserColW,
printuid((UID_ARG)Lp->uid, NULL));
if (!PrPass) {
(void) snpf(buf, sizeof(buf), "%s%c%c",
Lf->fd,
(Lf->lock == ' ') ? Lf->access
: (Lf->access == ' ') ? '-'
: Lf->access,
Lf->lock);
if ((len = strlen(buf)) > FdColW)
FdColW = len;
} else
(void) printf(" %*.*s%c%c", FdColW - 2, FdColW - 2, Lf->fd,
(Lf->lock == ' ') ? Lf->access
: (Lf->access == ' ') ? '-'
: Lf->access,
Lf->lock);
if (!PrPass) {
if ((len = strlen(Lf->type)) > TypeColW)
TypeColW = len;
} else
(void) printf(" %*.*s", TypeColW, TypeColW, Lf->type);
#if defined(HASFSTRUCT)
if (Fsv) {
# if !defined(HASNOFSADDR)
if (Fsv & FSV_FA) {
cp = (Lf->fsv & FSV_FA) ? print_kptr(Lf->fsa, buf, sizeof(buf))
: "";
if (!PrPass) {
if ((len = strlen(cp)) > FsColW)
FsColW = len;
} else
(void) printf(" %*.*s", FsColW, FsColW, cp);
}
# endif
# if !defined(HASNOFSCOUNT)
if (Fsv & FSV_CT) {
if (Lf->fsv & FSV_CT) {
(void) snpf(buf, sizeof(buf), "%ld", Lf->fct);
cp = buf;
} else
cp = "";
if (!PrPass) {
if ((len = strlen(cp)) > FcColW)
FcColW = len;
} else
(void) printf(" %*.*s", FcColW, FcColW, cp);
}
# endif
# if !defined(HASNOFSFLAGS)
if (Fsv & FSV_FG) {
if ((Lf->fsv & FSV_FG) && (FsvFlagX || Lf->ffg || Lf->pof))
cp = print_fflags(Lf->ffg, Lf->pof);
else
cp = "";
if (!PrPass) {
if ((len = strlen(cp)) > FgColW)
FgColW = len;
} else
(void) printf(" %*.*s", FgColW, FgColW, cp);
}
# endif
# if !defined(HASNOFSNADDR)
if (Fsv & FSV_NI) {
cp = (Lf->fsv & FSV_NI) ? print_kptr(Lf->fna, buf, sizeof(buf))
: "";
if (!PrPass) {
if ((len = strlen(cp)) > NiColW)
NiColW = len;
} else
(void) printf(" %*.*s", NiColW, NiColW, cp);
}
# endif
}
#endif
if (Lf->rdev_def) {
dev = Lf->rdev;
devs = 1;
} else if (Lf->dev_def) {
dev = Lf->dev;
devs = 1;
} else
devs = 0;
if (devs) {
#if defined(HASPRINTDEV)
cp = HASPRINTDEV(Lf, &dev);
#else
(void) snpf(buf, sizeof(buf), "%u,%u", GET_MAJ_DEV(dev),
GET_MIN_DEV(dev));
cp = buf;
#endif
}
if (!PrPass) {
if (devs)
len = strlen(cp);
else if (Lf->dev_ch)
len = strlen(Lf->dev_ch);
else
len = 0;
if (len > DevColW)
DevColW = len;
} else {
if (devs)
(void) printf(" %*.*s", DevColW, DevColW, cp);
else {
if (Lf->dev_ch)
(void) printf(" %*.*s", DevColW, DevColW, Lf->dev_ch);
else
(void) printf(" %*.*s", DevColW, DevColW, "");
}
}
if (!PrPass) {
if (Lf->sz_def) {
#if defined(HASPRINTSZ)
cp = HASPRINTSZ(Lf);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_d, Lf->sz);
cp = buf;
#endif
len = strlen(cp);
} else if (Lf->off_def) {
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 0);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_0t, Lf->off);
cp = buf;
#endif
len = strlen(cp);
if (OffDecDig && len > (OffDecDig + 2)) {
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 1);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_x, Lf->off);
cp = buf;
#endif
len = strlen(cp);
}
} else
len = 0;
if (len > SzOffColW)
SzOffColW = len;
} else {
putchar(' ');
if (Lf->sz_def)
#if defined(HASPRINTSZ)
(void) printf("%*.*s", SzOffColW, SzOffColW, HASPRINTSZ(Lf));
#else
(void) printf(SzOffFmt_dv, SzOffColW, Lf->sz);
#endif
else if (Lf->off_def) {
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 0);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_0t, Lf->off);
cp = buf;
#endif
if (OffDecDig && (int)strlen(cp) > (OffDecDig + 2)) {
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 1);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_x, Lf->off);
cp = buf;
#endif
}
(void) printf("%*.*s", SzOffColW, SzOffColW, cp);
} else
(void) printf("%*.*s", SzOffColW, SzOffColW, "");
}
if (Fnlink) {
if (Lf->nlink_def) {
(void) snpf(buf, sizeof(buf), " %ld", Lf->nlink);
cp = buf;
} else
cp = "";
if (!PrPass) {
if ((len = strlen(cp)) > NlColW)
NlColW = len;
} else
(void) printf(" %*s", NlColW, cp);
}
switch (Lf->inp_ty) {
case 1:
#if defined(HASPRINTINO)
cp = HASPRINTINO(Lf);
#else
(void) snpf(buf, sizeof(buf), InodeFmt_d, Lf->inode);
cp = buf;
#endif
break;
case 2:
if (Lf->iproto[0])
cp = Lf->iproto;
else
cp = "";
break;
case 3:
(void) snpf(buf, sizeof(buf), InodeFmt_x, Lf->inode);
cp = buf;
break;
default:
cp = "";
}
if (!PrPass) {
if ((len = strlen(cp)) > NodeColW)
NodeColW = len;
} else {
(void) printf(" %*.*s", NodeColW, NodeColW, cp);
}
if (PrPass) {
putchar(' ');
#if defined(HASPRINTNM)
HASPRINTNM(Lf);
#else
printname(1);
#endif
}
}
static int
printinaddr()
{
int i, len, src;
char *host, *port;
int nl = Namechl - 1;
char *np = Namech;
char pbuf[32];
for (i = 0, *np = '\0'; i < 2; i++) {
if (!Lf->li[i].af)
continue;
host = port = (char *)NULL;
if (i) {
if (nl < 2)
addr_too_long:
{
(void) snpf(Namech, Namechl,
"network addresses too long");
return(1);
}
(void) snpf(np, nl, "->");
np += 2;
nl -= 2;
}
#if defined(HASIPv6)
if ((Lf->li[i].af == AF_INET6
&& IN6_IS_ADDR_UNSPECIFIED(&Lf->li[i].ia.a6))
|| (Lf->li[i].af == AF_INET
&& Lf->li[i].ia.a4.s_addr == INADDR_ANY))
host ="*";
else
host = gethostnm((unsigned char *)&Lf->li[i].ia, Lf->li[i].af);
#else
if (Lf->li[i].ia.a4.s_addr == INADDR_ANY)
host ="*";
else
host = gethostnm((unsigned char *)&Lf->li[i].ia, Lf->li[i].af);
#endif
if (Lf->li[i].p > 0) {
if (Fport || FportMap) {
if ((src = i) && FportMap) {
#if defined(HASIPv6)
if (Lf->li[0].af == AF_INET6) {
if (IN6_IS_ADDR_LOOPBACK(&Lf->li[i].ia.a6)
|| IN6_ARE_ADDR_EQUAL(&Lf->li[0].ia.a6,
&Lf->li[1].ia.a6)
)
src = 0;
} else
#endif
if (Lf->li[0].af == AF_INET) {
if (Lf->li[i].ia.a4.s_addr == htonl(INADDR_LOOPBACK)
|| Lf->li[0].ia.a4.s_addr == Lf->li[1].ia.a4.s_addr
)
src = 0;
}
}
if (strcasecmp(Lf->iproto, "TCP") == 0)
port = lkup_port(Lf->li[i].p, 0, src);
else if (strcasecmp(Lf->iproto, "UDP") == 0)
port = lkup_port(Lf->li[i].p, 1, src);
}
if (!port) {
(void) snpf(pbuf, sizeof(pbuf), "%d", Lf->li[i].p);
port = pbuf;
}
} else if (Lf->li[i].p == 0)
port = "*";
if (host) {
if ((len = strlen(host)) > nl)
goto addr_too_long;
if (len) {
(void) snpf(np, nl, "%s", host);
np += len;
nl -= len;
}
}
if (port) {
if (((len = strlen(port)) + 1) >= nl)
goto addr_too_long;
(void) snpf(np, nl, ":%s", port);
np += len + 1;
nl -= len - 1;
}
}
if (Namech[0]) {
safestrprt(Namech, stdout, 0);
return(1);
}
return(0);
}
void
print_init()
{
PrPass = (Ffield || Fterse) ? 1 : 0;
CmdColW = strlen(CMDTTL);
DevColW = strlen(DEVTTL);
FdColW = strlen(FDTTL);
if (Fnlink)
NlColW = strlen(NLTTL);
NmColW = strlen(NMTTL);
NodeColW = strlen(NODETTL);
PgidColW = strlen(PGIDTTL);
PidColW = strlen(PIDTTL);
PpidColW = strlen(PPIDTTL);
if (Fsize)
SzOffColW = strlen(SZTTL);
else if (Foffset)
SzOffColW = strlen(OFFTTL);
else
SzOffColW = strlen(SZOFFTTL);
TypeColW = strlen(TYPETTL);
UserColW = strlen(USERTTL);
#if defined(HASFSTRUCT)
# if !defined(HASNOFSADDR)
FsColW = strlen(FSTTL);
# endif
# if !defined(HASNOFSCOUNT)
FcColW = strlen(FCTTL);
# endif
# if !defined(HASNOFSFLAGS)
FgColW = strlen(FGTTL);
# endif
# if !defined(HASNOFSNADDR)
NiColW = strlen(NiTtl);
# endif
#endif
#if defined(HASSELINUX)
if (Fcntx)
CntxColW = strlen(CNTXTTL);
#endif
#if defined(HASZONES)
if (Fzone)
ZoneColW = strlen(ZONETTL);
#endif
}
#if !defined(HASPRIVPRIPP)
void
printiproto(p)
int p;
{
int i;
static int m = -1;
char *s;
switch (p) {
#if defined(IPPROTO_TCP)
case IPPROTO_TCP:
s = "TCP";
break;
#endif
#if defined(IPPROTO_UDP)
case IPPROTO_UDP:
s = "UDP";
break;
#endif
#if defined(IPPROTO_IP)
# if !defined(IPPROTO_HOPOPTS) || IPPROTO_IP!=IPPROTO_HOPOPTS
case IPPROTO_IP:
s = "IP";
break;
# endif
#endif
#if defined(IPPROTO_ICMP)
case IPPROTO_ICMP:
s = "ICMP";
break;
#endif
#if defined(IPPROTO_ICMPV6)
case IPPROTO_ICMPV6:
s = "ICMPV6";
break;
#endif
#if defined(IPPROTO_IGMP)
case IPPROTO_IGMP:
s = "IGMP";
break;
#endif
#if defined(IPPROTO_GGP)
case IPPROTO_GGP:
s = "GGP";
break;
#endif
#if defined(IPPROTO_EGP)
case IPPROTO_EGP:
s = "EGP";
break;
#endif
#if defined(IPPROTO_PUP)
case IPPROTO_PUP:
s = "PUP";
break;
#endif
#if defined(IPPROTO_IDP)
case IPPROTO_IDP:
s = "IDP";
break;
#endif
#if defined(IPPROTO_ND)
case IPPROTO_ND:
s = "ND";
break;
#endif
#if defined(IPPROTO_RAW)
case IPPROTO_RAW:
s = "RAW";
break;
#endif
#if defined(IPPROTO_HELLO)
case IPPROTO_HELLO:
s = "HELLO";
break;
#endif
#if defined(IPPROTO_PXP)
case IPPROTO_PXP:
s = "PXP";
break;
#endif
#if defined(IPPROTO_RAWIP)
case IPPROTO_RAWIP:
s = "RAWIP";
break;
#endif
#if defined(IPPROTO_RAWIF)
case IPPROTO_RAWIF:
s = "RAWIF";
break;
#endif
#if defined(IPPROTO_HOPOPTS)
case IPPROTO_HOPOPTS:
s = "HOPOPTS";
break;
#endif
#if defined(IPPROTO_IPIP)
case IPPROTO_IPIP:
s = "IPIP";
break;
#endif
#if defined(IPPROTO_ST)
case IPPROTO_ST:
s = "ST";
break;
#endif
#if defined(IPPROTO_PIGP)
case IPPROTO_PIGP:
s = "PIGP";
break;
#endif
#if defined(IPPROTO_RCCMON)
case IPPROTO_RCCMON:
s = "RCCMON";
break;
#endif
#if defined(IPPROTO_NVPII)
case IPPROTO_NVPII:
s = "NVPII";
break;
#endif
#if defined(IPPROTO_ARGUS)
case IPPROTO_ARGUS:
s = "ARGUS";
break;
#endif
#if defined(IPPROTO_EMCON)
case IPPROTO_EMCON:
s = "EMCON";
break;
#endif
#if defined(IPPROTO_XNET)
case IPPROTO_XNET:
s = "XNET";
break;
#endif
#if defined(IPPROTO_CHAOS)
case IPPROTO_CHAOS:
s = "CHAOS";
break;
#endif
#if defined(IPPROTO_MUX)
case IPPROTO_MUX:
s = "MUX";
break;
#endif
#if defined(IPPROTO_MEAS)
case IPPROTO_MEAS:
s = "MEAS";
break;
#endif
#if defined(IPPROTO_HMP)
case IPPROTO_HMP:
s = "HMP";
break;
#endif
#if defined(IPPROTO_PRM)
case IPPROTO_PRM:
s = "PRM";
break;
#endif
#if defined(IPPROTO_TRUNK1)
case IPPROTO_TRUNK1:
s = "TRUNK1";
break;
#endif
#if defined(IPPROTO_TRUNK2)
case IPPROTO_TRUNK2:
s = "TRUNK2";
break;
#endif
#if defined(IPPROTO_LEAF1)
case IPPROTO_LEAF1:
s = "LEAF1";
break;
#endif
#if defined(IPPROTO_LEAF2)
case IPPROTO_LEAF2:
s = "LEAF2";
break;
#endif
#if defined(IPPROTO_RDP)
case IPPROTO_RDP:
s = "RDP";
break;
#endif
#if defined(IPPROTO_IRTP)
case IPPROTO_IRTP:
s = "IRTP";
break;
#endif
#if defined(IPPROTO_TP)
case IPPROTO_TP:
s = "TP";
break;
#endif
#if defined(IPPROTO_BLT)
case IPPROTO_BLT:
s = "BLT";
break;
#endif
#if defined(IPPROTO_NSP)
case IPPROTO_NSP:
s = "NSP";
break;
#endif
#if defined(IPPROTO_INP)
case IPPROTO_INP:
s = "INP";
break;
#endif
#if defined(IPPROTO_SEP)
case IPPROTO_SEP:
s = "SEP";
break;
#endif
#if defined(IPPROTO_3PC)
case IPPROTO_3PC:
s = "3PC";
break;
#endif
#if defined(IPPROTO_IDPR)
case IPPROTO_IDPR:
s = "IDPR";
break;
#endif
#if defined(IPPROTO_XTP)
case IPPROTO_XTP:
s = "XTP";
break;
#endif
#if defined(IPPROTO_DDP)
case IPPROTO_DDP:
s = "DDP";
break;
#endif
#if defined(IPPROTO_CMTP)
case IPPROTO_CMTP:
s = "CMTP";
break;
#endif
#if defined(IPPROTO_TPXX)
case IPPROTO_TPXX:
s = "TPXX";
break;
#endif
#if defined(IPPROTO_IL)
case IPPROTO_IL:
s = "IL";
break;
#endif
#if defined(IPPROTO_IPV6)
case IPPROTO_IPV6:
s = "IPV6";
break;
#endif
#if defined(IPPROTO_SDRP)
case IPPROTO_SDRP:
s = "SDRP";
break;
#endif
#if defined(IPPROTO_ROUTING)
case IPPROTO_ROUTING:
s = "ROUTING";
break;
#endif
#if defined(IPPROTO_FRAGMENT)
case IPPROTO_FRAGMENT:
s = "FRAGMNT";
break;
#endif
#if defined(IPPROTO_IDRP)
case IPPROTO_IDRP:
s = "IDRP";
break;
#endif
#if defined(IPPROTO_RSVP)
case IPPROTO_RSVP:
s = "RSVP";
break;
#endif
#if defined(IPPROTO_GRE)
case IPPROTO_GRE:
s = "GRE";
break;
#endif
#if defined(IPPROTO_MHRP)
case IPPROTO_MHRP:
s = "MHRP";
break;
#endif
#if defined(IPPROTO_BHA)
case IPPROTO_BHA:
s = "BHA";
break;
#endif
#if defined(IPPROTO_ESP)
case IPPROTO_ESP:
s = "ESP";
break;
#endif
#if defined(IPPROTO_AH)
case IPPROTO_AH:
s = "AH";
break;
#endif
#if defined(IPPROTO_INLSP)
case IPPROTO_INLSP:
s = "INLSP";
break;
#endif
#if defined(IPPROTO_SWIPE)
case IPPROTO_SWIPE:
s = "SWIPE";
break;
#endif
#if defined(IPPROTO_NHRP)
case IPPROTO_NHRP:
s = "NHRP";
break;
#endif
#if defined(IPPROTO_NONE)
case IPPROTO_NONE:
s = "NONE";
break;
#endif
#if defined(IPPROTO_DSTOPTS)
case IPPROTO_DSTOPTS:
s = "DSTOPTS";
break;
#endif
#if defined(IPPROTO_AHIP)
case IPPROTO_AHIP:
s = "AHIP";
break;
#endif
#if defined(IPPROTO_CFTP)
case IPPROTO_CFTP:
s = "CFTP";
break;
#endif
#if defined(IPPROTO_SATEXPAK)
case IPPROTO_SATEXPAK:
s = "SATEXPK";
break;
#endif
#if defined(IPPROTO_KRYPTOLAN)
case IPPROTO_KRYPTOLAN:
s = "KRYPTOL";
break;
#endif
#if defined(IPPROTO_RVD)
case IPPROTO_RVD:
s = "RVD";
break;
#endif
#if defined(IPPROTO_IPPC)
case IPPROTO_IPPC:
s = "IPPC";
break;
#endif
#if defined(IPPROTO_ADFS)
case IPPROTO_ADFS:
s = "ADFS";
break;
#endif
#if defined(IPPROTO_SATMON)
case IPPROTO_SATMON:
s = "SATMON";
break;
#endif
#if defined(IPPROTO_VISA)
case IPPROTO_VISA:
s = "VISA";
break;
#endif
#if defined(IPPROTO_IPCV)
case IPPROTO_IPCV:
s = "IPCV";
break;
#endif
#if defined(IPPROTO_CPNX)
case IPPROTO_CPNX:
s = "CPNX";
break;
#endif
#if defined(IPPROTO_CPHB)
case IPPROTO_CPHB:
s = "CPHB";
break;
#endif
#if defined(IPPROTO_WSN)
case IPPROTO_WSN:
s = "WSN";
break;
#endif
#if defined(IPPROTO_PVP)
case IPPROTO_PVP:
s = "PVP";
break;
#endif
#if defined(IPPROTO_BRSATMON)
case IPPROTO_BRSATMON:
s = "BRSATMN";
break;
#endif
#if defined(IPPROTO_WBMON)
case IPPROTO_WBMON:
s = "WBMON";
break;
#endif
#if defined(IPPROTO_WBEXPAK)
case IPPROTO_WBEXPAK:
s = "WBEXPAK";
break;
#endif
#if defined(IPPROTO_EON)
case IPPROTO_EON:
s = "EON";
break;
#endif
#if defined(IPPROTO_VMTP)
case IPPROTO_VMTP:
s = "VMTP";
break;
#endif
#if defined(IPPROTO_SVMTP)
case IPPROTO_SVMTP:
s = "SVMTP";
break;
#endif
#if defined(IPPROTO_VINES)
case IPPROTO_VINES:
s = "VINES";
break;
#endif
#if defined(IPPROTO_TTP)
case IPPROTO_TTP:
s = "TTP";
break;
#endif
#if defined(IPPROTO_IGP)
case IPPROTO_IGP:
s = "IGP";
break;
#endif
#if defined(IPPROTO_DGP)
case IPPROTO_DGP:
s = "DGP";
break;
#endif
#if defined(IPPROTO_TCF)
case IPPROTO_TCF:
s = "TCF";
break;
#endif
#if defined(IPPROTO_IGRP)
case IPPROTO_IGRP:
s = "IGRP";
break;
#endif
#if defined(IPPROTO_OSPFIGP)
case IPPROTO_OSPFIGP:
s = "OSPFIGP";
break;
#endif
#if defined(IPPROTO_SRPC)
case IPPROTO_SRPC:
s = "SRPC";
break;
#endif
#if defined(IPPROTO_LARP)
case IPPROTO_LARP:
s = "LARP";
break;
#endif
#if defined(IPPROTO_MTP)
case IPPROTO_MTP:
s = "MTP";
break;
#endif
#if defined(IPPROTO_AX25)
case IPPROTO_AX25:
s = "AX25";
break;
#endif
#if defined(IPPROTO_IPEIP)
case IPPROTO_IPEIP:
s = "IPEIP";
break;
#endif
#if defined(IPPROTO_MICP)
case IPPROTO_MICP:
s = "MICP";
break;
#endif
#if defined(IPPROTO_SCCSP)
case IPPROTO_SCCSP:
s = "SCCSP";
break;
#endif
#if defined(IPPROTO_ETHERIP)
case IPPROTO_ETHERIP:
s = "ETHERIP";
break;
#endif
#if defined(IPPROTO_ENCAP)
# if !defined(IPPROTO_IPIP) || IPPROTO_IPIP!=IPPROTO_ENCAP
case IPPROTO_ENCAP:
s = "ENCAP";
break;
# endif
#endif
#if defined(IPPROTO_APES)
case IPPROTO_APES:
s = "APES";
break;
#endif
#if defined(IPPROTO_GMTP)
case IPPROTO_GMTP:
s = "GMTP";
break;
#endif
#if defined(IPPROTO_DIVERT)
case IPPROTO_DIVERT:
s = "DIVERT";
break;
#endif
default:
s = (char *)NULL;
}
if (s)
(void) snpf(Lf->iproto, sizeof(Lf->iproto), "%.*s", IPROTOL-1, s);
else {
if (m < 0) {
for (i = 0, m = 1; i < IPROTOL-2; i++)
m *= 10;
}
if (m > p)
(void) snpf(Lf->iproto, sizeof(Lf->iproto), "%d?", p);
else
(void) snpf(Lf->iproto, sizeof(Lf->iproto), "*%d?", p % (m/10));
}
}
#endif
void
printname(nl)
int nl;
{
#if defined(HASNCACHE)
char buf[MAXPATHLEN];
char *cp;
int fp;
#endif
int ps = 0;
if (Lf->nm && Lf->nm[0]) {
safestrprt(Lf->nm, stdout, 0);
ps++;
if (!Lf->li[0].af && !Lf->li[1].af)
goto print_nma;
}
if (Lf->li[0].af || Lf->li[1].af) {
if (ps)
putchar(' ');
if (printinaddr())
ps++;
goto print_nma;
}
if (((Lf->ntype == N_BLK) || (Lf->ntype == N_CHR))
&& Lf->dev_def && Lf->rdev_def
&& printdevname(&Lf->dev, &Lf->rdev, 0, Lf->ntype))
{
ps++;
goto print_nma;
}
if (Lf->is_com) {
(void) fputs("COMMON: ", stdout);
ps++;
goto print_nma;
}
#if defined(HASPRIVNMCACHE)
if (HASPRIVNMCACHE(Lf)) {
ps++;
goto print_nma;
}
#endif
if (Lf->lmi_srch) {
struct mounts *mp;
for (mp = readmnt(); mp; mp = mp->next) {
if (Lf->dev == mp->dev) {
Lf->fsdir = mp->dir;
Lf->fsdev = mp->fsname;
#if defined(HASFSINO)
Lf->fs_ino = mp->inode;
#endif
break;
}
}
Lf->lmi_srch = 0;
}
if (Lf->fsdir || Lf->fsdev) {
#if !defined(HASNCACHE) || HASNCACHE<2
if (Lf->fsdir) {
safestrprt(Lf->fsdir, stdout, 0);
ps++;
}
#endif
#if defined(HASNCACHE)
# if HASNCACHE<2
if (Lf->na) {
if (NcacheReload) {
# if defined(NCACHELDPFX)
NCACHELDPFX
# endif
(void) ncache_load();
# if defined(NCACHELDSFX)
NCACHELDSFX
# endif
NcacheReload = 0;
}
if ((cp = ncache_lookup(buf, sizeof(buf), &fp))) {
char *cp1;
if (*cp == '\0')
goto print_nma;
if (fp && Lf->fsdir) {
if (*cp != '/') {
cp1 = strrchr(Lf->fsdir, '/');
if (cp1 == (char *)NULL || *(cp1 + 1) != '\0')
putchar('/');
}
} else
(void) fputs(" -- ", stdout);
safestrprt(cp, stdout, 0);
ps++;
goto print_nma;
}
}
# else
if (NcacheReload) {
# if defined(NCACHELDPFX)
NCACHELDPFX
# endif
(void) ncache_load();
# if defined(NCACHELDSFX)
NCACHELDSFX
# endif
NcacheReload = 0;
}
if ((cp = ncache_lookup(buf, sizeof(buf), &fp))) {
if (fp) {
safestrprt(cp, stdout, 0);
ps++;
} else {
if (Lf->fsdir) {
safestrprt(Lf->fsdir, stdout, 0);
ps++;
}
if (*cp) {
(void) fputs(" -- ", stdout);
safestrprt(cp, stdout, 0);
ps++;
}
}
goto print_nma;
}
if (Lf->fsdir) {
safestrprt(Lf->fsdir, stdout, 0);
ps++;
}
# endif
#endif
if (Lf->fsdev) {
if (Lf->fsdir)
(void) fputs(" (", stdout);
else
(void) putchar('(');
safestrprt(Lf->fsdev, stdout, 0);
(void) putchar(')');
ps++;
}
}
print_nma:
if (Lf->nma) {
if (ps)
putchar(' ');
safestrprt(Lf->nma, stdout, 0);
ps++;
}
if (!Ffield && Ftcptpi
&& (Lf->lts.type >= 0
#if defined(HASTCPTPIQ)
|| ((Ftcptpi & TCPTPI_QUEUES) && (Lf->lts.rqs || Lf->lts.sqs))
#endif
#if defined(HASTCPTPIW)
|| ((Ftcptpi & TCPTPI_WINDOWS) && (Lf->lts.rws || Lf->lts.wws))
#endif
)) {
if (ps)
putchar(' ');
(void) print_tcptpi(1);
return;
}
if (nl)
putchar('\n');
}
void
printrawaddr(sa)
struct sockaddr *sa;
{
char *ep;
size_t sz;
ep = endnm(&sz);
(void) snpf(ep, sz, "%u/%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u",
sa->sa_family,
(unsigned char)sa->sa_data[0],
(unsigned char)sa->sa_data[1],
(unsigned char)sa->sa_data[2],
(unsigned char)sa->sa_data[3],
(unsigned char)sa->sa_data[4],
(unsigned char)sa->sa_data[5],
(unsigned char)sa->sa_data[6],
(unsigned char)sa->sa_data[7],
(unsigned char)sa->sa_data[8],
(unsigned char)sa->sa_data[9],
(unsigned char)sa->sa_data[10],
(unsigned char)sa->sa_data[11],
(unsigned char)sa->sa_data[12],
(unsigned char)sa->sa_data[13]);
}
char *
printsockty(ty)
int ty;
{
static char buf[64];
char *cp;
switch (ty) {
#if defined(SOCK_STREAM)
case SOCK_STREAM:
cp = "STREAM";
break;
#endif
#if defined(SOCK_STREAM)
case SOCK_DGRAM:
cp = "DGRAM";
break;
#endif
#if defined(SOCK_RAW)
case SOCK_RAW:
cp = "RAW";
break;
#endif
#if defined(SOCK_RDM)
case SOCK_RDM:
cp = "RDM";
break;
#endif
#if defined(SOCK_SEQPACKET)
case SOCK_SEQPACKET:
cp = "SEQPACKET";
break;
#endif
default:
(void) snpf(buf, sizeof(buf), "SOCK_%#x", ty);
return(buf);
}
(void) snpf(buf, sizeof(buf), "SOCK_%s", cp);
return(buf);
}
char *
printuid(uid, ty)
UID_ARG uid;
int *ty;
{
int i;
struct passwd *pw;
struct stat sb;
static struct stat sbs;
static struct uidcache {
uid_t uid;
char nm[LOGINML+1];
struct uidcache *next;
} **uc = (struct uidcache **)NULL;
struct uidcache *up, *upn;
static char user[USERPRTL+1];
if (Futol) {
if (CkPasswd) {
if (stat("/etc/passwd", &sb) != 0) {
(void) fprintf(stderr, "%s: can't stat(/etc/passwd): %s\n",
Pn, strerror(errno));
Exit(1);
}
}
if (!uc) {
if (!(uc = (struct uidcache **)calloc(UIDCACHEL,
sizeof(struct uidcache *))))
{
(void) fprintf(stderr,
"%s: no space for %d byte UID cache hash buckets\n",
Pn, (int)(UIDCACHEL * (sizeof(struct uidcache *))));
Exit(1);
}
if (CkPasswd) {
sbs = sb;
CkPasswd = 0;
}
}
if (CkPasswd) {
if (sbs.st_mtime != sb.st_mtime || sbs.st_ctime != sb.st_ctime)
{
for (i = 0; i < UIDCACHEL; i++) {
if ((up = uc[i])) {
do {
upn = up->next;
(void) free((FREE_P *)up);
} while ((up = upn) != (struct uidcache *)NULL);
uc[i] = (struct uidcache *)NULL;
}
}
sbs = sb;
}
CkPasswd = 0;
}
i = (int)((((unsigned long)uid * 31415L) >> 7) & (UIDCACHEL - 1));
for (up = uc[i]; up; up = up->next) {
if (up->uid == (uid_t)uid) {
if (ty)
*ty = 0;
return(up->nm);
}
}
if (!(pw = getpwuid((uid_t)uid))) {
if (!Fwarn) {
(void) fprintf(stderr, "%s: no pwd entry for UID %lu\n",
Pn, (unsigned long)uid);
}
} else {
if (!(upn = (struct uidcache *)malloc(sizeof(struct uidcache))))
{
(void) fprintf(stderr,
"%s: no space for UID cache entry for: %lu, %s)\n",
Pn, (unsigned long)uid, pw->pw_name);
Exit(1);
}
(void) strncpy(upn->nm, pw->pw_name, LOGINML);
upn->nm[LOGINML] = '\0';
upn->uid = (uid_t)uid;
upn->next = uc[i];
uc[i] = upn;
if (ty)
*ty = 0;
return(upn->nm);
}
}
(void) snpf(user, sizeof(user), "%*lu", USERPRTL, (unsigned long)uid);
if (ty)
*ty = 1;
return(user);
}
void
printunkaf(fam, ty)
int fam;
int ty;
{
char *p, *s;
p = "";
switch (fam) {
#if defined(AF_UNSPEC)
case AF_UNSPEC:
s = "UNSPEC";
break;
#endif
#if defined(AF_UNIX)
case AF_UNIX:
s = "UNIX";
break;
#endif
#if defined(AF_INET)
case AF_INET:
s = "INET";
break;
#endif
#if defined(AF_INET6)
case AF_INET6:
s = "INET6";
break;
#endif
#if defined(AF_IMPLINK)
case AF_IMPLINK:
s = "IMPLINK";
break;
#endif
#if defined(AF_PUP)
case AF_PUP:
s = "PUP";
break;
#endif
#if defined(AF_CHAOS)
case AF_CHAOS:
s = "CHAOS";
break;
#endif
#if defined(AF_NS)
case AF_NS:
s = "NS";
break;
#endif
#if defined(AF_ISO)
case AF_ISO:
s = "ISO";
break;
#endif
#if defined(AF_NBS)
# if !defined(AF_ISO) || AF_NBS!=AF_ISO
case AF_NBS:
s = "NBS";
break;
# endif
#endif
#if defined(AF_ECMA)
case AF_ECMA:
s = "ECMA";
break;
#endif
#if defined(AF_DATAKIT)
case AF_DATAKIT:
s = "DATAKIT";
break;
#endif
#if defined(AF_CCITT)
case AF_CCITT:
s = "CCITT";
break;
#endif
#if defined(AF_SNA)
case AF_SNA:
s = "SNA";
break;
#endif
#if defined(AF_DECnet)
case AF_DECnet:
s = "DECnet";
break;
#endif
#if defined(AF_DLI)
case AF_DLI:
s = "DLI";
break;
#endif
#if defined(AF_LAT)
case AF_LAT:
s = "LAT";
break;
#endif
#if defined(AF_HYLINK)
case AF_HYLINK:
s = "HYLINK";
break;
#endif
#if defined(AF_APPLETALK)
case AF_APPLETALK:
s = "APPLETALK";
break;
#endif
#if defined(AF_BSC)
case AF_BSC:
s = "BSC";
break;
#endif
#if defined(AF_DSS)
case AF_DSS:
s = "DSS";
break;
#endif
#if defined(AF_ROUTE)
case AF_ROUTE:
s = "ROUTE";
break;
#endif
#if defined(AF_RAW)
case AF_RAW:
s = "RAW";
break;
#endif
#if defined(AF_LINK)
case AF_LINK:
s = "LINK";
break;
#endif
#if defined(pseudo_AF_XTP)
case pseudo_AF_XTP:
p = "pseudo_";
s = "XTP";
break;
#endif
#if defined(AF_RMP)
case AF_RMP:
s = "RMP";
break;
#endif
#if defined(AF_COIP)
case AF_COIP:
s = "COIP";
break;
#endif
#if defined(AF_CNT)
case AF_CNT:
s = "CNT";
break;
#endif
#if defined(pseudo_AF_RTIP)
case pseudo_AF_RTIP:
p = "pseudo_";
s = "RTIP";
break;
#endif
#if defined(AF_NETMAN)
case AF_NETMAN:
s = "NETMAN";
break;
#endif
#if defined(AF_INTF)
case AF_INTF:
s = "INTF";
break;
#endif
#if defined(AF_NETWARE)
case AF_NETWARE:
s = "NETWARE";
break;
#endif
#if defined(AF_NDD)
case AF_NDD:
s = "NDD";
break;
#endif
#if defined(AF_NIT)
# if !defined(AF_ROUTE) || AF_ROUTE!=AF_NIT
case AF_NIT:
s = "NIT";
break;
# endif
#endif
#if defined(AF_802)
# if !defined(AF_RAW) || AF_RAW!=AF_802
case AF_802:
s = "802";
break;
# endif
#endif
#if defined(AF_X25)
case AF_X25:
s = "X25";
break;
#endif
#if defined(AF_CTF)
case AF_CTF:
s = "CTF";
break;
#endif
#if defined(AF_WAN)
case AF_WAN:
s = "WAN";
break;
#endif
#if defined(AF_OSINET)
# if defined(AF_INET) && AF_INET!=AF_OSINET
case AF_OSINET:
s = "OSINET";
break;
# endif
#endif
#if defined(AF_GOSIP)
case AF_GOSIP:
s = "GOSIP";
break;
#endif
#if defined(AF_SDL)
case AF_SDL:
s = "SDL";
break;
#endif
#if defined(AF_IPX)
case AF_IPX:
s = "IPX";
break;
#endif
#if defined(AF_SIP)
case AF_SIP:
s = "SIP";
break;
#endif
#if defined(psuedo_AF_PIP)
case psuedo_AF_PIP:
p = "pseudo_";
s = "PIP";
break;
#endif
#if defined(AF_OTS)
case AF_OTS:
s = "OTS";
break;
#endif
#if defined(pseudo_AF_BLUE)
case pseudo_AF_BLUE:
p = "pseudo_";
s = "BLUE";
break;
#endif
#if defined(AF_NDRV)
case AF_NDRV:
s = "NDRV";
break;
#endif
#if defined(AF_SYSTEM)
case AF_SYSTEM:
s = "SYSTEM";
break;
#endif
#if defined(AF_USER)
case AF_USER:
s = "USER";
break;
#endif
#if defined(pseudo_AF_KEY)
case pseudo_AF_KEY:
p = "pseudo_";
s = "KEY";
break;
#endif
#if defined(AF_KEY)
case AF_KEY:
s = "KEY";
break;
#endif
#if defined(AF_NCA)
case AF_NCA:
s = "NCA";
break;
#endif
#if defined(AF_POLICY)
case AF_POLICY:
s = "POLICY";
break;
#endif
#if defined(AF_PPP)
case AF_PPP:
s = "PPP";
break;
#endif
default:
if (!ty)
(void) snpf(Namech, Namechl, "%#x", fam);
else
(void) snpf(Namech, Namechl,
"no further information on family %#x", fam);
return;
}
if (!ty)
(void) snpf(Namech, Namechl, "%sAF_%s", p, s);
else
(void) snpf(Namech, Namechl, "no further information on %sAF_%s",
p, s);
return;
}
static void
update_portmap(pt, pn)
struct porttab *pt;
char *pn;
{
MALLOC_S al, nl;
char *cp;
if (pt->ss)
return;
if (!(al = strlen(pn))) {
pt->ss = 1;
return;
}
nl = al + pt->nl + 2;
if (!(cp = (char *)malloc(nl + 1))) {
(void) fprintf(stderr,
"%s: can't allocate %d bytes for portmap name: %s[%s]\n",
Pn, (int)(nl + 1), pn, pt->name);
Exit(1);
}
(void) snpf(cp, nl + 1, "%s[%s]", pn, pt->name);
(void) free((FREE_P *)pt->name);
pt->name = cp;
pt->nl = nl;
pt->ss = 1;
}