1 /*
2 * UNIX An implementation of the AF_UNIX network domain for the
3 * LINUX operating system. UNIX is implemented using the
4 * BSD Socket interface as the means of communication with
5 * the user level.
6 *
7 * The functions in this file provide an interface between
8 * the PROC file system and the "unix" family of networking
9 * protocols. It is mainly used for debugging and statistics.
10 *
11 * Version: @(#)proc.c 1.0.4 05/23/93
12 *
13 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
14 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
15 * Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
16 * Fred Baumgarten, <dc6iq@insu1.etec.uni-kalrsruhe.de>
17 *
18 * Fixes:
19 * Dmitry Gorodchanin : /proc locking fix
20 *
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version
24 * 2 of the License, or (at your option) any later version.
25 */
26 #include <linux/autoconf.h>
27 #include <linux/sched.h>
28 #include <linux/string.h>
29 #include <linux/socket.h>
30 #include <linux/net.h>
31 #include <linux/ddi.h>
32 #include <linux/un.h>
33 #include <linux/param.h>
34 #include "unix.h"
35
36
37 /* Called from PROCfs. */
38 int unix_get_info(char *buffer)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
39 {
40 char *pos;
41 int i;
42
43 pos = buffer;
44 pos += sprintf(pos, "Num RefCount Protocol Flags Type St Path\n");
45
46 for(i = 0; i < NSOCKETS; i++) {
47 if (unix_datas[i].refcnt>0) {
48 pos += sprintf(pos, "%2d: %08X %08X %08lX %04X %02X", i,
49 unix_datas[i].refcnt,
50 unix_datas[i].protocol,
51 unix_datas[i].socket->flags,
52 unix_datas[i].socket->type,
53 unix_datas[i].socket->state
54 );
55
56 /* If socket is bound to a filename, we'll print it. */
57 if(unix_datas[i].sockaddr_len>0) {
58 pos += sprintf(pos, " %s\n",
59 unix_datas[i].sockaddr_un.sun_path);
60 } else { /* just add a newline */
61 *pos='\n';
62 pos++;
63 *pos='\0';
64 }
65
66 /*
67 * Check whether buffer _may_ overflow in the next loop.
68 * Since sockets may have very very long paths, we make
69 * PATH_MAX+80 the minimum space left for a new line.
70 */
71 if (pos > buffer+PAGE_SIZE-80-PATH_MAX) {
72 printk("UNIX: netinfo: oops, too many sockets.\n");
73 return(pos - buffer);
74 }
75 }
76 }
77 return(pos - buffer);
78 }