diff --git a/usr.bin/netstat/ipx.c b/usr.bin/netstat/ipx.c index 654d2e6babe2..0e8d34ff8d17 100644 --- a/usr.bin/netstat/ipx.c +++ b/usr.bin/netstat/ipx.c @@ -1,351 +1,364 @@ /* * 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. */ #ifndef lint /* static char sccsid[] = "@(#)ns.c 8.1 (Berkeley) 6/6/93"; */ static const char rcsid[] = - "$Id$"; + "$Id: ipx.c,v 1.7 1997/02/22 19:56:22 peter Exp $"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include +#ifdef IPXERRORMSGS #include +#endif #include #include #include #define SANAMES #include #include #include #include #include #include "netstat.h" struct ipxpcb ipxpcb; struct spxpcb spxpcb; struct socket sockb; static char *ipx_prpr __P((struct ipx_addr *)); static void ipx_erputil __P((int, int)); static int first = 1; /* * Print a summary of connections related to a Network Systems * protocol. For SPX, also give state of connection. * Listening processes (aflag) are suppressed unless the * -a (all) flag is specified. */ void ipxprotopr(off, name) u_long off; char *name; { struct ipxpcb cb; register struct ipxpcb *prev, *next; int isspx; if (off == 0) return; isspx = strcmp(name, "spx") == 0; kread(off, (char *)&cb, sizeof (struct ipxpcb)); ipxpcb = cb; prev = (struct ipxpcb *)off; if (ipxpcb.ipxp_next == (struct ipxpcb *)off) return; for (;ipxpcb.ipxp_next != (struct ipxpcb *)off; prev = next) { u_long ppcb; next = ipxpcb.ipxp_next; kread((u_long)next, (char *)&ipxpcb, sizeof (ipxpcb)); if (ipxpcb.ipxp_prev != prev) { printf("???\n"); break; } if (!aflag && ipx_nullhost(ipxpcb.ipxp_faddr) ) { continue; } kread((u_long)ipxpcb.ipxp_socket, (char *)&sockb, sizeof (sockb)); ppcb = (u_long) ipxpcb.ipxp_pcb; if (ppcb) { if (isspx) { kread(ppcb, (char *)&spxpcb, sizeof (spxpcb)); } else continue; } else if (isspx) continue; if (first) { printf("Active IPX 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) printf("%8lx ", ppcb); printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc); printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_laddr)); printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_faddr)); if (isspx) { extern char *tcpstates[]; if (spxpcb.s_state >= TCP_NSTATES) printf(" %d", spxpcb.s_state); else printf(" %s", tcpstates[spxpcb.s_state]); } putchar('\n'); prev = next; } } -#define ANY(x,y,z) \ - ((x) ? printf("\t%ld %s%s%s -- %s\n",(long)x,y,plural(x),z,"x") : 0) + +#define ANY(x,y,z) (printf("\t%u %s%s%s\n",x,y,plural(x),z)) /* * Dump SPX statistics structure. */ void spx_stats(off, name) u_long off; char *name; { struct spx_istat spx_istat; #define spxstat spx_istat.newstats if (off == 0) return; kread(off, (char *)&spx_istat, sizeof (spx_istat)); printf("%s:\n", name); ANY(spx_istat.nonucn, "connection", " dropped due to no new sockets "); ANY(spx_istat.gonawy, "connection", " terminated due to our end dying"); ANY(spx_istat.nonucn, "connection", " dropped due to inability to connect"); ANY(spx_istat.noconn, "connection", " dropped due to inability to connect"); ANY(spx_istat.notme, "connection", " incompleted due to mismatched id's"); ANY(spx_istat.wrncon, "connection", " dropped due to mismatched id's"); ANY(spx_istat.bdreas, "packet", " dropped out of sequence"); ANY(spx_istat.lstdup, "packet", " duplicating the highest packet"); ANY(spx_istat.notyet, "packet", " refused as exceeding allocation"); ANY(spxstat.spxs_connattempt, "connection", " initiated"); ANY(spxstat.spxs_accepts, "connection", " accepted"); ANY(spxstat.spxs_connects, "connection", " established"); ANY(spxstat.spxs_drops, "connection", " dropped"); ANY(spxstat.spxs_conndrops, "embryonic connection", " dropped"); ANY(spxstat.spxs_closed, "connection", " closed (includes drops)"); ANY(spxstat.spxs_segstimed, "packet", " where we tried to get rtt"); ANY(spxstat.spxs_rttupdated, "time", " we got rtt"); ANY(spxstat.spxs_delack, "delayed ack", " sent"); ANY(spxstat.spxs_timeoutdrop, "connection", " dropped in rxmt timeout"); ANY(spxstat.spxs_rexmttimeo, "retransmit timeout", ""); ANY(spxstat.spxs_persisttimeo, "persist timeout", ""); ANY(spxstat.spxs_keeptimeo, "keepalive timeout", ""); ANY(spxstat.spxs_keepprobe, "keepalive probe", " sent"); ANY(spxstat.spxs_keepdrops, "connection", " dropped in keepalive"); ANY(spxstat.spxs_sndtotal, "total packet", " sent"); ANY(spxstat.spxs_sndpack, "data packet", " sent"); ANY(spxstat.spxs_sndbyte, "data byte", " sent"); ANY(spxstat.spxs_sndrexmitpack, "data packet", " retransmitted"); ANY(spxstat.spxs_sndrexmitbyte, "data byte", " retransmitted"); ANY(spxstat.spxs_sndacks, "ack-only packet", " sent"); ANY(spxstat.spxs_sndprobe, "window probe", " sent"); ANY(spxstat.spxs_sndurg, "packet", " sent with URG only"); ANY(spxstat.spxs_sndwinup, "window update-only packet", " sent"); ANY(spxstat.spxs_sndctrl, "control (SYN|FIN|RST) packet", " sent"); ANY(spxstat.spxs_sndvoid, "request", " to send a non-existant packet"); ANY(spxstat.spxs_rcvtotal, "total packet", " received"); ANY(spxstat.spxs_rcvpack, "packet", " received in sequence"); ANY(spxstat.spxs_rcvbyte, "byte", " received in sequence"); ANY(spxstat.spxs_rcvbadsum, "packet", " received with ccksum errs"); ANY(spxstat.spxs_rcvbadoff, "packet", " received with bad offset"); ANY(spxstat.spxs_rcvshort, "packet", " received too short"); ANY(spxstat.spxs_rcvduppack, "duplicate-only packet", " received"); ANY(spxstat.spxs_rcvdupbyte, "duplicate-only byte", " received"); ANY(spxstat.spxs_rcvpartduppack, "packet", " with some duplicate data"); ANY(spxstat.spxs_rcvpartdupbyte, "dup. byte", " in part-dup. packet"); ANY(spxstat.spxs_rcvoopack, "out-of-order packet", " received"); ANY(spxstat.spxs_rcvoobyte, "out-of-order byte", " received"); ANY(spxstat.spxs_rcvpackafterwin, "packet", " with data after window"); ANY(spxstat.spxs_rcvbyteafterwin, "byte", " rcvd after window"); ANY(spxstat.spxs_rcvafterclose, "packet", " rcvd after 'close'"); ANY(spxstat.spxs_rcvwinprobe, "rcvd window probe packet", ""); ANY(spxstat.spxs_rcvdupack, "rcvd duplicate ack", ""); ANY(spxstat.spxs_rcvacktoomuch, "rcvd ack", " for unsent data"); ANY(spxstat.spxs_rcvackpack, "rcvd ack packet", ""); ANY(spxstat.spxs_rcvackbyte, "byte", " acked by rcvd acks"); ANY(spxstat.spxs_rcvwinupd, "rcvd window update packet", ""); } + #undef ANY -#define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0) +#define ANY(x,y,z) (printf("\t%u %s%s%s\n",x,y,plural(x),z)) /* * Dump IPX statistics structure. */ void ipx_stats(off, name) u_long off; char *name; { struct ipxstat ipxstat; if (off == 0) return; kread(off, (char *)&ipxstat, sizeof (ipxstat)); printf("%s:\n", name); - ANY(ipxstat.ipxs_toosmall, "packet", " smaller than a header"); - ANY(ipxstat.ipxs_tooshort, "packet", " smaller than advertised"); + ANY(ipxstat.ipxs_total, "total packet", " received"); ANY(ipxstat.ipxs_badsum, "packet", " with bad checksums"); + ANY(ipxstat.ipxs_tooshort, "packet", " smaller than advertised"); + ANY(ipxstat.ipxs_toosmall, "packet", " smaller than a header"); + ANY(ipxstat.ipxs_forward, "packet", " forwarded"); + ANY(ipxstat.ipxs_cantforward, "packet", " not forwardable"); + ANY(ipxstat.ipxs_delivered, "packet", " for this host"); + ANY(ipxstat.ipxs_localout, "packet", " sent from this host"); + ANY(ipxstat.ipxs_odropped, "packet", " dropped due to no bufs, etc."); + ANY(ipxstat.ipxs_noroute, "packet", " discarded due to no route"); + ANY(ipxstat.ipxs_mtutoosmall, "packet", " too big"); } static struct { u_short code; char *name; char *where; } ipx_errnames[] = { {0, "Unspecified Error", " at Destination"}, {1, "Bad Checksum", " at Destination"}, {2, "No Listener", " at Socket"}, {3, "Packet", " Refused due to lack of space at Destination"}, {01000, "Unspecified Error", " while gatewayed"}, {01001, "Bad Checksum", " while gatewayed"}, {01002, "Packet", " forwarded too many times"}, {01003, "Packet", " too large to be forwarded"}, {-1, 0, 0}, }; +#ifdef IPXERRORMSGS /* * Dump IPX Error statistics structure. */ /*ARGSUSED*/ void ipxerr_stats(off, name) u_long off; char *name; { struct ipx_errstat ipx_errstat; register int j; register int histoprint = 1; int z; if (off == 0) return; kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat)); printf("IPX error statistics:\n"); ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error"); ANY(ipx_errstat.ipx_es_oldshort, "error", " ignored due to insufficient addressing"); ANY(ipx_errstat.ipx_es_oldipx_err, "error request", " in response to error packets"); ANY(ipx_errstat.ipx_es_tooshort, "error packet", " received incomplete"); ANY(ipx_errstat.ipx_es_badcode, "error packet", " received of unknown type"); for(j = 0; j < IPX_ERR_MAX; j ++) { z = ipx_errstat.ipx_es_outhist[j]; if (z && histoprint) { printf("Output Error Histogram:\n"); histoprint = 0; } ipx_erputil(z, ipx_errstat.ipx_es_codes[j]); } histoprint = 1; for(j = 0; j < IPX_ERR_MAX; j ++) { z = ipx_errstat.ipx_es_inhist[j]; if (z && histoprint) { printf("Input Error Histogram:\n"); histoprint = 0; } ipx_erputil(z, ipx_errstat.ipx_es_codes[j]); } } static void ipx_erputil(z, c) int z, c; { int j; char codebuf[30]; char *name, *where; for(j = 0;; j ++) { if ((name = ipx_errnames[j].name) == 0) break; if (ipx_errnames[j].code == c) break; } if (name == 0) { if (c > 01000) where = "in transit"; else where = "at destination"; sprintf(codebuf, "Unknown IPX error code 0%o", c); name = codebuf; } else where = ipx_errnames[j].where; ANY(z, name, where); } +#endif /* IPXERRORMSGS */ static struct sockaddr_ipx ssipx = {AF_IPX}; static char *ipx_prpr(x) struct ipx_addr *x; { struct sockaddr_ipx *sipx = &ssipx; sipx->sipx_addr = *x; return(ipx_print((struct sockaddr *)sipx)); } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 56b908035243..08e15ee10f26 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,615 +1,611 @@ /* * Copyright (c) 1983, 1988, 1993 * 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. */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1983, 1988, 1993\n\ Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" struct nlist nl[] = { #define N_MBSTAT 0 { "_mbstat" }, #define N_IPSTAT 1 { "_ipstat" }, #define N_TCB 2 { "_tcb" }, #define N_TCPSTAT 3 { "_tcpstat" }, #define N_UDB 4 { "_udb" }, #define N_UDPSTAT 5 { "_udpstat" }, #define N_IFNET 6 { "_ifnet" }, #define N_IMP 7 { "_imp_softc" }, #define N_ICMPSTAT 8 { "_icmpstat" }, #define N_RTSTAT 9 { "_rtstat" }, #define N_UNIXSW 10 { "_localsw" }, #define N_IDP 11 { "_nspcb"}, #define N_IDPSTAT 12 { "_idpstat"}, #define N_SPPSTAT 13 { "_spp_istat"}, #define N_NSERR 14 { "_ns_errstat"}, #define N_CLNPSTAT 15 { "_clnp_stat"}, #define IN_NOTUSED 16 { "_tp_inpcb" }, #define ISO_TP 17 { "_tp_refinfo" }, #define N_TPSTAT 18 { "_tp_stat" }, #define N_ESISSTAT 19 { "_esis_stat"}, #define N_NIMP 20 { "_nimp"}, #define N_RTREE 21 { "_rt_tables"}, #define N_CLTP 22 { "_cltb"}, #define N_CLTPSTAT 23 { "_cltpstat"}, #define N_NFILE 24 { "_nfile" }, #define N_FILE 25 { "_file" }, #define N_IGMPSTAT 26 { "_igmpstat" }, #define N_MRTPROTO 27 { "_ip_mrtproto" }, #define N_MRTSTAT 28 { "_mrtstat" }, #define N_MFCTABLE 29 { "_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"}, -#define N_DDPSTAT 35 +#define N_DDPSTAT 34 { "_ddpstat"}, -#define N_DDPCB 36 +#define N_DDPCB 35 { "_ddpcb"}, -#define N_DIVPCB 37 +#define N_DIVPCB 36 { "_divcb"}, -#define N_DIVSTAT 38 +#define N_DIVSTAT 37 { "_divstat"}, { "" }, }; struct protox { u_char pr_index; /* index into nlist of cb head */ u_char pr_sindex; /* index into nlist of stat block */ u_char pr_wanted; /* 1 if wanted, 0 otherwise */ void (*pr_cblocks)(); /* control blocks printing routine */ void (*pr_stats)(); /* statistics printing routine */ char *pr_name; /* well-known name */ } protox[] = { { N_TCB, N_TCPSTAT, 1, protopr, tcp_stats, "tcp" }, { N_UDB, N_UDPSTAT, 1, protopr, udp_stats, "udp" }, { N_DIVPCB, N_DIVSTAT, 1, protopr, NULL, "divert" }, /* no stat structure yet */ { -1, N_IPSTAT, 1, 0, ip_stats, "ip" }, { -1, N_ICMPSTAT, 1, 0, icmp_stats, "icmp" }, { -1, N_IGMPSTAT, 1, 0, igmp_stats, "igmp" }, { -1, -1, 0, 0, 0, 0 } }; struct protox atalkprotox[] = { { N_DDPCB, N_DDPSTAT, 1, atalkprotopr, ddp_stats, "ddp" }, { -1, -1, 0, 0, 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 } }; #ifdef NS struct protox nsprotox[] = { { N_IDP, N_IDPSTAT, 1, nsprotopr, idp_stats, "idp" }, { N_IDP, N_SPPSTAT, 1, nsprotopr, spp_stats, "spp" }, { -1, N_NSERR, 1, 0, nserr_stats, "ns_err" }, { -1, -1, 0, 0, 0, 0 } }; #endif #ifdef ISO struct protox isoprotox[] = { { ISO_TP, N_TPSTAT, 1, iso_protopr, tp_stats, "tp" }, { N_CLTP, N_CLTPSTAT, 1, iso_protopr, cltp_stats, "cltp" }, { -1, N_CLNPSTAT, 1, 0, clnp_stats, "clnp"}, { -1, N_ESISSTAT, 1, 0, esis_stats, "esis"}, { -1, -1, 0, 0, 0, 0 } }; #endif struct protox *protoprotox[] = { protox, ipxprotox, atalkprotox, #ifdef NS nsprotox, #endif #ifdef ISO isoprotox, #endif NULL }; static void printproto __P((struct protox *, char *)); static void usage __P((void)); static struct protox *name2protox __P((char *)); static struct protox *knownname __P((char *)); kvm_t *kvmd; int main(argc, argv) int argc; char *argv[]; { extern char *optarg; extern int optind; register struct protoent *p; register struct protox *tp; /* for printing cblocks & stats */ register char *cp; int ch; char *nlistf = NULL, *memf = NULL; char buf[_POSIX2_LINE_MAX]; if ((cp = rindex(argv[0], '/'))) prog = cp + 1; else prog = argv[0]; af = AF_UNSPEC; while ((ch = getopt(argc, argv, "Aabdf:ghI:iM:mN:np:rstuw:")) != -1) switch(ch) { case 'A': Aflag = 1; break; case 'a': aflag = 1; break; case 'b': bflag = 1; break; case 'd': dflag = 1; break; case 'f': #ifdef NS if (strcmp(optarg, "ns") == 0) af = AF_NS; else #endif if (strcmp(optarg, "ipx") == 0) af = AF_IPX; else if (strcmp(optarg, "inet") == 0) af = AF_INET; else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; else if (strcmp(optarg, "atalk") == 0) af = AF_APPLETALK; #ifdef ISO else if (strcmp(optarg, "iso") == 0) af = AF_ISO; #endif else { errx(1, "%s: unknown address family", optarg); } break; case 'g': gflag = 1; break; case 'I': { char *cp; iflag = 1; for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); break; } case 'i': iflag = 1; break; case 'M': memf = optarg; break; case 'm': mflag = 1; break; case 'N': nlistf = optarg; break; case 'n': nflag = 1; break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, "%s: unknown or uninstrumented protocol", optarg); } pflag = 1; break; case 'r': rflag = 1; break; case 's': ++sflag; break; case 't': tflag = 1; break; case 'u': af = AF_UNIX; break; case 'w': interval = atoi(optarg); iflag = 1; break; case '?': default: usage(); } argv += optind; argc -= optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { if (isdigit(**argv)) { interval = atoi(*argv); if (interval <= 0) usage(); ++argv; iflag = 1; } if (*argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) setgid(getgid()); kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf); if (kvmd == NULL) { errx(1, "kvm_open: %s", buf); } if (kvm_nlist(kvmd, nl) < 0) { if(nlistf) errx(1, "%s: kvm_nlist: %s", nlistf, kvm_geterr(kvmd)); else errx(1, "kvm_nlist: %s", kvm_geterr(kvmd)); } if (nl[0].n_type == 0) { if(nlistf) errx(1, "%s: no namelist", nlistf); else errx(1, "no namelist"); } if (mflag) { mbpr(nl[N_MBSTAT].n_value); exit(0); } if (pflag) { if (tp->pr_stats) (*tp->pr_stats)(nl[tp->pr_sindex].n_value, tp->pr_name); else printf("%s: no stats routine\n", tp->pr_name); exit(0); } #if 0 /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); #else /* * This does not make sense any more with DNS being default over * the files. Doing a setXXXXent(1) causes a tcp connection to be * used for the queries, which is slower. */ #endif if (iflag) { intpr(interval, nl[N_IFNET].n_value); exit(0); } if (rflag) { if (sflag) rt_stats(nl[N_RTSTAT].n_value); else routepr(nl[N_RTREE].n_value); exit(0); } if (gflag) { if (sflag) mrt_stats(nl[N_MRTPROTO].n_value, nl[N_MRTSTAT].n_value); else mroutepr(nl[N_MRTPROTO].n_value, nl[N_MFCTABLE].n_value, nl[N_VIFTABLE].n_value); exit(0); } if (af == AF_INET || af == AF_UNSPEC) { setprotoent(1); setservent(1); /* ugh, this is O(MN) ... why do we do this? */ while ((p = getprotoent())) { for (tp = protox; tp->pr_name; tp++) if (strcmp(tp->pr_name, p->p_name) == 0) break; if (tp->pr_name == 0 || tp->pr_wanted == 0) continue; printproto(tp, p->p_name); } endprotoent(); } if (af == AF_IPX || af == AF_UNSPEC) for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); if (af == AF_APPLETALK || af == AF_UNSPEC) for (tp = atalkprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef NS if (af == AF_NS || af == AF_UNSPEC) for (tp = nsprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif #ifdef ISO if (af == AF_ISO || af == AF_UNSPEC) for (tp = isoprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNIXSW].n_value); exit(0); } /* * Print out protocol statistics or control blocks (per sflag). * If the interface was not specifically requested, and the symbol * is not in the namelist, ignore this one. */ static void printproto(tp, name) register struct protox *tp; char *name; { void (*pr)(); u_long off; if (sflag) { pr = tp->pr_stats; off = nl[tp->pr_sindex].n_value; } else { pr = tp->pr_cblocks; off = nl[tp->pr_index].n_value; } if (pr != NULL && (off || af != AF_UNSPEC)) (*pr)(off, name); } /* * Read kernel memory, return 0 on success. */ int kread(addr, buf, size) u_long addr; char *buf; int size; { if (kvm_read(kvmd, addr, buf, size) != size) { warnx("%s", kvm_geterr(kvmd)); return (-1); } return (0); } char * plural(n) int n; { return (n != 1 ? "s" : ""); } char * plurales(n) int n; { return (n != 1 ? "es" : ""); } /* * Find the protox for the given "well-known" name. */ static struct protox * knownname(name) char *name; { struct protox **tpp, *tp; for (tpp = protoprotox; *tpp; tpp++) for (tp = *tpp; tp->pr_name; tp++) if (strcmp(tp->pr_name, name) == 0) return (tp); return (NULL); } /* * Find the protox corresponding to name. */ static struct protox * name2protox(name) char *name; { struct protox *tp; char **alias; /* alias from p->aliases */ struct protoent *p; /* * Try to find the name in the list of "well-known" names. If that * fails, check if name is an alias for an Internet protocol. */ if ((tp = knownname(name))) return (tp); setprotoent(1); /* make protocol lookup cheaper */ while ((p = getprotoent())) { /* assert: name not same as p->name */ for (alias = p->p_aliases; *alias; alias++) if (strcmp(name, *alias) == 0) { endprotoent(); return (knownname(p->p_name)); } } endprotoent(); return (NULL); } static void usage() { (void)fprintf(stderr, "usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog); (void)fprintf(stderr, " %s [-bdghimnrs] [-f address_family] [-M core] [-N system]\n", prog); (void)fprintf(stderr, " %s [-bdn] [-I interface] [-M core] [-N system] [-w wait]\n", prog); (void)fprintf(stderr, " %s [-M core] [-N system] [-p protocol]\n", prog); exit(1); } void trimdomain(cp) char *cp; { static char domain[MAXHOSTNAMELEN + 1]; static int first = 1; char *s; if (first) { first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (s = strchr(domain, '.'))) (void) strcpy(domain, s + 1); else domain[0] = 0; } if (domain[0]) { while ((cp = strchr(cp, '.'))) { if (!strcasecmp(cp + 1, domain)) { *cp = 0; /* hit it */ break; } else { cp++; } } } } diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 710087a5e0db..b6487fe23b4f 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,894 +1,885 @@ /* * 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. */ #ifndef lint #if 0 static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id$"; + "$Id: route.c,v 1.25 1997/02/22 19:56:23 peter Exp $"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #ifdef NS #include #endif #include #include #include #include #include #include #include #include #include "netstat.h" #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d))) /* * Definitions for showing gateway flags. */ struct bits { u_long b_mask; char b_val; } bits[] = { { RTF_UP, 'U' }, { RTF_GATEWAY, 'G' }, { RTF_HOST, 'H' }, { RTF_REJECT, 'R' }, { RTF_DYNAMIC, 'D' }, { RTF_MODIFIED, 'M' }, { RTF_DONE, 'd' }, /* Completed -- for routing messages only */ { RTF_CLONING, 'C' }, { RTF_XRESOLVE, 'X' }, { RTF_LLINFO, 'L' }, { RTF_STATIC, 'S' }, { RTF_PROTO1, '1' }, { RTF_PROTO2, '2' }, { RTF_WASCLONED,'W' }, { RTF_PRCLONING,'c' }, { RTF_PROTO3, '3' }, { RTF_BLACKHOLE,'B' }, { RTF_BROADCAST,'b' }, { 0 } }; static union { struct sockaddr u_sa; u_short u_data[128]; } pt_u; int do_rtent = 0; struct rtentry rtentry; struct radix_node rnode; struct radix_mask rmask; struct radix_node_head *rt_tables[AF_MAX+1]; int NewTree = 0; static struct sockaddr *kgetsa __P((struct sockaddr *)); static void p_tree __P((struct radix_node *)); static void p_rtnode __P(()); static void ntreestuff __P(()); static void np_rtentry __P((struct rt_msghdr *)); static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); /* * Print routing tables. */ void routepr(rtree) u_long rtree; { struct radix_node_head *rnh, head; int i; printf("Routing tables\n"); if (Aflag == 0 && NewTree) ntreestuff(); else { if (rtree == 0) { printf("rt_tables: symbol not in namelist\n"); return; } kget(rtree, rt_tables); for (i = 0; i <= AF_MAX; i++) { if ((rnh = rt_tables[i]) == 0) continue; kget(rnh, head); if (i == AF_UNSPEC) { if (Aflag && af == 0) { printf("Netmasks:\n"); p_tree(head.rnh_treetop); } } else if (af == AF_UNSPEC || af == i) { pr_family(i); do_rtent = 1; pr_rthdr(); p_tree(head.rnh_treetop); } } } } /* * Print address family header before a section of the routing table. */ void pr_family(af) int af; { char *afname; switch (af) { case AF_INET: afname = "Internet"; break; case AF_IPX: afname = "IPX"; break; #ifdef NS case AF_NS: afname = "XNS"; break; #endif case AF_ISO: afname = "ISO"; break; case AF_APPLETALK: afname = "AppleTalk"; break; case AF_CCITT: afname = "X.25"; break; default: afname = NULL; break; } if (afname) printf("\n%s:\n", afname); else printf("\nProtocol Family %d:\n", af); } /* column widths; each followed by one space */ #define WID_DST 18 /* width of destination column */ #define WID_GW 18 /* width of gateway column */ /* * Print header for routing table columns. */ void pr_rthdr() { if (Aflag) printf("%-8.8s ","Address"); printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n", WID_DST, WID_DST, "Destination", WID_GW, WID_GW, "Gateway", "Flags", "Refs", "Use", "Netif", "Expire"); } static struct sockaddr * kgetsa(dst) register struct sockaddr *dst; { kget(dst, pt_u.u_sa); if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa)) kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len); return (&pt_u.u_sa); } static void p_tree(rn) struct radix_node *rn; { again: kget(rn, rnode); if (rnode.rn_b < 0) { if (Aflag) printf("%-8.8x ", (int)rn); if (rnode.rn_flags & RNF_ROOT) { if (Aflag) printf("(root node)%s", rnode.rn_dupedkey ? " =>\n" : "\n"); } else if (do_rtent) { kget(rn, rtentry); p_rtentry(&rtentry); if (Aflag) p_rtnode(); } else { p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key), NULL, 0, 44); putchar('\n'); } if ((rn = rnode.rn_dupedkey)) goto again; } else { if (Aflag && do_rtent) { printf("%-8.8x ", (int)rn); p_rtnode(); } rn = rnode.rn_r; p_tree(rnode.rn_l); p_tree(rn); } } char nbuf[20]; static void p_rtnode() { struct radix_mask *rm = rnode.rn_mklist; if (rnode.rn_b < 0) { if (rnode.rn_mask) { printf("\t mask "); p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask), NULL, 0, -1); } else if (rm == 0) return; } else { sprintf(nbuf, "(%d)", rnode.rn_b); printf("%6.6s %8.8x : %8.8x", nbuf, (int)rnode.rn_l, (int)rnode.rn_r); } while (rm) { kget(rm, rmask); sprintf(nbuf, " %d refs, ", rmask.rm_refs); printf(" mk = %8.8x {(%d),%s", (int)rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " "); if (rmask.rm_flags & RNF_NORMAL) { struct radix_node rnode_aux; printf(" , "); kget(rmask.rm_leaf, rnode_aux); p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask), NULL, 0, -1); } else p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), NULL, 0, -1); putchar('}'); if ((rm = rmask.rm_mklist)) printf(" ->"); } putchar('\n'); } static void ntreestuff() { size_t needed; int mib[6]; char *buf, *next, *lim; register struct rt_msghdr *rtm; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump estimate"); } if ((buf = malloc(needed)) == 0) { err(2, "malloc(%lu)", (unsigned long)needed); } if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump"); } lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; np_rtentry(rtm); } } static void np_rtentry(rtm) register struct rt_msghdr *rtm; { register struct sockaddr *sa = (struct sockaddr *)(rtm + 1); #ifdef notdef static int masks_done, banner_printed; #endif static int old_af; int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST; #ifdef notdef /* for the moment, netmasks are skipped over */ if (!banner_printed) { printf("Netmasks:\n"); banner_printed = 1; } if (masks_done == 0) { if (rtm->rtm_addrs != RTA_DST ) { masks_done = 1; af = sa->sa_family; } } else #endif af = sa->sa_family; if (af != old_af) { pr_family(af); old_af = af; } if (rtm->rtm_addrs == RTA_DST) p_sockaddr(sa, NULL, 0, 36); else { p_sockaddr(sa, NULL, rtm->rtm_flags, 16); if (sa->sa_len == 0) sa->sa_len = sizeof(long); sa = (struct sockaddr *)(sa->sa_len + (char *)sa); p_sockaddr(sa, NULL, 0, 18); } p_flags(rtm->rtm_flags & interesting, "%-6.6s "); putchar('\n'); } static void p_sockaddr(sa, mask, flags, width) struct sockaddr *sa, *mask; int flags, width; { char workbuf[128], *cplim; register char *cp = workbuf; switch(sa->sa_family) { case AF_INET: { register struct sockaddr_in *sin = (struct sockaddr_in *)sa; if (sin->sin_addr.s_addr == INADDR_ANY) cp = "default"; else if (flags & RTF_HOST) cp = routename(sin->sin_addr.s_addr); else if (mask) cp = netname(sin->sin_addr.s_addr, ntohl(((struct sockaddr_in *)mask) ->sin_addr.s_addr)); else cp = netname(sin->sin_addr.s_addr, 0L); break; } case AF_IPX: { struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr; if (ipx_nullnet(satoipx_addr(work))) cp = "default"; else cp = ipx_print(sa); break; } case AF_APPLETALK: { if (!(flags & RTF_HOST) && mask) cp = atalk_print2(sa,mask,9); else cp = atalk_print(sa,11); break; } #ifdef NS case AF_NS: cp = ns_print(sa); break; #endif case AF_LINK: { register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) (void) sprintf(workbuf, "link#%d", sdl->sdl_index); else switch (sdl->sdl_type) { case IFT_ETHER: { register int i; register u_char *lla = (u_char *)sdl->sdl_data + sdl->sdl_nlen; cplim = ""; for (i = 0; i < sdl->sdl_alen; i++, lla++) { cp += sprintf(cp, "%s%x", cplim, *lla); cplim = ":"; } cp = workbuf; break; } default: cp = link_ntoa(sdl); break; } break; } default: { register u_char *s = (u_char *)sa->sa_data, *slim; slim = sa->sa_len + (u_char *) sa; cplim = cp + sizeof(workbuf) - 6; cp += sprintf(cp, "(%d)", sa->sa_family); while (s < slim && cp < cplim) { cp += sprintf(cp, " %02x", *s++); if (s < slim) cp += sprintf(cp, "%02x", *s++); } cp = workbuf; } } if (width < 0 ) printf("%s ", cp); else { if (nflag) printf("%-*s ", width, cp); else printf("%-*.*s ", width, width, cp); } } static void p_flags(f, format) register int f; char *format; { char name[33], *flags; register struct bits *p = bits; for (flags = name; p->b_mask; p++) if (p->b_mask & f) *flags++ = p->b_val; *flags = '\0'; printf(format, name); } static void p_rtentry(rt) register struct rtentry *rt; { static struct ifnet ifnet, *lastif; static char name[16]; static char prettyname[9]; struct sockaddr *sa; struct sockaddr addr, mask; /* * Don't print protocol-cloned routes unless -a. */ if(rt->rt_parent && !aflag) return; if (!(sa = kgetsa(rt_key(rt)))) bzero(&addr, sizeof addr); else addr = *sa; if (!rt_mask(rt) || !(sa = kgetsa(rt_mask(rt)))) bzero(&mask, sizeof mask); else mask = *sa; p_sockaddr(&addr, &mask, rt->rt_flags, WID_DST); p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST, WID_GW); p_flags(rt->rt_flags, "%-6.6s "); printf("%6d %8ld ", rt->rt_refcnt, rt->rt_use); if (rt->rt_ifp) { if (rt->rt_ifp != lastif) { kget(rt->rt_ifp, ifnet); kread((u_long)ifnet.if_name, name, 16); lastif = rt->rt_ifp; snprintf(prettyname, sizeof prettyname, "%.6s%d", name, ifnet.if_unit); } if(rt->rt_rmx.rmx_expire) { time_t expire_time; if ((expire_time =rt->rt_rmx.rmx_expire - time((time_t *)0)) > 0) printf(" %8.8s %6d%s", prettyname, (int)expire_time, rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); } else { printf(" %8.8s%s", prettyname, rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); } } putchar('\n'); } char * routename(in) u_long in; { register char *cp; static char line[MAXHOSTNAMELEN + 1]; struct hostent *hp; cp = 0; if (!nflag) { hp = gethostbyaddr((char *)&in, sizeof (struct in_addr), AF_INET); if (hp) { cp = hp->h_name; trimdomain(cp); } } if (cp) strncpy(line, cp, sizeof(line) - 1); else { #define C(x) ((x) & 0xff) in = ntohl(in); sprintf(line, "%lu.%lu.%lu.%lu", C(in >> 24), C(in >> 16), C(in >> 8), C(in)); } return (line); } static u_long forgemask(a) u_long a; { u_long m; if (IN_CLASSA(a)) m = IN_CLASSA_NET; else if (IN_CLASSB(a)) m = IN_CLASSB_NET; else m = IN_CLASSC_NET; return (m); } static void domask(dst, addr, mask) char *dst; u_long addr, mask; { register int b, i; if (!mask || (forgemask(addr) == mask)) { *dst = '\0'; return; } i = 0; for (b = 0; b < 32; b++) if (mask & (1 << b)) { register int bb; i = b; for (bb = b+1; bb < 32; bb++) if (!(mask & (1 << bb))) { i = -1; /* noncontig */ break; } break; } if (i == -1) sprintf(dst, "&0x%lx", mask); else sprintf(dst, "/%d", 32-i); } /* * Return the name of the network whose address is given. * The address is assumed to be that of a net or subnet, not a host. */ char * netname(in, mask) u_long in, mask; { char *cp = 0; static char line[MAXHOSTNAMELEN + 1]; struct netent *np = 0; u_long net, omask; register u_long i; int subnetshift; i = ntohl(in); omask = mask; if (!nflag && i) { if (mask == 0) { switch (mask = forgemask(i)) { case IN_CLASSA_NET: subnetshift = 8; break; case IN_CLASSB_NET: subnetshift = 8; break; case IN_CLASSC_NET: subnetshift = 4; break; default: abort(); } /* * If there are more bits than the standard mask * would suggest, subnets must be in use. * Guess at the subnet mask, assuming reasonable * width subnet fields. */ while (i &~ mask) mask = (long)mask >> subnetshift; } net = i & mask; while ((mask & 1) == 0) mask >>= 1, net >>= 1; if (!(np = getnetbyaddr(i, AF_INET))) np = getnetbyaddr(net, AF_INET); if (np) { cp = np->n_name; trimdomain(cp); } } if (cp) strncpy(line, cp, sizeof(line) - 1); else if ((i & 0xffffff) == 0) sprintf(line, "%lu", C(i >> 24)); else if ((i & 0xffff) == 0) sprintf(line, "%lu.%lu", C(i >> 24) , C(i >> 16)); else if ((i & 0xff) == 0) sprintf(line, "%lu.%lu.%lu", C(i >> 24), C(i >> 16), C(i >> 8)); else sprintf(line, "%lu.%lu.%lu.%lu", C(i >> 24), C(i >> 16), C(i >> 8), C(i)); domask(line+strlen(line), i, omask); return (line); } /* * Print routing statistics */ void rt_stats(off) u_long off; { struct rtstat rtstat; if (off == 0) { printf("rtstat: symbol not in namelist\n"); return; } kread(off, (char *)&rtstat, sizeof (rtstat)); printf("routing:\n"); printf("\t%u bad routing redirect%s\n", rtstat.rts_badredirect, plural(rtstat.rts_badredirect)); printf("\t%u dynamically created route%s\n", rtstat.rts_dynamic, plural(rtstat.rts_dynamic)); printf("\t%u new gateway%s due to redirects\n", rtstat.rts_newgateway, plural(rtstat.rts_newgateway)); printf("\t%u destination%s found unreachable\n", rtstat.rts_unreach, plural(rtstat.rts_unreach)); 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]; - if(!nflag) - 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 (!nflag && (np = getnetbyaddr(*(u_long *)&work.x_net, AF_IPX))) - net = np->n_name; - else if (ipx_wildnet(work)) + 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 (!nflag && (hp = gethostbyaddr((char *)&work.x_host, 6, AF_IPX))) - host = hp->h_name; - else if (ipx_wildhost(work)) + 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); } #ifdef NS short ns_nullh[] = {0,0,0}; short ns_bh[] = {-1,-1,-1}; char * ns_print(sa) register struct sockaddr *sa; { register struct sockaddr_ns *sns = (struct sockaddr_ns*)sa; struct ns_addr work; union { union ns_net net_e; u_long long_e; } net; u_short port; static char mybuf[50], cport[10], chost[25]; char *host = ""; register char *p; register u_char *q; work = sns->sns_addr; port = ntohs(work.x_port); work.x_port = 0; net.net_e = work.x_net; if (ns_nullhost(work) && net.long_e == 0) { if (port ) { sprintf(mybuf, "*.%xH", port); upHex(mybuf); } else sprintf(mybuf, "*.*"); return (mybuf); } if (bcmp(ns_bh, work.x_host.c_host, 6) == 0) { host = "any"; } else if (bcmp(ns_nullh, work.x_host.c_host, 6) == 0) { host = "*"; } else { q = work.x_host.c_host; sprintf(chost, "%02x%02x%02x%02x%02x%02xH", 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) sprintf(cport, ".%xH", htons(port)); else *cport = 0; sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport); upHex(mybuf); return(mybuf); } char * ns_phost(sa) struct sockaddr *sa; { register struct sockaddr_ns *sns = (struct sockaddr_ns *)sa; struct sockaddr_ns work; static union ns_net ns_zeronet; char *p; work = *sns; work.sns_addr.x_port = 0; work.sns_addr.x_net = ns_zeronet; p = ns_print((struct sockaddr *)&work); if (strncmp("0H.", p, 3) == 0) p += 3; return(p); } #endif void upHex(p0) char *p0; { register char *p = p0; for (; *p; p++) switch (*p) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': *p += ('A' - 'a'); } }