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 * Mathijs Maassen : unbound /proc fix. 21 * Alan Cox : Fix sock=NULL race 22 * 23 * This program is free software; you can redistribute it and/or 24 * modify it under the terms of the GNU General Public License 25 * as published by the Free Software Foundation; either version 26 * 2 of the License, or (at your option) any later version. 27 */ 28 #include <linux/autoconf.h>
29 #include <linux/sched.h>
30 #include <linux/string.h>
31 #include <linux/socket.h>
32 #include <linux/net.h>
33 #include <linux/un.h>
34 #include <linux/param.h>
35 #include "unix.h"
36
37
38 /* Called from PROCfs. */ 39 intunix_get_info(char *buffer, char **start, off_toffset, intlength)
/* */ 40 { 41 off_tpos=0;
42 off_tbegin=0;
43 intlen=0;
44 inti;
45 unsignedlongflags;
46 socket_states_state;
47 shorts_type;
48 longs_flags;
49
50 len += sprintf(buffer, "Num RefCount Protocol Flags Type St Path\n");
51
52 for(i = 0; i < NSOCKETS; i++)
53 { 54 save_flags(flags);
55 cli();
56 if (unix_datas[i].refcnt>0 && unix_datas[i].socket!=NULL)
57 { 58 /* sprintf is slow... lock only for the variable reads */ 59 s_type=unix_datas[i].socket->type;
60 s_flags=unix_datas[i].socket->flags;
61 s_state=unix_datas[i].socket->state;
62 restore_flags(flags);
63 len += sprintf(buffer+len, "%2d: %08X %08X %08lX %04X %02X", i,
64 unix_datas[i].refcnt,
65 unix_datas[i].protocol,
66 s_flags,
67 s_type,
68 s_state 69 );
70
71 /* If socket is bound to a filename, we'll print it. */ 72 if(unix_datas[i].sockaddr_len>0)
73 { 74 len += sprintf(buffer+len, " %s\n",
75 unix_datas[i].sockaddr_un.sun_path);
76 } 77 else 78 {/* just add a newline */ 79 buffer[len++]='\n';
80 } 81
82 pos=begin+len;
83 if(pos<offset)
84 { 85 len=0;
86 begin=pos;
87 } 88 if(pos>offset+length)
89 break;
90 } 91 else 92 restore_flags(flags);
93 } 94
95 *start=buffer+(offset-begin);
96 len-=(offset-begin);
97 if(len>length)
98 len=length;
99 returnlen;
100 }