2 * This file is part of the UCB release of Plan 9. It is subject to the license
3 * terms in the LICENSE file found in the top-level directory of this
4 * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
5 * part of the UCB release of Plan 9, including this file, may be copied,
6 * modified, propagated, or distributed except according to the terms contained
15 #include <parlib/parlib.h>
18 #include <iplib/iplib.h>
24 void pip(char *, struct dirent *);
25 void nstat(char *, void (*)(char *, struct dirent *));
30 char *proto[maxproto];
34 void usage(char *argv0)
36 fprintf(stderr, "usage: %s [-in] [-p proto] [network-dir]\n", argv0);
37 fprintf(stderr, "usage");
41 void main(int argc, char *argv[])
43 int justinterfaces = 0;
50 while (argc > 0 && *argv[0] == '-') {
59 if (nproto >= maxproto){
60 fprintf(stderr, "too many protos");
66 proto[nproto++] = argv[0];
91 for (i = 0; i < nproto; i++)
94 dir = opendir(netroot);
96 fprintf(stderr, "open %s: %r", netroot);
100 while ((d = readdir(dir))) {
101 if (strcmp(d->d_name, "ipifc") == 0)
103 snprintf(buf, sizeof buf, "%s/%s/0/local", netroot, d->d_name);
104 /* access is bogus for now. */
105 if (1 || access(buf, 0) >= 0)
106 nstat(d->d_name, pip);
108 fprintf(stderr, "Can't access %s\n", d->d_name);
115 void nstat(char *net, void (*f) (char *, struct dirent *))
122 snprintf(buf, sizeof buf, "%s/%s", netroot, net);
127 while ((d = readdir(dir))) {
133 char *getport(char *net, char *p)
135 static char port[10];
137 strncpy(port, p, sizeof(port) - 1);
138 port[sizeof(port) - 1] = 0;
139 if (1) //if(notrans || (p = csgetvalue(netroot, "port", p, net, nil)) == nil)
141 strncpy(port, p, sizeof(port) - 1);
142 port[sizeof(port) - 1] = 0;
147 void pip(char *net, struct dirent *db)
153 if (strcmp(db->d_name, "clone") == 0)
155 if (strcmp(db->d_name, "stats") == 0)
158 snprintf(buf, sizeof buf, "%s/%s/%s/status", netroot, net, db->d_name);
159 fd = open(buf, O_RDONLY);
162 n = read(fd, buf, sizeof(buf));
168 p = strchr(buf, ' ');
171 p = strrchr(buf, '\n');
174 fprintf(out, "%-4s %-4s %-12s ", net, db->d_name, /*db->uid, */ buf);
176 snprintf(buf, sizeof buf, "%s/%s/%s/local", netroot, net, db->d_name);
177 fd = open(buf, O_RDONLY);
182 n = read(fd, buf, sizeof(buf));
189 p = strchr(buf, '!');
195 fprintf(out, "%-10s ", getport(net, p + 1));
197 snprintf(buf, sizeof buf, "%s/%s/%s/remote", netroot, net, db->d_name);
198 fd = open(buf, O_RDONLY);
203 n = read(fd, buf, sizeof(buf));
210 p = strchr(buf, '!');
215 fprintf(out, "%-10s %s\n", getport(net, p), buf);
218 dname = NULL; //csgetvalue(netroot, "ip", buf, "dom", nil);
220 fprintf(out, "%-10s %s\n", getport(net, p), buf);
223 fprintf(out, "%-10s %s\n", getport(net, p), dname);
229 struct ipifc *ip, *nip;
234 // fmtinstall('I', eipfmt);
235 // fmtinstall('M', eipfmt);
237 ip = readipifc(netroot, NULL, -1);
240 for (nip = ip; nip; nip = nip->next) {
241 for (lifc = nip->lifc; lifc; lifc = lifc->next) {
242 i = snprintf(buf, sizeof buf, "%I", lifc->ip);
245 i = snprintf(buf, sizeof buf, "%I", lifc->net);
251 for (nip = ip; nip; nip = nip->next) {
252 for (lifc = nip->lifc; lifc; lifc = lifc->next)
253 fprintf(out, "%-12s %5d %-*I %5M %-*I %8lud %8lud %8lud %8lud\n",
255 l, lifc->ip, lifc->mask, l, lifc->net,
256 nip->pktin, nip->pktout, nip->errin, nip->errout);