1: /*
   2:  * Copyright (c) 1983,1988 Regents of the University of California.
   3:  * All rights reserved.
   4:  *
   5:  * Redistribution and use in source and binary forms are permitted
   6:  * provided that this notice is preserved and that due credit is given
   7:  * to the University of California at Berkeley. The name of the University
   8:  * may not be used to endorse or promote products derived from this
   9:  * software without specific prior written permission. This software
  10:  * is provided ``as is'' without express or implied warranty.
  11:  */
  12: 
  13: #if defined(DOSCCS) && !defined(lint)
  14: static char sccsid[] = "@(#)unix.c	5.5.1 (2.11BSD GTE) 1/1/94";
  15: #endif
  16: 
  17: /*
  18:  * Display protocol blocks in the unix domain.
  19:  */
  20: #include <sys/param.h>
  21: #include <sys/protosw.h>
  22: #include <sys/socket.h>
  23: #include <sys/socketvar.h>
  24: #include <sys/mbuf.h>
  25: #include <sys/un.h>
  26: #include <sys/unpcb.h>
  27: #define KERNEL
  28: #include <sys/file.h>
  29: 
  30: int Aflag;
  31: int kmem;
  32: extern  char *calloc();
  33: 
  34: unixpr(nfileaddr, fileaddr, unixsw)
  35:     off_t nfileaddr, fileaddr;
  36:     struct protosw *unixsw;
  37: {
  38:     register struct file *fp;
  39:     struct file *filep, *fil, *fileNFILE;
  40:     struct socket sock, *so = &sock;
  41: 
  42:     if (nfileaddr == 0 || fileaddr == 0) {
  43:         printf("nfile or file not in namelist.\n");
  44:         return;
  45:     }
  46:     klseek(kmem, nfileaddr, L_SET);
  47:     if (read(kmem, (char *)&nfile, sizeof (nfile)) != sizeof (nfile)) {
  48:         printf("nfile: bad read.\n");
  49:         return;
  50:     }
  51:     klseek(kmem, fileaddr, L_SET);
  52: #ifndef pdp11
  53:     if (read(kmem, (char *)&filep, sizeof (filep)) != sizeof (filep)) {
  54:         printf("File table address, bad read.\n");
  55:         return;
  56:     }
  57: #endif
  58:     fil = (struct file *)calloc(nfile, sizeof (struct file));
  59:     if (fil == (struct file *)0) {
  60:         printf("Out of memory (file table).\n");
  61:         return;
  62:     }
  63: #ifndef pdp11
  64:     klseek(kmem, (off_t)filep, L_SET);
  65: #endif
  66:     if (read(kmem, (char *)fil, nfile * sizeof (struct file)) !=
  67:         nfile * sizeof (struct file)) {
  68:         printf("File table read error.\n");
  69:         return;
  70:     }
  71:     fileNFILE = fil + nfile;
  72:     for (fp = fil; fp < fileNFILE; fp++) {
  73:         if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
  74:             continue;
  75: #ifdef pdp11
  76:         slseek(kmem, (off_t)fp->f_data, L_SET);
  77: #else
  78:         klseek(kmem, (off_t)fp->f_data, L_SET);
  79: #endif
  80:         if (read(kmem, (char *)so, sizeof (*so)) != sizeof (*so))
  81:             continue;
  82:         /* kludge */
  83:         if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
  84:             if (so->so_pcb)
  85:                 unixdomainpr(so, fp->f_data);
  86:     }
  87:     free((char *)fil);
  88: }
  89: 
  90: static  char *socktype[] =
  91:     { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
  92: 
  93: unixdomainpr(so, soaddr)
  94:     register struct socket *so;
  95:     caddr_t soaddr;
  96: {
  97:     struct unpcb unpcb, *unp = &unpcb;
  98:     struct mbuf mbuf, *m;
  99:     struct sockaddr_un *sa;
 100:     static int first = 1;
 101: #ifdef pdp11
 102: #define klseek slseek
 103: #endif
 104: 
 105:     klseek(kmem, (off_t)so->so_pcb, L_SET);
 106:     if (read(kmem, (char *)unp, sizeof (*unp)) != sizeof (*unp))
 107:         return;
 108:     if (unp->unp_addr) {
 109:         m = &mbuf;
 110:         klseek(kmem, (off_t)unp->unp_addr, L_SET);
 111:         if (read(kmem, (char *)m, sizeof (*m)) != sizeof (*m))
 112:             m = (struct mbuf *)0;
 113:         sa = mtod(m, struct sockaddr_un *);
 114:     } else
 115:         m = (struct mbuf *)0;
 116:     if (first) {
 117:         printf("Active UNIX domain sockets\n");
 118:         printf(
 119: "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
 120:             "Address", "Type", "Recv-Q", "Send-Q",
 121:             "Inode", "Conn", "Refs", "Nextref");
 122:         first = 0;
 123:     }
 124:     printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
 125:         soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc,
 126:         unp->unp_inode, unp->unp_conn,
 127:         unp->unp_refs, unp->unp_nextref);
 128:     if (m)
 129:         printf(" %.*s", m->m_len - sizeof(sa->sun_family),
 130:             sa->sun_path);
 131:     putchar('\n');
 132: }

Defined functions

unixdomainpr defined in line 93; used 1 times
  • in line 85
unixpr defined in line 34; never used

Defined variables

Aflag defined in line 30; used 8 times
kmem defined in line 31; used 77 times
sccsid defined in line 14; never used
socktype defined in line 90; used 1 times

Defined macros

KERNEL defined in line 27; never used
klseek defined in line 102; used 6 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3637
Valid CSS Valid XHTML 1.0 Strict