Annotation of src/usr.bin/netstat/route.c, Revision 1.7
1.7 ! millert 1: /* $OpenBSD: route.c,v 1.6 1996/10/25 10:50:52 deraadt Exp $ */
1.2 deraadt 2: /* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1988, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
40: #else
1.7 ! millert 41: static char *rcsid = "$OpenBSD: route.c,v 1.6 1996/10/25 10:50:52 deraadt Exp $";
1.1 deraadt 42: #endif
43: #endif /* not lint */
44:
45: #include <sys/param.h>
46: #include <sys/protosw.h>
47: #include <sys/socket.h>
48: #include <sys/mbuf.h>
49:
50: #include <net/if.h>
51: #include <net/if_dl.h>
52: #include <net/if_types.h>
53: #define _KERNEL
54: #include <net/route.h>
55: #undef _KERNEL
56: #include <netinet/in.h>
57:
58: #include <netns/ns.h>
59:
1.5 mickey 60: #include <netipx/ipx.h>
61:
1.1 deraadt 62: #include <sys/sysctl.h>
63:
64: #include <netdb.h>
65: #include <stdio.h>
66: #include <stdlib.h>
67: #include <string.h>
68: #include <unistd.h>
69: #include "netstat.h"
70:
71: #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
72:
73: /*
74: * Definitions for showing gateway flags.
75: */
76: struct bits {
77: short b_mask;
78: char b_val;
79: } bits[] = {
80: { RTF_UP, 'U' },
81: { RTF_GATEWAY, 'G' },
82: { RTF_HOST, 'H' },
83: { RTF_REJECT, 'R' },
84: { RTF_DYNAMIC, 'D' },
85: { RTF_MODIFIED, 'M' },
86: { RTF_DONE, 'd' }, /* Completed -- for routing messages only */
87: { RTF_MASK, 'm' }, /* Mask Present -- for routing messages only */
88: { RTF_CLONING, 'C' },
89: { RTF_XRESOLVE, 'X' },
90: { RTF_LLINFO, 'L' },
91: { RTF_STATIC, 'S' },
92: { RTF_PROTO1, '1' },
93: { RTF_PROTO2, '2' },
94: { 0 }
95: };
96:
97: static union {
1.6 deraadt 98: struct sockaddr u_sa;
99: u_int32_t u_data[64];
1.1 deraadt 100: } pt_u;
101:
102: int do_rtent = 0;
103: struct rtentry rtentry;
104: struct radix_node rnode;
105: struct radix_mask rmask;
106:
107: int NewTree = 0;
108:
109: static struct sockaddr *kgetsa __P((struct sockaddr *));
110: static void p_tree __P((struct radix_node *));
111: static void p_rtnode __P(());
112: static void ntreestuff __P(());
113: static void np_rtentry __P((struct rt_msghdr *));
114: static void p_sockaddr __P((struct sockaddr *, int, int));
115: static void p_flags __P((int, char *));
116: static void p_rtentry __P((struct rtentry *));
117:
118: /*
119: * Print routing tables.
120: */
121: void
122: routepr(rtree)
123: u_long rtree;
124: {
125: struct radix_node_head *rnh, head;
126: int i;
127:
128: printf("Routing tables\n");
129:
130: if (Aflag == 0 && NewTree)
131: ntreestuff();
132: else {
133: if (rtree == 0) {
134: printf("rt_tables: symbol not in namelist\n");
135: return;
136: }
137:
138: kget(rtree, rt_tables);
139: for (i = 0; i <= AF_MAX; i++) {
140: if ((rnh = rt_tables[i]) == 0)
141: continue;
142: kget(rnh, head);
143: if (i == AF_UNSPEC) {
144: if (Aflag && af == 0) {
145: printf("Netmasks:\n");
146: p_tree(head.rnh_treetop);
147: }
148: } else if (af == AF_UNSPEC || af == i) {
149: pr_family(i);
150: do_rtent = 1;
151: pr_rthdr();
152: p_tree(head.rnh_treetop);
153: }
154: }
155: }
156: }
157:
158: /*
159: * Print address family header before a section of the routing table.
160: */
161: void
162: pr_family(af)
163: int af;
164: {
165: char *afname;
166:
167: switch (af) {
168: case AF_INET:
169: afname = "Internet";
170: break;
171: case AF_NS:
172: afname = "XNS";
173: break;
1.5 mickey 174: case AF_IPX:
175: afname = "IPX";
176: break;
1.1 deraadt 177: case AF_ISO:
178: afname = "ISO";
179: break;
180: case AF_CCITT:
181: afname = "X.25";
182: break;
183: default:
184: afname = NULL;
185: break;
186: }
187: if (afname)
188: printf("\n%s:\n", afname);
189: else
190: printf("\nProtocol Family %d:\n", af);
191: }
192:
193: /* column widths; each followed by one space */
194: #define WID_DST 16 /* width of destination column */
195: #define WID_GW 18 /* width of gateway column */
196:
197: /*
198: * Print header for routing table columns.
199: */
200: void
201: pr_rthdr()
202: {
203:
204: if (Aflag)
205: printf("%-8.8s ","Address");
206: printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %6.6s %s\n",
207: WID_DST, WID_DST, "Destination",
208: WID_GW, WID_GW, "Gateway",
209: "Flags", "Refs", "Use", "Mtu", "Interface");
210: }
211:
212: static struct sockaddr *
213: kgetsa(dst)
214: register struct sockaddr *dst;
215: {
216:
217: kget(dst, pt_u.u_sa);
218: if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
219: kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
220: return (&pt_u.u_sa);
221: }
222:
223: static void
224: p_tree(rn)
225: struct radix_node *rn;
226: {
227:
228: again:
229: kget(rn, rnode);
230: if (rnode.rn_b < 0) {
231: if (Aflag)
232: printf("%-8.8x ", rn);
233: if (rnode.rn_flags & RNF_ROOT) {
234: if (Aflag)
235: printf("(root node)%s",
236: rnode.rn_dupedkey ? " =>\n" : "\n");
237: } else if (do_rtent) {
238: kget(rn, rtentry);
239: p_rtentry(&rtentry);
240: if (Aflag)
241: p_rtnode();
242: } else {
243: p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
244: 0, 44);
245: putchar('\n');
246: }
247: if (rn = rnode.rn_dupedkey)
248: goto again;
249: } else {
250: if (Aflag && do_rtent) {
251: printf("%-8.8x ", rn);
252: p_rtnode();
253: }
254: rn = rnode.rn_r;
255: p_tree(rnode.rn_l);
256: p_tree(rn);
257: }
258: }
259:
260: char nbuf[20];
261:
262: static void
263: p_rtnode()
264: {
265: struct radix_mask *rm = rnode.rn_mklist;
266:
267: if (rnode.rn_b < 0) {
268: if (rnode.rn_mask) {
269: printf("\t mask ");
270: p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask),
271: 0, -1);
272: } else if (rm == 0)
273: return;
274: } else {
275: sprintf(nbuf, "(%d)", rnode.rn_b);
276: printf("%6.6s %8.8x : %8.8x", nbuf, rnode.rn_l, rnode.rn_r);
277: }
278: while (rm) {
279: kget(rm, rmask);
280: sprintf(nbuf, " %d refs, ", rmask.rm_refs);
281: printf(" mk = %8.8x {(%d),%s",
282: rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
283: p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, -1);
284: putchar('}');
285: if (rm = rmask.rm_mklist)
286: printf(" ->");
287: }
288: putchar('\n');
289: }
290:
291: static void
292: ntreestuff()
293: {
294: size_t needed;
295: int mib[6];
296: char *buf, *next, *lim;
297: register struct rt_msghdr *rtm;
298:
299: mib[0] = CTL_NET;
300: mib[1] = PF_ROUTE;
301: mib[2] = 0;
302: mib[3] = 0;
303: mib[4] = NET_RT_DUMP;
304: mib[5] = 0;
305: if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
306: { perror("route-sysctl-estimate"); exit(1);}
307: if ((buf = malloc(needed)) == 0)
308: { printf("out of space\n"); exit(1);}
309: if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
310: { perror("sysctl of routing table"); exit(1);}
311: lim = buf + needed;
312: for (next = buf; next < lim; next += rtm->rtm_msglen) {
313: rtm = (struct rt_msghdr *)next;
314: np_rtentry(rtm);
315: }
316: }
317:
318: static void
319: np_rtentry(rtm)
320: register struct rt_msghdr *rtm;
321: {
322: register struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
323: #ifdef notdef
324: static int masks_done, banner_printed;
325: #endif
326: static int old_af;
327: int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
328:
329: #ifdef notdef
330: /* for the moment, netmasks are skipped over */
331: if (!banner_printed) {
332: printf("Netmasks:\n");
333: banner_printed = 1;
334: }
335: if (masks_done == 0) {
336: if (rtm->rtm_addrs != RTA_DST ) {
337: masks_done = 1;
338: af = sa->sa_family;
339: }
340: } else
341: #endif
342: af = sa->sa_family;
343: if (af != old_af) {
344: pr_family(af);
345: old_af = af;
346: }
347: if (rtm->rtm_addrs == RTA_DST)
348: p_sockaddr(sa, 0, 36);
349: else {
350: p_sockaddr(sa, rtm->rtm_flags, 16);
351: if (sa->sa_len == 0)
352: sa->sa_len = sizeof(long);
353: sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
354: p_sockaddr(sa, 0, 18);
355: }
356: p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
357: putchar('\n');
358: }
359:
360: static void
361: p_sockaddr(sa, flags, width)
362: struct sockaddr *sa;
363: int flags, width;
364: {
365: char workbuf[128], *cplim;
366: register char *cp = workbuf;
367:
368: switch(sa->sa_family) {
369: case AF_INET:
370: {
371: register struct sockaddr_in *sin = (struct sockaddr_in *)sa;
372:
373: cp = (sin->sin_addr.s_addr == 0) ? "default" :
374: ((flags & RTF_HOST) ?
375: routename(sin->sin_addr.s_addr) :
376: netname(sin->sin_addr.s_addr, INADDR_ANY));
377: break;
378: }
379:
380: case AF_NS:
381: cp = ns_print(sa);
382: break;
383:
1.5 mickey 384: case AF_IPX:
385: cp = ipx_print(sa);
386: break;
387:
1.1 deraadt 388: case AF_LINK:
389: {
390: register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
391:
392: if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
393: sdl->sdl_slen == 0)
394: (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
395: else switch (sdl->sdl_type) {
396: case IFT_ETHER:
397: {
398: register int i;
399: register u_char *lla = (u_char *)sdl->sdl_data +
400: sdl->sdl_nlen;
401:
402: cplim = "";
403: for (i = 0; i < sdl->sdl_alen; i++, lla++) {
1.4 deraadt 404: cp += snprintf(cp,
405: workbuf + sizeof (workbuf) - cp,
406: "%s%x", cplim, *lla);
1.1 deraadt 407: cplim = ":";
408: }
409: cp = workbuf;
410: break;
411: }
412: default:
413: cp = link_ntoa(sdl);
414: break;
415: }
416: break;
417: }
418:
419: default:
420: {
421: register u_char *s = (u_char *)sa->sa_data, *slim;
422:
423: slim = sa->sa_len + (u_char *) sa;
424: cplim = cp + sizeof(workbuf) - 6;
425: cp += sprintf(cp, "(%d)", sa->sa_family);
426: while (s < slim && cp < cplim) {
1.4 deraadt 427: cp += snprintf(cp, workbuf + sizeof (workbuf) - cp,
428: " %02x", *s++);
1.1 deraadt 429: if (s < slim)
1.4 deraadt 430: cp += snprintf(cp,
431: workbuf + sizeof (workbuf) - cp,
432: "%02x", *s++);
1.1 deraadt 433: }
434: cp = workbuf;
435: }
436: }
437: if (width < 0 )
438: printf("%s ", cp);
439: else {
440: if (nflag)
441: printf("%-*s ", width, cp);
442: else
443: printf("%-*.*s ", width, width, cp);
444: }
445: }
446:
447: static void
448: p_flags(f, format)
449: register int f;
450: char *format;
451: {
452: char name[33], *flags;
453: register struct bits *p = bits;
454:
455: for (flags = name; p->b_mask; p++)
456: if (p->b_mask & f)
457: *flags++ = p->b_val;
458: *flags = '\0';
459: printf(format, name);
460: }
461:
462: static void
463: p_rtentry(rt)
464: register struct rtentry *rt;
465: {
466: static struct ifnet ifnet, *lastif;
467:
468: p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, WID_DST);
469: p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW);
470: p_flags(rt->rt_flags, "%-6.6s ");
471: printf("%6d %8d ", rt->rt_refcnt, rt->rt_use);
472: if (rt->rt_rmx.rmx_mtu)
473: printf("%6d ", rt->rt_rmx.rmx_mtu);
474: else
475: printf("%6s ", "-");
476: if (rt->rt_ifp) {
477: if (rt->rt_ifp != lastif) {
478: kget(rt->rt_ifp, ifnet);
479: lastif = rt->rt_ifp;
480: }
1.2 deraadt 481: printf(" %.16s%s", ifnet.if_xname,
1.1 deraadt 482: rt->rt_nodes[0].rn_dupedkey ? " =>" : "");
483: }
484: putchar('\n');
485: }
486:
487: char *
488: routename(in)
489: u_int32_t in;
490: {
491: register char *cp;
492: static char line[MAXHOSTNAMELEN + 1];
493: struct hostent *hp;
494: static char domain[MAXHOSTNAMELEN + 1];
495: static int first = 1;
496:
497: if (first) {
498: first = 0;
499: if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1.7 ! millert 500: (cp = strchr(domain, '.')))
1.1 deraadt 501: (void) strcpy(domain, cp + 1);
502: else
503: domain[0] = 0;
504: }
505: cp = 0;
506: if (!nflag) {
507: hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
508: AF_INET);
509: if (hp) {
1.7 ! millert 510: if ((cp = strchr(hp->h_name, '.')) &&
1.1 deraadt 511: !strcmp(cp + 1, domain))
512: *cp = 0;
513: cp = hp->h_name;
514: }
515: }
516: if (cp)
517: strncpy(line, cp, sizeof(line) - 1);
518: else {
519: #define C(x) ((x) & 0xff)
520: in = ntohl(in);
521: sprintf(line, "%u.%u.%u.%u",
522: C(in >> 24), C(in >> 16), C(in >> 8), C(in));
523: }
524: return (line);
525: }
526:
527: /*
528: * Return the name of the network whose address is given.
529: * The address is assumed to be that of a net or subnet, not a host.
530: */
531: char *
532: netname(in, mask)
533: u_int32_t in, mask;
534: {
535: char *cp = 0;
536: static char line[MAXHOSTNAMELEN + 1];
537: struct netent *np = 0;
538: u_int32_t net;
539: int subnetshift;
540:
541: in = ntohl(in);
542: mask = ntohl(mask);
543: if (!nflag && in != INADDR_ANY) {
544: if (mask == INADDR_ANY) {
545: if (IN_CLASSA(in)) {
546: mask = IN_CLASSA_NET;
547: subnetshift = 8;
548: } else if (IN_CLASSB(in)) {
549: mask = IN_CLASSB_NET;
550: subnetshift = 8;
551: } else {
552: mask = IN_CLASSC_NET;
553: subnetshift = 4;
554: }
555: /*
556: * If there are more bits than the standard mask
557: * would suggest, subnets must be in use.
558: * Guess at the subnet mask, assuming reasonable
559: * width subnet fields.
560: */
561: while (in &~ mask)
562: mask = (long)mask >> subnetshift;
563: }
564: net = in & mask;
565: while ((mask & 1) == 0)
566: mask >>= 1, net >>= 1;
567: np = getnetbyaddr(net, AF_INET);
568: if (np)
569: cp = np->n_name;
570: }
571: if (cp)
572: strncpy(line, cp, sizeof(line) - 1);
573: else if ((in & 0xffffff) == 0)
574: sprintf(line, "%u", C(in >> 24));
575: else if ((in & 0xffff) == 0)
576: sprintf(line, "%u.%u", C(in >> 24) , C(in >> 16));
577: else if ((in & 0xff) == 0)
578: sprintf(line, "%u.%u.%u", C(in >> 24), C(in >> 16), C(in >> 8));
579: else
580: sprintf(line, "%u.%u.%u.%u", C(in >> 24),
581: C(in >> 16), C(in >> 8), C(in));
582: return (line);
583: }
584:
585: /*
586: * Print routing statistics
587: */
588: void
589: rt_stats(off)
590: u_long off;
591: {
592: struct rtstat rtstat;
593:
594: if (off == 0) {
595: printf("rtstat: symbol not in namelist\n");
596: return;
597: }
598: kread(off, (char *)&rtstat, sizeof (rtstat));
599: printf("routing:\n");
600: printf("\t%u bad routing redirect%s\n",
601: rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
602: printf("\t%u dynamically created route%s\n",
603: rtstat.rts_dynamic, plural(rtstat.rts_dynamic));
604: printf("\t%u new gateway%s due to redirects\n",
605: rtstat.rts_newgateway, plural(rtstat.rts_newgateway));
606: printf("\t%u destination%s found unreachable\n",
607: rtstat.rts_unreach, plural(rtstat.rts_unreach));
608: printf("\t%u use%s of a wildcard route\n",
609: rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
610: }
1.5 mickey 611:
1.1 deraadt 612: short ns_nullh[] = {0,0,0};
613: short ns_bh[] = {-1,-1,-1};
614:
615: char *
616: ns_print(sa)
617: register struct sockaddr *sa;
618: {
619: register struct sockaddr_ns *sns = (struct sockaddr_ns*)sa;
620: struct ns_addr work;
621: union { union ns_net net_e; u_long long_e; } net;
622: u_short port;
623: static char mybuf[50], cport[10], chost[25];
624: char *host = "";
625: register char *p; register u_char *q;
626:
627: work = sns->sns_addr;
628: port = ntohs(work.x_port);
629: work.x_port = 0;
630: net.net_e = work.x_net;
631: if (ns_nullhost(work) && net.long_e == 0) {
632: if (port ) {
633: sprintf(mybuf, "*.%xH", port);
634: upHex(mybuf);
635: } else
636: sprintf(mybuf, "*.*");
637: return (mybuf);
638: }
639:
640: if (bcmp(ns_bh, work.x_host.c_host, 6) == 0) {
641: host = "any";
642: } else if (bcmp(ns_nullh, work.x_host.c_host, 6) == 0) {
643: host = "*";
644: } else {
645: q = work.x_host.c_host;
646: sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
647: q[0], q[1], q[2], q[3], q[4], q[5]);
648: for (p = chost; *p == '0' && p < chost + 12; p++)
649: continue;
650: host = p;
651: }
652: if (port)
653: sprintf(cport, ".%xH", htons(port));
654: else
655: *cport = 0;
656:
657: sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport);
658: upHex(mybuf);
659: return(mybuf);
660: }
661:
662: char *
663: ns_phost(sa)
664: struct sockaddr *sa;
665: {
666: register struct sockaddr_ns *sns = (struct sockaddr_ns *)sa;
667: struct sockaddr_ns work;
668: static union ns_net ns_zeronet;
669: char *p;
670:
671: work = *sns;
672: work.sns_addr.x_port = 0;
673: work.sns_addr.x_net = ns_zeronet;
674:
675: p = ns_print((struct sockaddr *)&work);
1.5 mickey 676: if (strncmp("0H.", p, 3) == 0) p += 3;
677: return(p);
678: }
679:
680: u_short ipx_nullh[] = {0,0,0};
681: u_short ipx_bh[] = {0xffff,0xffff,0xffff};
682:
683: char *
684: ipx_print(sa)
685: register struct sockaddr *sa;
686: {
687: register struct sockaddr_ipx *sipx = (struct sockaddr_ipx*)sa;
688: struct ipx_addr work;
689: union { union ipx_net net_e; u_long long_e; } net;
690: u_short port;
691: static char mybuf[50], cport[10], chost[25];
692: char *host = "";
693: register char *p; register u_char *q;
694:
695: work = sipx->sipx_addr;
696: port = ntohs(work.ipx_port);
697: work.ipx_port = 0;
698: net.net_e = work.ipx_net;
699: if (ipx_nullhost(work) && net.long_e == 0) {
700: if (port != 0) {
701: sprintf(mybuf, "*.%xH", port);
702: upHex(mybuf);
703: } else
704: sprintf(mybuf, "*.*");
705: return (mybuf);
706: }
707:
708: if (bcmp(ipx_bh, work.ipx_host.c_host, 6) == 0) {
709: host = "any";
710: } else if (bcmp(ipx_nullh, work.ipx_host.c_host, 6) == 0) {
711: host = "*";
712: } else {
713: q = work.ipx_host.c_host;
714: sprintf(chost, "%02x:%02x:%02x:%02x:%02x:%02x",
715: q[0], q[1], q[2], q[3], q[4], q[5]);
716: host = chost;
717: }
718: if (port)
719: sprintf(cport, ".%xH", htons(port));
720: else
721: *cport = 0;
722:
723: sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport);
724: upHex(mybuf);
725: return(mybuf);
726: }
727:
728: char *
729: ipx_phost(sa)
730: struct sockaddr *sa;
731: {
732: register struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa;
733: struct sockaddr_ipx work;
734: static union ipx_net ipx_zeronet;
735: char *p;
736:
737: work = *sipx;
738: work.sipx_addr.ipx_port = 0;
739: work.sipx_addr.ipx_net = ipx_zeronet;
740:
741: p = ipx_print((struct sockaddr *)&work);
1.1 deraadt 742: if (strncmp("0H.", p, 3) == 0) p += 3;
743: return(p);
744: }
745:
746: void
747: upHex(p0)
748: char *p0;
749: {
750: register char *p = p0;
751: for (; *p; p++) switch (*p) {
752:
753: case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
754: *p += ('A' - 'a');
755: }
756: }