Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / common / C / netstat / unix.c
blob30a5032cbe624e44f6e86d9ae3e07c61ac2c63b2
1 /*-
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2006
5 * Pavel Fedin
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
33 * SUCH DAMAGE.
36 /* "@(#)unix.c 8.1 (Berkeley) 6/6/93" */
39 * Display protocol blocks in the unix domain.
42 #ifdef ENABLE_UNIX_DOMAIN
43 #include <kvm.h>
44 #include <sys/param.h>
45 #include <sys/protosw.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
48 #include <sys/mbuf.h>
49 #include <sys/sysctl.h>
50 #include <sys/un.h>
51 #include <sys/unpcb.h>
52 #define KERNEL
53 struct uio;
54 struct proc;
55 #include <sys/file.h>
57 #include <netinet/in.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include "netstat.h"
63 static void unixdomainpr __P((struct socket *, caddr_t));
65 static struct file *file, *fileNFILE;
66 static int nfiles;
67 extern kvm_t *kvmd;
69 void
70 unixpr(off)
71 u_long off;
73 register struct file *fp;
74 struct socket sock, *so = &sock;
75 char *filebuf;
76 struct protosw *unixsw = (struct protosw *)off;
78 filebuf = (char *)kvm_getfiles(kvmd, KERN_FILE, 0, &nfiles);
79 if (filebuf == 0) {
80 printf("Out of memory (file table).\n");
81 return;
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)
87 continue;
88 if (kread((u_long)fp->f_data, (char *)so, sizeof (*so)))
89 continue;
90 /* kludge */
91 if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
92 if (so->so_pcb)
93 unixdomainpr(so, fp->f_data);
97 static char *socktype[] =
98 { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
100 static void
101 unixdomainpr(so, soaddr)
102 register struct socket *so;
103 caddr_t soaddr;
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)))
111 return;
112 if (unp->unp_addr) {
113 m = &mbuf;
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);
117 } else
118 m = (struct mbuf *)0;
119 if (first) {
120 printf("Active UNIX domain sockets\n");
121 printf(
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");
125 first = 0;
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);
131 if (m)
132 printf(" %.*s",
133 m->m_len - (int)(sizeof(*sa) - sizeof(sa->sun_path)),
134 sa->sun_path);
135 putchar('\n');
137 #endif