Multicast changes from lbl
[unix-history] / usr / src / usr.bin / netstat / unix.c
CommitLineData
64addc1e 1/*-
b36fc510 2 * Copyright (c) 1983, 1988 Regents of the University of California.
ee3f90a5
MK
3 * All rights reserved.
4 *
64addc1e 5 * %sccs.include.redist.c%
5ff67f98
DF
6 */
7
0b1fe039 8#ifndef lint
27788811 9static char sccsid[] = "@(#)unix.c 5.13 (Berkeley) %G%";
b36fc510 10#endif /* not lint */
0b1fe039
SL
11
12/*
13 * Display protocol blocks in the unix domain.
14 */
6e549c8f 15#include <kvm.h>
0b1fe039
SL
16#include <sys/param.h>
17#include <sys/protosw.h>
18#include <sys/socket.h>
19#include <sys/socketvar.h>
20#include <sys/mbuf.h>
6e549c8f 21#include <sys/kinfo.h>
0b1fe039
SL
22#include <sys/un.h>
23#include <sys/unpcb.h>
26596563
KB
24#define KERNEL
25struct uio;
6e549c8f 26struct proc;
0b1fe039 27#include <sys/file.h>
27788811
KS
28
29#include <netinet/in.h>
30
31#include <stdio.h>
6e549c8f
KS
32#include <stdlib.h>
33#include "netstat.h"
34
27788811 35static void unixdomainpr __P((struct socket *, caddr_t));
0b1fe039 36
27788811
KS
37struct file *file, *fileNFILE;
38int nfiles;
6e549c8f 39extern kvm_t *kvmd;
0b1fe039 40
6e549c8f
KS
41void
42unixpr(unixsw)
0b1fe039
SL
43 struct protosw *unixsw;
44{
45 register struct file *fp;
0b1fe039 46 struct socket sock, *so = &sock;
6e549c8f 47 char *filebuf;
0b1fe039 48
6e549c8f
KS
49 filebuf = (char *)kvm_getfiles(kvmd, KINFO_FILE, 0, &nfiles);
50 if (filebuf == 0) {
0b1fe039
SL
51 printf("Out of memory (file table).\n");
52 return;
53 }
6e549c8f
KS
54 file = (struct file *)(filebuf + sizeof(fp));
55 fileNFILE = file + nfiles;
0b1fe039
SL
56 for (fp = file; fp < fileNFILE; fp++) {
57 if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
58 continue;
6e549c8f 59 if (kread((off_t)fp->f_data, (char *)so, sizeof (*so)))
0b1fe039
SL
60 continue;
61 /* kludge */
62 if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
63 if (so->so_pcb)
64 unixdomainpr(so, fp->f_data);
65 }
0b1fe039
SL
66}
67
68static char *socktype[] =
69 { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
70
6e549c8f 71static void
0b1fe039
SL
72unixdomainpr(so, soaddr)
73 register struct socket *so;
74 caddr_t soaddr;
75{
76 struct unpcb unpcb, *unp = &unpcb;
77 struct mbuf mbuf, *m;
2a893f10 78 struct sockaddr_un *sa;
0b1fe039
SL
79 static int first = 1;
80
6e549c8f 81 if (kread((off_t)so->so_pcb, (char *)unp, sizeof (*unp)))
0b1fe039 82 return;
57140966 83 if (unp->unp_addr) {
0b1fe039 84 m = &mbuf;
6e549c8f 85 if (kread((off_t)unp->unp_addr, (char *)m, sizeof (*m)))
0b1fe039 86 m = (struct mbuf *)0;
39173c8c 87 sa = (struct sockaddr_un *)(m->m_dat);
0b1fe039
SL
88 } else
89 m = (struct mbuf *)0;
90 if (first) {
2a893f10 91 printf("Active UNIX domain sockets\n");
0b1fe039 92 printf(
2a893f10 93"%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
0b1fe039
SL
94 "Address", "Type", "Recv-Q", "Send-Q",
95 "Inode", "Conn", "Refs", "Nextref");
96 first = 0;
97 }
98 printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
99 soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc,
64addc1e 100 unp->unp_vnode, unp->unp_conn,
0b1fe039
SL
101 unp->unp_refs, unp->unp_nextref);
102 if (m)
27788811 103 printf(" %.*s", m->m_len - (int)sizeof(sa->sun_family),
2a893f10 104 sa->sun_path);
0b1fe039
SL
105 putchar('\n');
106}