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

Defined functions

unixdomainpr defined in line 78; used 1 times
  • in line 70
unixpr defined in line 27; used 1 times

Defined variables

Aflag defined in line 24; used 8 times
kmem defined in line 25; used 78 times
sccsid defined in line 8; never used
socktype defined in line 75; used 1 times

Defined macros

KERNEL defined in line 21; never used
Last modified: 1986-05-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1167
Valid CSS Valid XHTML 1.0 Strict