1*43249Skarels /*- 234902Sbostic * Copyright (c) 1983, 1988 Regents of the University of California. 333451Skarels * All rights reserved. 433451Skarels * 5*43249Skarels * %sccs.include.redist.c% 621991Sdist */ 721991Sdist 816560Ssam #ifndef lint 9*43249Skarels static char sccsid[] = "@(#)unix.c 5.8 (Berkeley) 06/18/90"; 1034902Sbostic #endif /* not lint */ 1116560Ssam 1216560Ssam /* 1316560Ssam * Display protocol blocks in the unix domain. 1416560Ssam */ 1516560Ssam #include <sys/param.h> 1616560Ssam #include <sys/protosw.h> 1716560Ssam #include <sys/socket.h> 1816560Ssam #include <sys/socketvar.h> 1916560Ssam #include <sys/mbuf.h> 2016560Ssam #include <sys/un.h> 2116560Ssam #include <sys/unpcb.h> 2216560Ssam #define KERNEL 2316560Ssam #include <sys/file.h> 2416560Ssam 2516560Ssam int Aflag; 2616560Ssam int kmem; 2729750Skupfer extern char *calloc(); 2816560Ssam 2916560Ssam unixpr(nfileaddr, fileaddr, unixsw) 3016560Ssam off_t nfileaddr, fileaddr; 3116560Ssam struct protosw *unixsw; 3216560Ssam { 3316560Ssam register struct file *fp; 3416560Ssam struct file *filep; 3516560Ssam struct socket sock, *so = &sock; 3616560Ssam 3716560Ssam if (nfileaddr == 0 || fileaddr == 0) { 3816560Ssam printf("nfile or file not in namelist.\n"); 3916560Ssam return; 4016560Ssam } 4116560Ssam klseek(kmem, nfileaddr, L_SET); 4229750Skupfer if (read(kmem, (char *)&nfile, sizeof (nfile)) != sizeof (nfile)) { 4316560Ssam printf("nfile: bad read.\n"); 4416560Ssam return; 4516560Ssam } 4616560Ssam klseek(kmem, fileaddr, L_SET); 4729750Skupfer if (read(kmem, (char *)&filep, sizeof (filep)) != sizeof (filep)) { 4816560Ssam printf("File table address, bad read.\n"); 4916560Ssam return; 5016560Ssam } 5116560Ssam file = (struct file *)calloc(nfile, sizeof (struct file)); 5216560Ssam if (file == (struct file *)0) { 5316560Ssam printf("Out of memory (file table).\n"); 5416560Ssam return; 5516560Ssam } 5616560Ssam klseek(kmem, (off_t)filep, L_SET); 5729750Skupfer if (read(kmem, (char *)file, nfile * sizeof (struct file)) != 5816560Ssam nfile * sizeof (struct file)) { 5916560Ssam printf("File table read error.\n"); 6016560Ssam return; 6116560Ssam } 6216560Ssam fileNFILE = file + nfile; 6316560Ssam for (fp = file; fp < fileNFILE; fp++) { 6416560Ssam if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) 6516560Ssam continue; 6629750Skupfer klseek(kmem, (off_t)fp->f_data, L_SET); 6729750Skupfer if (read(kmem, (char *)so, sizeof (*so)) != sizeof (*so)) 6816560Ssam continue; 6916560Ssam /* kludge */ 7016560Ssam if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) 7116560Ssam if (so->so_pcb) 7216560Ssam unixdomainpr(so, fp->f_data); 7316560Ssam } 7416560Ssam free((char *)file); 7516560Ssam } 7616560Ssam 7716560Ssam static char *socktype[] = 7816560Ssam { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; 7916560Ssam 8016560Ssam unixdomainpr(so, soaddr) 8116560Ssam register struct socket *so; 8216560Ssam caddr_t soaddr; 8316560Ssam { 8416560Ssam struct unpcb unpcb, *unp = &unpcb; 8516560Ssam struct mbuf mbuf, *m; 8627887Skarels struct sockaddr_un *sa; 8716560Ssam static int first = 1; 8816560Ssam 8929750Skupfer klseek(kmem, (off_t)so->so_pcb, L_SET); 9029750Skupfer if (read(kmem, (char *)unp, sizeof (*unp)) != sizeof (*unp)) 9116560Ssam return; 9226022Smckusick if (unp->unp_addr) { 9316560Ssam m = &mbuf; 9429750Skupfer klseek(kmem, (off_t)unp->unp_addr, L_SET); 9529750Skupfer if (read(kmem, (char *)m, sizeof (*m)) != sizeof (*m)) 9616560Ssam m = (struct mbuf *)0; 9739215Skarels sa = (struct sockaddr_un *)(m->m_dat); 9816560Ssam } else 9916560Ssam m = (struct mbuf *)0; 10016560Ssam if (first) { 10127887Skarels printf("Active UNIX domain sockets\n"); 10216560Ssam printf( 10327887Skarels "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n", 10416560Ssam "Address", "Type", "Recv-Q", "Send-Q", 10516560Ssam "Inode", "Conn", "Refs", "Nextref"); 10616560Ssam first = 0; 10716560Ssam } 10816560Ssam printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x", 10916560Ssam soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, 110*43249Skarels unp->unp_vnode, unp->unp_conn, 11116560Ssam unp->unp_refs, unp->unp_nextref); 11216560Ssam if (m) 11327887Skarels printf(" %.*s", m->m_len - sizeof(sa->sun_family), 11427887Skarels sa->sun_path); 11516560Ssam putchar('\n'); 11616560Ssam } 117