2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 /* "@(#)unix.c 8.1 (Berkeley) 6/6/93" */
39 * Display protocol blocks in the unix domain.
42 #ifdef ENABLE_UNIX_DOMAIN
44 #include <sys/param.h>
45 #include <sys/protosw.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
49 #include <sys/sysctl.h>
51 #include <sys/unpcb.h>
57 #include <netinet/in.h>
63 static void unixdomainpr
__P((struct socket
*, caddr_t
));
65 static struct file
*file
, *fileNFILE
;
73 register struct file
*fp
;
74 struct socket sock
, *so
= &sock
;
76 struct protosw
*unixsw
= (struct protosw
*)off
;
78 filebuf
= (char *)kvm_getfiles(kvmd
, KERN_FILE
, 0, &nfiles
);
80 printf("Out of memory (file table).\n");
83 file
= (struct file
*)(filebuf
+ sizeof(fp
));
84 fileNFILE
= file
+ nfiles
;
85 for (fp
= file
; fp
< fileNFILE
; fp
++) {
86 if (fp
->f_count
== 0 || fp
->f_type
!= DTYPE_SOCKET
)
88 if (kread((u_long
)fp
->f_data
, (char *)so
, sizeof (*so
)))
91 if (so
->so_proto
>= unixsw
&& so
->so_proto
<= unixsw
+ 2)
93 unixdomainpr(so
, fp
->f_data
);
97 static char *socktype
[] =
98 { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
101 unixdomainpr(so
, soaddr
)
102 register struct socket
*so
;
105 struct unpcb unpcb
, *unp
= &unpcb
;
106 struct mbuf mbuf
, *m
;
107 struct sockaddr_un
*sa
;
108 static int first
= 1;
110 if (kread((u_long
)so
->so_pcb
, (char *)unp
, sizeof (*unp
)))
114 if (kread((u_long
)unp
->unp_addr
, (char *)m
, sizeof (*m
)))
115 m
= (struct mbuf
*)0;
116 sa
= (struct sockaddr_un
*)(m
->m_dat
);
118 m
= (struct mbuf
*)0;
120 printf("Active UNIX domain sockets\n");
122 "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
123 "Address", "Type", "Recv-Q", "Send-Q",
124 "Inode", "Conn", "Refs", "Nextref");
127 printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
128 soaddr
, socktype
[so
->so_type
], so
->so_rcv
.sb_cc
, so
->so_snd
.sb_cc
,
129 unp
->unp_vnode
, unp
->unp_conn
,
130 unp
->unp_refs
, unp
->unp_nextref
);
133 m
->m_len
- (int)(sizeof(*sa
) - sizeof(sa
->sun_path
)),