1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * UNIX		An implementation of the AF_UNIX network domain for the
 *		LINUX operating system.  UNIX is implemented using the
 *		BSD Socket interface as the means of communication with
 *		the user level.
 *
 *		The functions in this file provide an interface between
 *		the PROC file system and the "unix" family of networking
 *		protocols. It is mainly used for debugging and statistics.
 *
 * Version:	@(#)proc.c	1.0.4	05/23/93
 *
 * Authors:	Ross Biro, <bir7@leland.Stanford.Edu>
 *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
 *		Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
 *		Fred Baumgarten, <dc6iq@insu1.etec.uni-kalrsruhe.de>
 *
 * Fixes:
 *		Dmitry Gorodchanin	:	/proc locking fix
 *
 *		This program is free software; you can redistribute it and/or
 *		modify it under the terms of the GNU General Public License
 *		as published by the Free Software Foundation; either version
 *		2 of the License, or (at your option) any later version.
 */
#include <linux/autoconf.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/net.h>
#include <linux/ddi.h>
#include <linux/un.h>
#include <linux/param.h>
#include "unix.h"


/* Called from PROCfs. */
int unix_get_info(char *buffer)
{
  char *pos;
  int i;

  pos = buffer;
  pos += sprintf(pos, "Num RefCount Protocol Flags    Type St Path\n");

  for(i = 0; i < NSOCKETS; i++) {
	if (unix_datas[i].refcnt>0) {
		pos += sprintf(pos, "%2d: %08X %08X %08lX %04X %02X", i,
			unix_datas[i].refcnt,
			unix_datas[i].protocol,
			unix_datas[i].socket->flags,
			unix_datas[i].socket->type,
			unix_datas[i].socket->state
		);

		/* If socket is bound to a filename, we'll print it. */
		if(unix_datas[i].sockaddr_len>0) {
			pos += sprintf(pos, " %s\n",
				unix_datas[i].sockaddr_un.sun_path);
		} else { /* just add a newline */
			*pos='\n';
			pos++;
			*pos='\0';
		}

		/*
		 * Check whether buffer _may_ overflow in the next loop.
		 * Since sockets may have very very long paths, we make
		 * PATH_MAX+80 the minimum space left for a new line.
		 */
		if (pos > buffer+PAGE_SIZE-80-PATH_MAX) {
			printk("UNIX: netinfo: oops, too many sockets.\n");
			return(pos - buffer);
		}
	}
  }
  return(pos - buffer);
}
鱼站在海里脚会痛吗