2 * Copyright (c) 1996-1999 Whistle Communications, Inc.
5 * Subject to the following obligations and disclaimer of warranty, use and
6 * redistribution of this software, in source or object code forms, with or
7 * without modifications are expressly permitted by Whistle Communications;
8 * provided, however, that:
9 * 1. Any and all reproductions of the source or object code must include the
10 * copyright notice above and the following disclaimer of warranties; and
11 * 2. No rights are granted, in any manner or form, to use Whistle
12 * Communications, Inc. trademarks, including the mark "WHISTLE
13 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
14 * such appears in the above copyright notice or in the software.
16 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
17 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
18 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
19 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
21 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
22 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
23 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
24 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
25 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
26 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
42 #include <sys/socketvar.h>
43 #include <sys/protosw.h>
44 #include <sys/linker.h>
46 #include <net/route.h>
49 #include <netgraph/ng_message.h>
50 #include <netgraph/ng_socket.h>
51 #include <netgraph/ng_socketvar.h>
64 static int csock = -1;
67 netgraphprotopr(u_long off, const char *name, int af1 __unused,
70 struct ngpcb *this, *next;
75 /* If symbol not found, try looking in the KLD module */
78 xo_warnx("Error reading symbols from ng_socket.ko");
82 /* Get pointer to first socket */
83 kread(off, (char *)&this, sizeof(this));
85 /* Get my own socket node */
87 NgMkSockNode(NULL, &csock, NULL);
89 for (; this != NULL; this = next) {
90 u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)];
91 struct ng_mesg *resp = (struct ng_mesg *) rbuf;
92 struct nodeinfo *ni = (struct nodeinfo *) resp->data;
95 /* Read in ngpcb structure */
96 kread((u_long)this, (char *)&ngpcb, sizeof(ngpcb));
97 next = LIST_NEXT(&ngpcb, socks);
99 /* Read in socket structure */
100 kread((u_long)ngpcb.ng_socket, (char *)&sockb, sizeof(sockb));
102 /* Check type of socket */
103 if (strcmp(name, "ctrl") == 0 && ngpcb.type != NG_CONTROL)
105 if (strcmp(name, "data") == 0 && ngpcb.type != NG_DATA)
110 xo_emit("{T:Netgraph sockets}\n");
112 xo_emit("{T:/%-8.8s} ", "PCB");
113 xo_emit("{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} "
114 "{T:/%-14.14s} {T:/%s}\n",
115 "Type", "Recv-Q", "Send-Q", "Node Address",
122 xo_emit("{:address/%8lx} ", (u_long) this);
123 xo_emit("{t:name/%-5.5s} {:receive-bytes-waiting/%6u} "
124 "{:send-byte-waiting/%6u} ",
125 name, sockb.so_rcv.sb_ccc, sockb.so_snd.sb_ccc);
127 /* Get info on associated node */
128 if (ngpcb.node_id == 0 || csock == -1)
130 snprintf(path, sizeof(path), "[%x]:", ngpcb.node_id);
131 if (NgSendMsg(csock, path,
132 NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) < 0)
134 if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0)
137 /* Display associated node info */
138 if (*ni->name != '\0')
139 snprintf(path, sizeof(path), "%s:", ni->name);
140 xo_emit("{t:path/%-14.14s} {:hooks/%4d}", path, ni->hooks);