2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)atalk.c 1.1 (Whistle) 6/6/96";
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
44 #include <sys/queue.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/protosw.h>
49 #include <arpa/inet.h>
50 #include <net/route.h>
52 #include <netatalk/at.h>
53 #include <netatalk/ddp_var.h>
68 * Print a summary of connections related to a Network Systems
69 * protocol. For XXX, also give state of connection.
70 * Listening processes (aflag) are suppressed unless the
71 * -a (all) flag is specified.
75 at_pr_net(struct sockaddr_at *sat, int numeric)
77 static char mybuf[50];
80 switch(sat->sat_addr.s_net) {
87 sprintf(mybuf,"%hu",ntohs(sat->sat_addr.s_net));
92 at_pr_host(struct sockaddr_at *sat, int numeric)
94 static char mybuf[50];
97 switch(sat->sat_addr.s_node) {
104 sprintf(mybuf,"%d",(unsigned int)sat->sat_addr.s_node);
109 at_pr_port(struct sockaddr_at *sat)
111 static char mybuf[50];
112 struct servent *serv;
114 switch(sat->sat_port) {
121 (void)snprintf(mybuf, sizeof(mybuf), "%d",
122 (unsigned int)sat->sat_port);
124 serv = getservbyport(sat->sat_port, "ddp");
126 (void)snprintf(mybuf, sizeof(mybuf), "%d",
127 (unsigned int) sat->sat_port);
129 (void) snprintf(mybuf, sizeof(mybuf), "%s",
137 at_pr_range(struct sockaddr_at *sat)
139 static char mybuf[50];
141 if(sat->sat_range.r_netrange.nr_firstnet
142 != sat->sat_range.r_netrange.nr_lastnet) {
143 sprintf(mybuf,"%d-%d",
144 ntohs(sat->sat_range.r_netrange.nr_firstnet),
145 ntohs(sat->sat_range.r_netrange.nr_lastnet));
148 ntohs(sat->sat_range.r_netrange.nr_firstnet));
154 /* what == 0 for addr only == 3 */
158 /* 8 for numeric only */
160 atalk_print(struct sockaddr *sa, int what)
162 struct sockaddr_at *sat = (struct sockaddr_at *)sa;
163 static char mybuf[50];
164 int numeric = (what & 0x08);
167 switch (what & 0x13) {
172 sprintf(mybuf,"%s",at_pr_net(sat, numeric));
175 sprintf(mybuf,"%s",at_pr_host(sat, numeric));
178 sprintf(mybuf,"%s.%s",
179 at_pr_net(sat, numeric),
180 at_pr_host(sat, numeric));
183 sprintf(mybuf,"%s", at_pr_range(sat));
186 sprintf(mybuf+strlen(mybuf),".%s",at_pr_port(sat));
192 atalk_print2(struct sockaddr *sa, struct sockaddr *mask, int what)
195 static char buf[100];
196 struct sockaddr_at *sat1, *sat2;
197 struct sockaddr_at thesockaddr;
198 struct sockaddr *sa2;
200 sat1 = (struct sockaddr_at *)sa;
201 sat2 = (struct sockaddr_at *)mask;
202 sa2 = (struct sockaddr *)&thesockaddr;
204 thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net & sat2->sat_addr.s_net;
205 snprintf(buf, sizeof(buf), "%s", atalk_print(sa2, 1 |(what & 8)));
206 if(sat2->sat_addr.s_net != 0xFFFF) {
207 thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net | ~sat2->sat_addr.s_net;
209 snprintf(buf + n, sizeof(buf) - n, "-%s", atalk_print(sa2, 1 |(what & 8)));
213 snprintf(buf + n, sizeof(buf) - n, ".%s", atalk_print(sa, what & (~1)));
219 atalkprotopr(u_long off __unused, const char *name, int af1 __unused)
221 struct ddpcb *this, *next;
225 kread(off, (char *)&this, sizeof (struct ddpcb *));
226 for ( ; this != NULL; this = next) {
227 kread((u_long)this, (char *)&ddpcb, sizeof (ddpcb));
228 next = ddpcb.ddp_next;
230 if (!aflag && atalk_nullhost(ddpcb.ddp_lsat) ) {
234 kread((u_long)ddpcb.ddp_socket, (char *)&sockb, sizeof (sockb));
236 printf("Active ATALK connections");
238 printf(" (including servers)");
241 printf("%-8.8s ", "PCB");
243 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
244 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
245 "Proto", "Recv-Q", "Send-Q",
246 "Local Address", "Foreign Address", "(state)");
250 printf("%8lx ", (u_long) this);
251 printf("%-5.5s %6u %6u ", name, sockb.so_rcv.sb_cc,
253 printf(Aflag?" %-18.18s":" %-22.22s", atalk_print(
254 (struct sockaddr *)&ddpcb.ddp_lsat,7));
255 printf(Aflag?" %-18.18s":" %-22.22s", atalk_print(
256 (struct sockaddr *)&ddpcb.ddp_fsat,7));
261 #define ANY(x,y,z) if (x || sflag <= 1) \
262 printf("\t%lu %s%s%s\n",x,y,plural(x),z)
265 * Dump DDP statistics structure.
268 ddp_stats(u_long off __unused, const char *name, int af1 __unused)
270 struct ddpstat ddpstat;
274 kread(off, (char *)&ddpstat, sizeof (ddpstat));
275 printf("%s:\n", name);
276 ANY(ddpstat.ddps_short, "packet", " with short headers ");
277 ANY(ddpstat.ddps_long, "packet", " with long headers ");
278 ANY(ddpstat.ddps_nosum, "packet", " with no checksum ");
279 ANY(ddpstat.ddps_tooshort, "packet", " too short ");
280 ANY(ddpstat.ddps_badsum, "packet", " with bad checksum ");
281 ANY(ddpstat.ddps_toosmall, "packet", " with not enough data ");
282 ANY(ddpstat.ddps_forward, "packet", " forwarded ");
283 ANY(ddpstat.ddps_encap, "packet", " encapsulated ");
284 ANY(ddpstat.ddps_cantforward, "packet", " rcvd for unreachable dest ");
285 ANY(ddpstat.ddps_nosockspace, "packet", " dropped due to no socket space ");