Make loses argument information.
[unix-history] / usr.bin / netstat / unix.c
CommitLineData
15637ed4
RG
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, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
49f80972
GW
35/* from: static char sccsid[] = "@(#)unix.c 5.11 (Berkeley) 7/1/91"; */
36static const char unix_c_rcsid[] =
db78aa36 37 "$Id: unix.c,v 1.4 1994/01/23 15:06:14 davidg Exp $";
15637ed4
RG
38#endif /* not lint */
39
40/*
41 * Display protocol blocks in the unix domain.
42 */
43#include <sys/param.h>
44#include <sys/protosw.h>
45#include <sys/socket.h>
46#include <sys/socketvar.h>
47#include <sys/mbuf.h>
48#include <sys/un.h>
49#include <sys/unpcb.h>
04a411fa
RG
50#include <sys/time.h>
51#include <sys/proc.h>
15637ed4
RG
52#define KERNEL
53struct uio;
54#include <sys/file.h>
55struct file *file, *fileNFILE;
56int nfiles;
57
58int Aflag;
59extern char *calloc();
60
61unixpr(fileheadaddr, nfilesaddr, unixsw)
62 off_t fileheadaddr, nfilesaddr;
63 struct protosw *unixsw;
64{
65 register struct file *fp, *lfp;
66 struct file *filep;
67 struct socket sock, *so = &sock;
68 int i;
69
70 if (fileheadaddr == 0 || nfilesaddr == 0) {
71 printf("filehead or nfiles not in namelist.\n");
72 return;
73 }
74 if (kvm_read(nfilesaddr, (char *)&nfiles, sizeof (nfiles)) !=
75 sizeof (nfiles)) {
76 printf("nfiles: bad read.\n");
77 return;
78 }
79 if (kvm_read(fileheadaddr, (char *)&filep, sizeof (filep))
80 != sizeof (filep)) {
81 printf("File table address, bad read.\n");
82 return;
83 }
84 file = (struct file *)calloc(nfiles, sizeof (struct file));
85 if (file == (struct file *)0) {
86 printf("Out of memory (file table).\n");
87 return;
88 }
89 for (lfp = file, i = nfiles;
90 filep != NULL && i-- > 0;
91 filep = lfp->f_filef, lfp++)
92 {
93 if(kvm_read((off_t)filep, (char *)lfp, sizeof (struct file))
94 != sizeof(struct file)) {
95 printf("File table read error.\n");
96 return;
97 }
98 }
99 fileNFILE = file + nfiles;
100 for (fp = file; fp < fileNFILE; fp++) {
101 if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
102 continue;
103 if (kvm_read((off_t)fp->f_data, (char *)so, sizeof (*so))
104 != sizeof (*so))
105 continue;
106 /* kludge */
107 if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
108 if (so->so_pcb)
109 unixdomainpr(so, fp->f_data);
110 }
111 free((char *)file);
112}
113
114static char *socktype[] =
115 { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
116
117unixdomainpr(so, soaddr)
118 register struct socket *so;
119 caddr_t soaddr;
120{
121 struct unpcb unpcb, *unp = &unpcb;
122 struct mbuf mbuf, *m;
123 struct sockaddr_un *sa;
124 static int first = 1;
125
126 if (kvm_read((off_t)so->so_pcb, (char *)unp, sizeof (*unp))
127 != sizeof (*unp))
128 return;
129 if (unp->unp_addr) {
130 m = &mbuf;
131 if (kvm_read((off_t)unp->unp_addr, (char *)m, sizeof (*m))
132 != sizeof (*m))
133 m = (struct mbuf *)0;
134 sa = (struct sockaddr_un *)(m->m_dat);
135 } else
136 m = (struct mbuf *)0;
137 if (first) {
db78aa36 138 printf("Active local domain sockets\n");
15637ed4
RG
139 printf(
140"%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
141 "Address", "Type", "Recv-Q", "Send-Q",
142 "Inode", "Conn", "Refs", "Nextref");
143 first = 0;
144 }
145 printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
146 soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc,
147 unp->unp_vnode, unp->unp_conn,
148 unp->unp_refs, unp->unp_nextref);
149 if (m)
ea1a16f5 150 printf(" %.*s", m->m_len - sizeof(sa->sun_family) - 1,
15637ed4
RG
151 sa->sun_path);
152 putchar('\n');
153}