summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1995-10-26 20:31:59 +0000
committerjulian <julian@FreeBSD.org>1995-10-26 20:31:59 +0000
commit90ae06d6ac1d2da3758389a70a20c91f3e9fd1dc (patch)
treed823a4d0efac391c6dfad3ac2e27c0e984cea732 /usr.bin/netstat
parent627b063e661d2c0187cf625f83db54c6aca0a0c1 (diff)
downloadFreeBSD-src-90ae06d6ac1d2da3758389a70a20c91f3e9fd1dc.zip
FreeBSD-src-90ae06d6ac1d2da3758389a70a20c91f3e9fd1dc.tar.gz
Reviewed by: julian and jhay@mikom.csir.co.za
Submitted by: Mike Mitchell, supervisor@alb.asctmd.com This is a bulk mport of Mike's IPX/SPX protocol stacks and all the related gunf that goes with it.. it is not guaranteed to work 100% correctly at this time but as we had several people trying to work on it I figured it would be better to get it checked in so they could all get teh same thing to work on.. Mikes been using it for a year or so but on 2.0 more changes and stuff will be merged in from other developers now that this is in. Mike Mitchell, Network Engineer AMTECH Systems Corporation, Technology and Manufacturing 8600 Jefferson Street, Albuquerque, New Mexico 87113 (505) 856-8000 supervisor@alb.asctmd.com
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/Makefile4
-rw-r--r--usr.bin/netstat/if.c28
-rw-r--r--usr.bin/netstat/main.c26
-rw-r--r--usr.bin/netstat/netstat.h8
-rw-r--r--usr.bin/netstat/route.c116
5 files changed, 171 insertions, 11 deletions
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
index 51fc9fa..1c34e30 100644
--- a/usr.bin/netstat/Makefile
+++ b/usr.bin/netstat/Makefile
@@ -1,9 +1,9 @@
# @(#)Makefile 8.1 (Berkeley) 6/12/93
PROG= netstat
-SRCS= if.c inet.c iso.c main.c mbuf.c mroute.c ns.c route.c \
+SRCS= if.c inet.c iso.c main.c mbuf.c mroute.c ipx.c ns.c route.c \
tp_astring.c unix.c
-CFLAGS+=-I/sys
+CFLAGS+=-I/sys # -g
.PATH: ${.CURDIR}/../../sys/netiso
BINGRP= kmem
BINMODE=2555
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index adcc076..cd0a25e 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -43,6 +43,8 @@ static char sccsid[] = "@(#)if.c 8.2 (Berkeley) 2/21/94";
#include <net/if_dl.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#include <netiso/iso.h>
@@ -74,6 +76,7 @@ intpr(interval, ifnetaddr)
union {
struct ifaddr ifa;
struct in_ifaddr in;
+ struct ipx_ifaddr ipx;
struct ns_ifaddr ns;
struct iso_ifaddr iso;
} ifaddr;
@@ -91,7 +94,7 @@ intpr(interval, ifnetaddr)
}
if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
return;
- printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s",
+ printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
if (bflag)
printf(" %10.10s","Ibytes");
@@ -127,7 +130,7 @@ intpr(interval, ifnetaddr)
}
printf("%-5.5s %-5d ", name, ifnet.if_mtu);
if (ifaddraddr == 0) {
- printf("%-11.11s ", "none");
+ printf("%-13.13s ", "none");
printf("%-15.15s ", "none");
} else {
if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
@@ -139,7 +142,7 @@ intpr(interval, ifnetaddr)
CP(&ifaddr); sa = (struct sockaddr *)cp;
switch (sa->sa_family) {
case AF_UNSPEC:
- printf("%-11.11s ", "none");
+ printf("%-13.13s ", "none");
printf("%-15.15s ", "none");
break;
case AF_INET:
@@ -160,12 +163,27 @@ intpr(interval, ifnetaddr)
printf("%-15.15s ",
routename(sin->sin_addr.s_addr));
break;
+ case AF_IPX:
+ {
+ struct sockaddr_ipx *sipx =
+ (struct sockaddr_ipx *)sa;
+ u_long net;
+ char netnum[10];
+
+ *(union ipx_net *) &net = sipx->sipx_addr.x_net;
+ sprintf(netnum, "%lx", ntohl(net));
+ printf("ipx:%-8s ", netnum);
+/* printf("ipx:%-8s ", netname(net, 0L)); */
+ printf("%-15s ",
+ ipx_phost((struct sockaddr *)sipx));
+ }
+ break;
case AF_NS:
{
struct sockaddr_ns *sns =
(struct sockaddr_ns *)sa;
u_long net;
- char netnum[8];
+ char netnum[10];
*(union ns_net *) &net = sns->sns_addr.x_net;
sprintf(netnum, "%lxH", ntohl(net));
@@ -194,7 +212,7 @@ intpr(interval, ifnetaddr)
while (--n >= 0)
m += printf("%02x%c", *cp++ & 0xff,
n > 0 ? '.' : ' ');
- m = 28 - m;
+ m = 30 - m;
while (m-- > 0)
putchar(' ');
break;
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index c8f2a98..47e6943 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -125,6 +125,14 @@ struct nlist nl[] = {
{ "_mfctable" },
#define N_VIFTABLE 30
{ "_viftable" },
+#define N_IPX 31
+ { "_ipxpcb"},
+#define N_IPXSTAT 32
+ { "_ipxstat"},
+#define N_SPXSTAT 33
+ { "_spx_istat"},
+#define N_IPXERR 34
+ { "_ipx_errstat"},
"",
};
@@ -150,6 +158,17 @@ struct protox {
0, 0 }
};
+struct protox ipxprotox[] = {
+ { N_IPX, N_IPXSTAT, 1, ipxprotopr,
+ ipx_stats, "ipx" },
+ { N_IPX, N_SPXSTAT, 1, ipxprotopr,
+ spx_stats, "spx" },
+ { -1, N_IPXERR, 1, 0,
+ ipxerr_stats, "ipx_err" },
+ { -1, -1, 0, 0,
+ 0, 0 }
+};
+
struct protox nsprotox[] = {
{ N_IDP, N_IDPSTAT, 1, nsprotopr,
idp_stats, "idp" },
@@ -174,7 +193,7 @@ struct protox isoprotox[] = {
0, 0 }
};
-struct protox *protoprotox[] = { protox, nsprotox, isoprotox, NULL };
+struct protox *protoprotox[] = { protox, ipxprotox, nsprotox, isoprotox, NULL };
static void printproto __P((struct protox *, char *));
static void usage __P((void));
@@ -221,6 +240,8 @@ main(argc, argv)
case 'f':
if (strcmp(optarg, "ns") == 0)
af = AF_NS;
+ else if (strcmp(optarg, "ipx") == 0)
+ af = AF_IPX;
else if (strcmp(optarg, "inet") == 0)
af = AF_INET;
else if (strcmp(optarg, "unix") == 0)
@@ -384,6 +405,9 @@ main(argc, argv)
}
endprotoent();
}
+ if (af == AF_IPX || af == AF_UNSPEC)
+ for (tp = ipxprotox; tp->pr_name; tp++)
+ printproto(tp, tp->pr_name);
if (af == AF_NS || af == AF_UNSPEC)
for (tp = nsprotox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index aa93f19..ce3bd38 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -80,14 +80,22 @@ void intpr __P((int, u_long));
void pr_rthdr __P(());
void pr_family __P((int));
void rt_stats __P((u_long));
+char *ipx_pnet __P((struct sockaddr *));
+char *ipx_phost __P((struct sockaddr *));
char *ns_phost __P((struct sockaddr *));
void upHex __P((char *));
char *routename __P((u_long));
char *netname __P((u_long, u_long));
+char *ipx_print __P((struct sockaddr *));
char *ns_print __P((struct sockaddr *));
void routepr __P((u_long));
+void ipxprotopr __P((u_long, char *));
+void spx_stats __P((u_long, char *));
+void ipx_stats __P((u_long, char *));
+void ipxerr_stats __P((u_long, char *));
+
void nsprotopr __P((u_long, char *));
void spp_stats __P((u_long, char *));
void idp_stats __P((u_long, char *));
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index ce7695a..ceedda6 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -36,7 +36,7 @@
static char sccsid[] = "From: @(#)route.c 8.3 (Berkeley) 3/9/94";
#endif
static const char rcsid[] =
- "$Id: route.c,v 1.5 1995/05/30 06:32:53 rgrimes Exp $";
+ "$Id: route.c,v 1.6 1995/07/12 19:21:36 bde Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -52,6 +52,8 @@ static const char rcsid[] =
#undef KERNEL
#include <netinet/in.h>
+#include <netipx/ipx.h>
+
#include <netns/ns.h>
#include <sys/sysctl.h>
@@ -169,6 +171,9 @@ pr_family(af)
case AF_INET:
afname = "Internet";
break;
+ case AF_IPX:
+ afname = "IPX";
+ break;
case AF_NS:
afname = "XNS";
break;
@@ -198,7 +203,6 @@ pr_family(af)
void
pr_rthdr()
{
-
if (Aflag)
printf("%-8.8s ","Address");
printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n",
@@ -379,6 +383,16 @@ p_sockaddr(sa, flags, width)
break;
}
+ case AF_IPX:
+ {
+struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr;
+ if (ipx_nullhost(satoipx_addr(work)))
+ cp = "default";
+ else
+ cp = ipx_print(sa);
+ break;
+ }
+
case AF_NS:
cp = ns_print(sa);
break;
@@ -575,7 +589,8 @@ netname(in, mask)
net = i & mask;
while ((mask & 1) == 0)
mask >>= 1, net >>= 1;
- np = getnetbyaddr(net, AF_INET);
+ if (!(np = getnetbyaddr(net, AF_INET)))
+ np = getnetbyaddr(i, AF_INET);
if (np)
cp = np->n_name;
}
@@ -619,6 +634,101 @@ rt_stats(off)
printf("\t%u use%s of a wildcard route\n",
rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
}
+
+char *
+ipx_print(sa)
+ register struct sockaddr *sa;
+{
+ u_short port;
+ struct netent *np = 0;
+ struct hostent *hp = 0;
+ struct servent *sp = 0;
+ char *net = "", *host = "";
+ register char *p; register u_char *q;
+ struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr;
+static char mybuf[50];
+ char cport[10], chost[15], cnet[15];
+
+ sp = getservbyport(work.x_port, "ipx");
+ port = ntohs(work.x_port);
+
+ if (ipx_nullnet(work) && ipx_nullhost(work)) {
+
+ if (port) {
+ if (sp) sprintf(mybuf, "*.%s", sp->s_name);
+ else sprintf(mybuf, "*.%x", port);
+ } else
+ sprintf(mybuf, "*.*");
+
+ return (mybuf);
+ }
+
+ if (np = getnetbyaddr(*(u_long *)&work.x_net, AF_IPX))
+ net = np->n_name;
+ else if (ipx_wildnet(work))
+ net = "any";
+ else if (ipx_nullnet(work))
+ net = "*";
+ else {
+ q = work.x_net.c_net;
+ sprintf(cnet, "%02x%02x%02x%02x",
+ q[0], q[1], q[2], q[3]);
+ for (p = cnet; *p == '0' && p < cnet + 8; p++)
+ continue;
+ net = p;
+ }
+
+ if (hp = gethostbyaddr((char *)&work.x_host, 6, AF_IPX))
+ host = hp->h_name;
+ else if (ipx_wildhost(work))
+ host = "any";
+ else if (ipx_nullhost(work))
+ host = "*";
+ else {
+ q = work.x_host.c_host;
+ sprintf(chost, "%02x%02x%02x%02x%02x%02x",
+ q[0], q[1], q[2], q[3], q[4], q[5]);
+ for (p = chost; *p == '0' && p < chost + 12; p++)
+ continue;
+ host = p;
+ }
+
+ if (port) {
+ if (strcmp(host, "*") == 0) host = "";
+ if (sp) sprintf(cport, "%s%s", *host ? "." : "", sp->s_name);
+ else sprintf(cport, "%s%x", *host ? "." : "", port);
+ } else
+ *cport = 0;
+
+ sprintf(mybuf,"%s.%s%s", net, host, cport);
+ return(mybuf);
+}
+
+char *
+ipx_phost(sa)
+ struct sockaddr *sa;
+{
+ register struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa;
+ struct sockaddr_ipx work;
+static union ipx_net ipx_zeronet;
+ char *p;
+ struct ipx_addr in;
+ struct hostent *hp;
+
+ work = *sipx;
+ in = work.sipx_addr;
+
+ hp = gethostbyaddr((char *)&in, sizeof(struct ipx_addr), AF_IPX);
+ if (hp) return (hp->h_name);
+
+ work.sipx_addr.x_port = 0;
+ work.sipx_addr.x_net = ipx_zeronet;
+ p = ipx_print((struct sockaddr *)&work);
+ if (strncmp("*.", p, 2) == 0) p += 2;
+
+ return(p);
+}
+
short ns_nullh[] = {0,0,0};
short ns_bh[] = {-1,-1,-1};
OpenPOWER on IntegriCloud