121991Sdist /* 221991Sdist * Copyright (c) 1983 Regents of the University of California. 321991Sdist * All rights reserved. The Berkeley software License Agreement 421991Sdist * specifies the terms and conditions for redistribution. 521991Sdist */ 621991Sdist 716560Ssam #ifndef lint 8*27887Skarels static char sccsid[] = "@(#)unix.c 5.3 (Berkeley) 05/08/86"; 921991Sdist #endif not lint 1016560Ssam 1116560Ssam /* 1216560Ssam * Display protocol blocks in the unix domain. 1316560Ssam */ 1416560Ssam #include <sys/param.h> 1516560Ssam #include <sys/protosw.h> 1616560Ssam #include <sys/socket.h> 1716560Ssam #include <sys/socketvar.h> 1816560Ssam #include <sys/mbuf.h> 1916560Ssam #include <sys/un.h> 2016560Ssam #include <sys/unpcb.h> 2116560Ssam #define KERNEL 2216560Ssam #include <sys/file.h> 2316560Ssam 2416560Ssam int Aflag; 2516560Ssam int kmem; 2616560Ssam 2716560Ssam unixpr(nfileaddr, fileaddr, unixsw) 2816560Ssam off_t nfileaddr, fileaddr; 2916560Ssam struct protosw *unixsw; 3016560Ssam { 3116560Ssam register struct file *fp; 3216560Ssam struct file *filep; 3316560Ssam struct socket sock, *so = &sock; 3416560Ssam 3516560Ssam if (nfileaddr == 0 || fileaddr == 0) { 3616560Ssam printf("nfile or file not in namelist.\n"); 3716560Ssam return; 3816560Ssam } 3916560Ssam klseek(kmem, nfileaddr, L_SET); 4016560Ssam if (read(kmem, &nfile, sizeof (nfile)) != sizeof (nfile)) { 4116560Ssam printf("nfile: bad read.\n"); 4216560Ssam return; 4316560Ssam } 4416560Ssam klseek(kmem, fileaddr, L_SET); 4516560Ssam if (read(kmem, &filep, sizeof (filep)) != sizeof (filep)) { 4616560Ssam printf("File table address, bad read.\n"); 4716560Ssam return; 4816560Ssam } 4916560Ssam file = (struct file *)calloc(nfile, sizeof (struct file)); 5016560Ssam if (file == (struct file *)0) { 5116560Ssam printf("Out of memory (file table).\n"); 5216560Ssam return; 5316560Ssam } 5416560Ssam klseek(kmem, (off_t)filep, L_SET); 5516560Ssam if (read(kmem, file, nfile * sizeof (struct file)) != 5616560Ssam nfile * sizeof (struct file)) { 5716560Ssam printf("File table read error.\n"); 5816560Ssam return; 5916560Ssam } 6016560Ssam fileNFILE = file + nfile; 6116560Ssam for (fp = file; fp < fileNFILE; fp++) { 6216560Ssam if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) 6316560Ssam continue; 6416560Ssam klseek(kmem, fp->f_data, L_SET); 6516560Ssam if (read(kmem, so, sizeof (*so)) != sizeof (*so)) 6616560Ssam continue; 6716560Ssam /* kludge */ 6816560Ssam if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) 6916560Ssam if (so->so_pcb) 7016560Ssam unixdomainpr(so, fp->f_data); 7116560Ssam } 7216560Ssam free((char *)file); 7316560Ssam } 7416560Ssam 7516560Ssam static char *socktype[] = 7616560Ssam { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; 7716560Ssam 7816560Ssam unixdomainpr(so, soaddr) 7916560Ssam register struct socket *so; 8016560Ssam caddr_t soaddr; 8116560Ssam { 8216560Ssam struct unpcb unpcb, *unp = &unpcb; 8316560Ssam struct mbuf mbuf, *m; 84*27887Skarels struct sockaddr_un *sa; 8516560Ssam static int first = 1; 8616560Ssam 8716560Ssam klseek(kmem, so->so_pcb, L_SET); 8816560Ssam if (read(kmem, unp, sizeof (*unp)) != sizeof (*unp)) 8916560Ssam return; 9026022Smckusick if (unp->unp_addr) { 9116560Ssam m = &mbuf; 9226022Smckusick klseek(kmem, unp->unp_addr, L_SET); 9316560Ssam if (read(kmem, m, sizeof (*m)) != sizeof (*m)) 9416560Ssam m = (struct mbuf *)0; 95*27887Skarels sa = mtod(m, struct sockaddr_un *); 9616560Ssam } else 9716560Ssam m = (struct mbuf *)0; 9816560Ssam if (first) { 99*27887Skarels printf("Active UNIX domain sockets\n"); 10016560Ssam printf( 101*27887Skarels "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n", 10216560Ssam "Address", "Type", "Recv-Q", "Send-Q", 10316560Ssam "Inode", "Conn", "Refs", "Nextref"); 10416560Ssam first = 0; 10516560Ssam } 10616560Ssam printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x", 10716560Ssam soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, 10816560Ssam unp->unp_inode, unp->unp_conn, 10916560Ssam unp->unp_refs, unp->unp_nextref); 11016560Ssam if (m) 111*27887Skarels printf(" %.*s", m->m_len - sizeof(sa->sun_family), 112*27887Skarels sa->sun_path); 11316560Ssam putchar('\n'); 11416560Ssam } 115