1*16560Ssam #ifndef lint 2*16560Ssam static char sccsid[] = "@(#)unix.c 1.1 (Berkeley) 06/03/84"; 3*16560Ssam #endif 4*16560Ssam 5*16560Ssam /* 6*16560Ssam * Display protocol blocks in the unix domain. 7*16560Ssam */ 8*16560Ssam #include <sys/param.h> 9*16560Ssam #include <sys/protosw.h> 10*16560Ssam #include <sys/socket.h> 11*16560Ssam #include <sys/socketvar.h> 12*16560Ssam #include <sys/mbuf.h> 13*16560Ssam #include <sys/un.h> 14*16560Ssam #include <sys/unpcb.h> 15*16560Ssam #define KERNEL 16*16560Ssam #include <sys/file.h> 17*16560Ssam 18*16560Ssam int Aflag; 19*16560Ssam int kmem; 20*16560Ssam 21*16560Ssam unixpr(nfileaddr, fileaddr, unixsw) 22*16560Ssam off_t nfileaddr, fileaddr; 23*16560Ssam struct protosw *unixsw; 24*16560Ssam { 25*16560Ssam register struct file *fp; 26*16560Ssam struct file *filep; 27*16560Ssam struct socket sock, *so = &sock; 28*16560Ssam 29*16560Ssam if (nfileaddr == 0 || fileaddr == 0) { 30*16560Ssam printf("nfile or file not in namelist.\n"); 31*16560Ssam return; 32*16560Ssam } 33*16560Ssam klseek(kmem, nfileaddr, L_SET); 34*16560Ssam if (read(kmem, &nfile, sizeof (nfile)) != sizeof (nfile)) { 35*16560Ssam printf("nfile: bad read.\n"); 36*16560Ssam return; 37*16560Ssam } 38*16560Ssam klseek(kmem, fileaddr, L_SET); 39*16560Ssam if (read(kmem, &filep, sizeof (filep)) != sizeof (filep)) { 40*16560Ssam printf("File table address, bad read.\n"); 41*16560Ssam return; 42*16560Ssam } 43*16560Ssam file = (struct file *)calloc(nfile, sizeof (struct file)); 44*16560Ssam if (file == (struct file *)0) { 45*16560Ssam printf("Out of memory (file table).\n"); 46*16560Ssam return; 47*16560Ssam } 48*16560Ssam klseek(kmem, (off_t)filep, L_SET); 49*16560Ssam if (read(kmem, file, nfile * sizeof (struct file)) != 50*16560Ssam nfile * sizeof (struct file)) { 51*16560Ssam printf("File table read error.\n"); 52*16560Ssam return; 53*16560Ssam } 54*16560Ssam fileNFILE = file + nfile; 55*16560Ssam for (fp = file; fp < fileNFILE; fp++) { 56*16560Ssam if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) 57*16560Ssam continue; 58*16560Ssam klseek(kmem, fp->f_data, L_SET); 59*16560Ssam if (read(kmem, so, sizeof (*so)) != sizeof (*so)) 60*16560Ssam continue; 61*16560Ssam /* kludge */ 62*16560Ssam if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) 63*16560Ssam if (so->so_pcb) 64*16560Ssam unixdomainpr(so, fp->f_data); 65*16560Ssam } 66*16560Ssam free((char *)file); 67*16560Ssam } 68*16560Ssam 69*16560Ssam static char *socktype[] = 70*16560Ssam { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; 71*16560Ssam 72*16560Ssam unixdomainpr(so, soaddr) 73*16560Ssam register struct socket *so; 74*16560Ssam caddr_t soaddr; 75*16560Ssam { 76*16560Ssam struct unpcb unpcb, *unp = &unpcb; 77*16560Ssam struct mbuf mbuf, *m; 78*16560Ssam static int first = 1; 79*16560Ssam 80*16560Ssam klseek(kmem, so->so_pcb, L_SET); 81*16560Ssam if (read(kmem, unp, sizeof (*unp)) != sizeof (*unp)) 82*16560Ssam return; 83*16560Ssam if (unp->unp_remaddr) { 84*16560Ssam m = &mbuf; 85*16560Ssam klseek(kmem, unp->unp_remaddr, L_SET); 86*16560Ssam if (read(kmem, m, sizeof (*m)) != sizeof (*m)) 87*16560Ssam m = (struct mbuf *)0; 88*16560Ssam } else 89*16560Ssam m = (struct mbuf *)0; 90*16560Ssam if (first) { 91*16560Ssam printf( 92*16560Ssam "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Remaddr\n", 93*16560Ssam "Address", "Type", "Recv-Q", "Send-Q", 94*16560Ssam "Inode", "Conn", "Refs", "Nextref"); 95*16560Ssam first = 0; 96*16560Ssam } 97*16560Ssam printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x", 98*16560Ssam soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, 99*16560Ssam unp->unp_inode, unp->unp_conn, 100*16560Ssam unp->unp_refs, unp->unp_nextref); 101*16560Ssam if (m) 102*16560Ssam printf(" %.*s", m->m_len, mtod(m, char *)); 103*16560Ssam putchar('\n'); 104*16560Ssam } 105