Ultrix-3.1/src/ucb/netstat/host.c
/**********************************************************************
* Copyright (c) Digital Equipment Corporation 1984, 1985, 1986. *
* All Rights Reserved. *
* Reference "/usr/src/COPYRIGHT" for applicable restrictions. *
**********************************************************************/
#ifndef lint
/*
* Based on static char sccsid[] = "@(#)host.c 4.2 82/11/14";
*/
static char *Sccsid = "@(#)host.c 3.0 (ULTRIX-11) 4/22/86";
#endif
#include <sys/types.h>
#include <sys/mbuf.h>
#include <netinet/in.h>
#include <netimp/if_imp.h>
#include <netimp/if_imphost.h>
#include <netdb.h>
extern int kmem;
extern int nflag;
extern char *inetname();
/*
* Print the host tables associated with the ARPANET IMP.
* Symbolic addresses are shown unless the nflag is given.
*/
hostpr(hostsaddr)
off_t hostsaddr;
{
struct mbuf *hosts, mb;
register struct mbuf *m;
register struct hmbuf *mh;
register struct host *hp;
struct hostent *p;
char flagbuf[10], *flags;
int first = 1;
if (hostsaddr == 0) {
printf("hosts: symbol not in namelist\n");
return;
}
klseek(kmem, hostsaddr, 0);
read(kmem, &hosts, sizeof (hosts));
m = hosts;
printf("IMP Host Table\n");
printf("%-5.5s %-15.15s %-4.4s %-9.9s %-4.4s %s\n",
"Flags", "Host", "Qcnt", "Q Address", "RFNM", "Timer");
while (m) {
klseek(kmem, m, 0);
read(kmem, &mb, sizeof (mb));
m = &mb;
mh = mtod(m, struct hmbuf *);
if (mh->hm_count == 0) {
m = m->m_next;
continue;
}
for (hp = mh->hm_hosts; hp < mh->hm_hosts + HPMBUF; hp++) {
if ((hp->h_flags&HF_INUSE) == 0 && hp->h_timer == 0)
continue;
flags = flagbuf;
*flags++ = hp->h_flags&HF_INUSE ? 'A' : 'F';
if (hp->h_flags&HF_DEAD)
*flags++ = 'D';
if (hp->h_flags&HF_UNREACH)
*flags++ = 'U';
*flags = '\0';
printf("%-5.5s %-15.15s %-4d %-9x %-4d %d\n",
flagbuf,
inetname(hp->h_addr),
hp->h_qcnt,
hp->h_q,
hp->h_rfnm,
hp->h_timer);
}
m = m->m_next;
}
}