1996-06-08 00:20:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2004-07-26 20:18:11 +00:00
|
|
|
#if 0
|
1996-06-08 00:20:42 +00:00
|
|
|
#ifndef lint
|
|
|
|
static char sccsid[] = "@(#)atalk.c 1.1 (Whistle) 6/6/96";
|
|
|
|
#endif /* not lint */
|
2004-07-26 20:18:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1996-06-08 00:20:42 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
#include <arpa/inet.h>
|
1996-06-08 00:20:42 +00:00
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/ddp_var.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
2001-06-15 20:47:01 +00:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <netdb.h>
|
1996-06-08 00:20:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "netstat.h"
|
|
|
|
|
|
|
|
struct ddpcb ddpcb;
|
|
|
|
struct socket sockb;
|
|
|
|
|
|
|
|
static int first = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a summary of connections related to a Network Systems
|
|
|
|
* protocol. For XXX, also give state of connection.
|
|
|
|
* Listening processes (aflag) are suppressed unless the
|
|
|
|
* -a (all) flag is specified.
|
|
|
|
*/
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
static const char *
|
1996-07-23 01:18:47 +00:00
|
|
|
at_pr_net(struct sockaddr_at *sat, int numeric)
|
1996-06-10 21:03:38 +00:00
|
|
|
{
|
|
|
|
static char mybuf[50];
|
|
|
|
|
1996-07-23 01:18:47 +00:00
|
|
|
if (!numeric) {
|
|
|
|
switch(sat->sat_addr.s_net) {
|
|
|
|
case 0xffff:
|
|
|
|
return "????";
|
|
|
|
case ATADDR_ANYNET:
|
|
|
|
return("*");
|
|
|
|
}
|
1996-06-10 21:03:38 +00:00
|
|
|
}
|
1996-07-23 01:18:47 +00:00
|
|
|
sprintf(mybuf,"%hu",ntohs(sat->sat_addr.s_net));
|
1996-06-10 21:03:38 +00:00
|
|
|
return mybuf;
|
|
|
|
}
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
static const char *
|
1996-07-23 01:18:47 +00:00
|
|
|
at_pr_host(struct sockaddr_at *sat, int numeric)
|
1996-06-10 21:03:38 +00:00
|
|
|
{
|
|
|
|
static char mybuf[50];
|
|
|
|
|
1996-07-23 01:18:47 +00:00
|
|
|
if (!numeric) {
|
|
|
|
switch(sat->sat_addr.s_node) {
|
|
|
|
case ATADDR_BCAST:
|
|
|
|
return "bcast";
|
|
|
|
case ATADDR_ANYNODE:
|
|
|
|
return("*");
|
|
|
|
}
|
1996-06-10 21:03:38 +00:00
|
|
|
}
|
1996-07-23 01:18:47 +00:00
|
|
|
sprintf(mybuf,"%d",(unsigned int)sat->sat_addr.s_node);
|
1996-06-10 21:03:38 +00:00
|
|
|
return mybuf;
|
|
|
|
}
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
static const char *
|
1996-06-10 21:03:38 +00:00
|
|
|
at_pr_port(struct sockaddr_at *sat)
|
|
|
|
{
|
|
|
|
static char mybuf[50];
|
2001-06-15 20:47:01 +00:00
|
|
|
struct servent *serv;
|
1996-06-10 21:03:38 +00:00
|
|
|
|
|
|
|
switch(sat->sat_port) {
|
|
|
|
case ATADDR_ANYPORT:
|
1996-07-09 02:55:47 +00:00
|
|
|
return("*");
|
1996-06-10 21:03:38 +00:00
|
|
|
case 0xff:
|
|
|
|
return "????";
|
|
|
|
default:
|
2001-06-15 22:57:41 +00:00
|
|
|
if (numeric_port) {
|
2001-06-15 20:47:01 +00:00
|
|
|
(void)snprintf(mybuf, sizeof(mybuf), "%d",
|
|
|
|
(unsigned int)sat->sat_port);
|
|
|
|
} else {
|
|
|
|
serv = getservbyport(sat->sat_port, "ddp");
|
|
|
|
if (serv == NULL)
|
|
|
|
(void)snprintf(mybuf, sizeof(mybuf), "%d",
|
|
|
|
(unsigned int) sat->sat_port);
|
|
|
|
else
|
|
|
|
(void) snprintf(mybuf, sizeof(mybuf), "%s",
|
|
|
|
serv->s_name);
|
|
|
|
}
|
1996-06-10 21:03:38 +00:00
|
|
|
}
|
|
|
|
return mybuf;
|
|
|
|
}
|
|
|
|
|
1996-08-31 07:43:01 +00:00
|
|
|
static char *
|
|
|
|
at_pr_range(struct sockaddr_at *sat)
|
|
|
|
{
|
|
|
|
static char mybuf[50];
|
|
|
|
|
|
|
|
if(sat->sat_range.r_netrange.nr_firstnet
|
|
|
|
!= sat->sat_range.r_netrange.nr_lastnet) {
|
|
|
|
sprintf(mybuf,"%d-%d",
|
|
|
|
ntohs(sat->sat_range.r_netrange.nr_firstnet),
|
|
|
|
ntohs(sat->sat_range.r_netrange.nr_lastnet));
|
|
|
|
} else {
|
|
|
|
sprintf(mybuf,"%d",
|
|
|
|
ntohs(sat->sat_range.r_netrange.nr_firstnet));
|
|
|
|
}
|
|
|
|
return mybuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-06-10 21:03:38 +00:00
|
|
|
/* what == 0 for addr only == 3 */
|
|
|
|
/* 1 for net */
|
|
|
|
/* 2 for host */
|
|
|
|
/* 4 for port */
|
1996-07-23 01:18:47 +00:00
|
|
|
/* 8 for numeric only */
|
1996-06-10 21:03:38 +00:00
|
|
|
char *
|
2001-06-15 23:35:13 +00:00
|
|
|
atalk_print(struct sockaddr *sa, int what)
|
1996-06-10 21:03:38 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_at *sat = (struct sockaddr_at *)sa;
|
1996-07-23 01:18:47 +00:00
|
|
|
static char mybuf[50];
|
|
|
|
int numeric = (what & 0x08);
|
1996-06-10 21:03:38 +00:00
|
|
|
|
|
|
|
mybuf[0] = 0;
|
1996-08-31 07:43:01 +00:00
|
|
|
switch (what & 0x13) {
|
1996-06-10 21:03:38 +00:00
|
|
|
case 0:
|
|
|
|
mybuf[0] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
1996-07-23 01:18:47 +00:00
|
|
|
sprintf(mybuf,"%s",at_pr_net(sat, numeric));
|
1996-06-10 21:03:38 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1996-07-23 01:18:47 +00:00
|
|
|
sprintf(mybuf,"%s",at_pr_host(sat, numeric));
|
1996-06-10 21:03:38 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
1996-07-23 01:18:47 +00:00
|
|
|
sprintf(mybuf,"%s.%s",
|
|
|
|
at_pr_net(sat, numeric),
|
|
|
|
at_pr_host(sat, numeric));
|
1996-08-31 07:43:01 +00:00
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
sprintf(mybuf,"%s", at_pr_range(sat));
|
1996-06-10 21:03:38 +00:00
|
|
|
}
|
|
|
|
if (what & 4) {
|
1996-08-31 07:43:01 +00:00
|
|
|
sprintf(mybuf+strlen(mybuf),".%s",at_pr_port(sat));
|
1996-06-10 21:03:38 +00:00
|
|
|
}
|
|
|
|
return mybuf;
|
|
|
|
}
|
1996-07-23 01:18:47 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
atalk_print2(struct sockaddr *sa, struct sockaddr *mask, int what)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
static char buf[100];
|
1996-08-31 07:43:01 +00:00
|
|
|
struct sockaddr_at *sat1, *sat2;
|
|
|
|
struct sockaddr_at thesockaddr;
|
|
|
|
struct sockaddr *sa2;
|
|
|
|
|
|
|
|
sat1 = (struct sockaddr_at *)sa;
|
|
|
|
sat2 = (struct sockaddr_at *)mask;
|
|
|
|
sa2 = (struct sockaddr *)&thesockaddr;
|
|
|
|
|
|
|
|
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net & sat2->sat_addr.s_net;
|
2001-08-20 11:58:05 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s", atalk_print(sa2, 1 |(what & 8)));
|
1996-08-31 07:43:01 +00:00
|
|
|
if(sat2->sat_addr.s_net != 0xFFFF) {
|
|
|
|
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net | ~sat2->sat_addr.s_net;
|
2001-08-20 11:58:05 +00:00
|
|
|
n = strlen(buf);
|
|
|
|
snprintf(buf + n, sizeof(buf) - n, "-%s", atalk_print(sa2, 1 |(what & 8)));
|
|
|
|
}
|
|
|
|
if(what & 2) {
|
|
|
|
n = strlen(buf);
|
|
|
|
snprintf(buf + n, sizeof(buf) - n, ".%s", atalk_print(sa, what & (~1)));
|
1996-08-31 07:43:01 +00:00
|
|
|
}
|
1996-07-23 01:18:47 +00:00
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
1996-06-08 00:20:42 +00:00
|
|
|
void
|
2002-09-05 17:06:51 +00:00
|
|
|
atalkprotopr(u_long off __unused, const char *name, int af1 __unused)
|
1996-06-08 00:20:42 +00:00
|
|
|
{
|
1999-10-21 07:08:56 +00:00
|
|
|
struct ddpcb *this, *next;
|
1996-06-08 00:20:42 +00:00
|
|
|
|
|
|
|
if (off == 0)
|
|
|
|
return;
|
1999-10-21 07:08:56 +00:00
|
|
|
kread(off, (char *)&this, sizeof (struct ddpcb *));
|
|
|
|
for ( ; this != NULL; this = next) {
|
|
|
|
kread((u_long)this, (char *)&ddpcb, sizeof (ddpcb));
|
1996-06-08 00:20:42 +00:00
|
|
|
next = ddpcb.ddp_next;
|
|
|
|
#if 0
|
|
|
|
if (!aflag && atalk_nullhost(ddpcb.ddp_lsat) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-21 07:08:56 +00:00
|
|
|
kread((u_long)ddpcb.ddp_socket, (char *)&sockb, sizeof (sockb));
|
1996-06-08 00:20:42 +00:00
|
|
|
if (first) {
|
|
|
|
printf("Active ATALK connections");
|
|
|
|
if (aflag)
|
|
|
|
printf(" (including servers)");
|
|
|
|
putchar('\n');
|
|
|
|
if (Aflag)
|
|
|
|
printf("%-8.8s ", "PCB");
|
|
|
|
printf(Aflag ?
|
|
|
|
"%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
|
|
|
|
"%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
|
|
|
|
"Proto", "Recv-Q", "Send-Q",
|
|
|
|
"Local Address", "Foreign Address", "(state)");
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
if (Aflag)
|
1999-10-21 07:08:56 +00:00
|
|
|
printf("%8lx ", (u_long) this);
|
2002-07-24 03:02:43 +00:00
|
|
|
printf("%-5.5s %6u %6u ", name, sockb.so_rcv.sb_cc,
|
1996-06-08 00:20:42 +00:00
|
|
|
sockb.so_snd.sb_cc);
|
|
|
|
printf(Aflag?" %-18.18s":" %-22.22s", atalk_print(
|
1996-06-10 21:03:38 +00:00
|
|
|
(struct sockaddr *)&ddpcb.ddp_lsat,7));
|
1996-06-08 00:20:42 +00:00
|
|
|
printf(Aflag?" %-18.18s":" %-22.22s", atalk_print(
|
1996-06-10 21:03:38 +00:00
|
|
|
(struct sockaddr *)&ddpcb.ddp_fsat,7));
|
1996-06-08 00:20:42 +00:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
1998-07-06 21:01:54 +00:00
|
|
|
|
2001-06-12 14:00:39 +00:00
|
|
|
#define ANY(x,y,z) if (x || sflag <= 1) \
|
|
|
|
printf("\t%lu %s%s%s\n",x,y,plural(x),z)
|
1996-06-08 00:20:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump DDP statistics structure.
|
|
|
|
*/
|
|
|
|
void
|
2002-09-05 17:06:51 +00:00
|
|
|
ddp_stats(u_long off __unused, const char *name, int af1 __unused)
|
1996-06-08 00:20:42 +00:00
|
|
|
{
|
|
|
|
struct ddpstat ddpstat;
|
|
|
|
|
|
|
|
if (off == 0)
|
|
|
|
return;
|
|
|
|
kread(off, (char *)&ddpstat, sizeof (ddpstat));
|
|
|
|
printf("%s:\n", name);
|
|
|
|
ANY(ddpstat.ddps_short, "packet", " with short headers ");
|
|
|
|
ANY(ddpstat.ddps_long, "packet", " with long headers ");
|
|
|
|
ANY(ddpstat.ddps_nosum, "packet", " with no checksum ");
|
|
|
|
ANY(ddpstat.ddps_tooshort, "packet", " too short ");
|
|
|
|
ANY(ddpstat.ddps_badsum, "packet", " with bad checksum ");
|
|
|
|
ANY(ddpstat.ddps_toosmall, "packet", " with not enough data ");
|
|
|
|
ANY(ddpstat.ddps_forward, "packet", " forwarded ");
|
|
|
|
ANY(ddpstat.ddps_encap, "packet", " encapsulated ");
|
|
|
|
ANY(ddpstat.ddps_cantforward, "packet", " rcvd for unreachable dest ");
|
|
|
|
ANY(ddpstat.ddps_nosockspace, "packet", " dropped due to no socket space ");
|
|
|
|
}
|