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[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
49 #include <net/ethernet.h>
51 #include <net/if_var.h>
52 #include <net/if_dl.h>
53 #include <net/if_types.h>
54 #include <net/radix.h>
55 #include <net/route.h>
57 #include <netinet/in.h>
58 #include <netipx/ipx.h>
59 #include <netatalk/at.h>
60 #include <netgraph/ng_socket.h>
62 #include <sys/sysctl.h>
64 #include <arpa/inet.h>
76 #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
79 * Definitions for showing gateway flags.
90 { RTF_MODIFIED, 'M' },
91 { RTF_DONE, 'd' }, /* Completed -- for routing messages only */
93 { RTF_XRESOLVE, 'X' },
98 { RTF_WASCLONED,'W' },
99 { RTF_PRCLONING,'c' },
101 { RTF_BLACKHOLE,'B' },
102 { RTF_BROADCAST,'b' },
107 long dummy; /* Helps align structure. */
108 struct sockaddr u_sa;
115 struct rtentry rtentry;
116 struct radix_node rnode;
117 struct radix_mask rmask;
118 struct radix_node_head *rt_tables[AF_MAX+1];
122 struct timespec uptime;
124 static struct sockaddr *kgetsa(struct sockaddr *);
125 static void size_cols(int ef, struct radix_node *rn);
126 static void size_cols_tree(struct radix_node *rn);
127 static void size_cols_rtentry(struct rtentry *rt);
128 static void p_tree(struct radix_node *);
129 static void p_rtnode(void);
130 static void ntreestuff(void);
131 static void np_rtentry(struct rt_msghdr *);
132 static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int);
133 static const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask,
135 static void p_flags(int, const char *);
136 static const char *fmt_flags(int f);
137 static void p_rtentry(struct rtentry *);
138 static void domask(char *, in_addr_t, u_long);
141 * Print routing tables.
144 routepr(u_long rtree)
146 struct radix_node_head *rnh, head;
150 * Since kernel & userland use different timebase
151 * (time_uptime vs time_second) and we are reading kernel memory
152 * directly we should do rt_rmx.rmx_expire --> expire_time conversion.
154 if (clock_gettime(CLOCK_UPTIME, &uptime) < 0)
155 err(EX_OSERR, "clock_gettime() failed");
157 printf("Routing tables\n");
159 if (Aflag == 0 && NewTree)
163 printf("rt_tables: symbol not in namelist\n");
167 if (kget(rtree, rt_tables) != 0)
169 for (i = 0; i <= AF_MAX; i++) {
170 if ((rnh = rt_tables[i]) == 0)
172 if (kget(rnh, head) != 0)
174 if (i == AF_UNSPEC) {
175 if (Aflag && af == 0) {
176 printf("Netmasks:\n");
177 p_tree(head.rnh_treetop);
179 } else if (af == AF_UNSPEC || af == i) {
180 size_cols(i, head.rnh_treetop);
184 p_tree(head.rnh_treetop);
191 * Print address family header before a section of the routing table.
204 afname = "Internet6";
214 afname = "AppleTalk";
227 printf("\n%s:\n", afname);
229 printf("\nProtocol Family %d:\n", af1);
232 /* column widths; each followed by one space */
234 #define WID_DST_DEFAULT(af) 18 /* width of destination column */
235 #define WID_GW_DEFAULT(af) 18 /* width of gateway column */
236 #define WID_IF_DEFAULT(af) (Wflag ? 8 : 6) /* width of netif column */
238 #define WID_DST_DEFAULT(af) \
239 ((af) == AF_INET6 ? (numeric_addr ? 33: 18) : 18)
240 #define WID_GW_DEFAULT(af) \
241 ((af) == AF_INET6 ? (numeric_addr ? 29 : 18) : 18)
242 #define WID_IF_DEFAULT(af) ((af) == AF_INET6 ? 8 : (Wflag ? 8 : 6))
247 static int wid_flags;
252 static int wid_expire;
255 size_cols(int ef __unused, struct radix_node *rn)
257 wid_dst = WID_DST_DEFAULT(ef);
258 wid_gw = WID_GW_DEFAULT(ef);
263 wid_if = WID_IF_DEFAULT(ef);
271 size_cols_tree(struct radix_node *rn)
274 if (kget(rn, rnode) != 0)
276 if (!(rnode.rn_flags & RNF_ACTIVE))
278 if (rnode.rn_bit < 0) {
279 if ((rnode.rn_flags & RNF_ROOT) == 0) {
280 if (kget(rn, rtentry) != 0)
282 size_cols_rtentry(&rtentry);
284 if ((rn = rnode.rn_dupedkey))
288 size_cols_tree(rnode.rn_left);
294 size_cols_rtentry(struct rtentry *rt)
296 static struct ifnet ifnet, *lastif;
297 struct rtentry parent;
298 static char buffer[100];
305 * Don't print protocol-cloned routes unless -a.
307 if (rt->rt_flags & RTF_WASCLONED && !aflag) {
308 if (kget(rt->rt_parent, parent) != 0)
310 if (parent.rt_flags & RTF_PRCLONING)
314 bzero(&addr, sizeof(addr));
315 if ((sa = kgetsa(rt_key(rt))))
316 bcopy(sa, &addr, sa->sa_len);
317 bzero(&mask, sizeof(mask));
318 if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
319 bcopy(sa, &mask, sa->sa_len);
320 bp = fmt_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags);
322 wid_dst = MAX(len, wid_dst);
324 bp = fmt_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST);
326 wid_gw = MAX(len, wid_gw);
328 bp = fmt_flags(rt->rt_flags);
330 wid_flags = MAX(len, wid_flags);
332 if (addr.u_sa.sa_family == AF_INET || Wflag) {
333 len = snprintf(buffer, sizeof(buffer), "%ld", rt->rt_refcnt);
334 wid_refs = MAX(len, wid_refs);
335 len = snprintf(buffer, sizeof(buffer), "%lu", rt->rt_use);
336 wid_use = MAX(len, wid_use);
337 if (Wflag && rt->rt_rmx.rmx_mtu != 0) {
338 len = snprintf(buffer, sizeof(buffer),
339 "%lu", rt->rt_rmx.rmx_mtu);
340 wid_mtu = MAX(len, wid_mtu);
344 if (rt->rt_ifp != lastif) {
345 if (kget(rt->rt_ifp, ifnet) == 0)
346 len = strlen(ifnet.if_xname);
350 wid_if = MAX(len, wid_if);
352 if (rt->rt_rmx.rmx_expire) {
356 rt->rt_rmx.rmx_expire - uptime.tv_sec) > 0) {
357 len = snprintf(buffer, sizeof(buffer), "%d",
359 wid_expire = MAX(len, wid_expire);
367 * Print header for routing table columns.
374 printf("%-8.8s ","Address");
375 if (af1 == AF_INET || Wflag) {
377 printf("%-*.*s %-*.*s %-*.*s %*.*s %*.*s %*.*s %*.*s %*s\n",
378 wid_dst, wid_dst, "Destination",
379 wid_gw, wid_gw, "Gateway",
380 wid_flags, wid_flags, "Flags",
381 wid_refs, wid_refs, "Refs",
382 wid_use, wid_use, "Use",
383 wid_mtu, wid_mtu, "Mtu",
384 wid_if, wid_if, "Netif",
385 wid_expire, "Expire");
387 printf("%-*.*s %-*.*s %-*.*s %*.*s %*.*s %*.*s %*s\n",
388 wid_dst, wid_dst, "Destination",
389 wid_gw, wid_gw, "Gateway",
390 wid_flags, wid_flags, "Flags",
391 wid_refs, wid_refs, "Refs",
392 wid_use, wid_use, "Use",
393 wid_if, wid_if, "Netif",
394 wid_expire, "Expire");
397 printf("%-*.*s %-*.*s %-*.*s %*.*s %*s\n",
398 wid_dst, wid_dst, "Destination",
399 wid_gw, wid_gw, "Gateway",
400 wid_flags, wid_flags, "Flags",
401 wid_if, wid_if, "Netif",
402 wid_expire, "Expire");
406 static struct sockaddr *
407 kgetsa(struct sockaddr *dst)
410 if (kget(dst, pt_u.u_sa) != 0)
412 if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
413 kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
418 p_tree(struct radix_node *rn)
422 if (kget(rn, rnode) != 0)
424 if (!(rnode.rn_flags & RNF_ACTIVE))
426 if (rnode.rn_bit < 0) {
428 printf("%-8.8lx ", (u_long)rn);
429 if (rnode.rn_flags & RNF_ROOT) {
431 printf("(root node)%s",
432 rnode.rn_dupedkey ? " =>\n" : "\n");
433 } else if (do_rtent) {
434 if (kget(rn, rtentry) == 0) {
440 p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
444 if ((rn = rnode.rn_dupedkey))
447 if (Aflag && do_rtent) {
448 printf("%-8.8lx ", (u_long)rn);
452 p_tree(rnode.rn_left);
462 struct radix_mask *rm = rnode.rn_mklist;
464 if (rnode.rn_bit < 0) {
467 p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask),
472 sprintf(nbuf, "(%d)", rnode.rn_bit);
473 printf("%6.6s %8.8lx : %8.8lx", nbuf, (u_long)rnode.rn_left, (u_long)rnode.rn_right);
476 if (kget(rm, rmask) != 0)
478 sprintf(nbuf, " %d refs, ", rmask.rm_refs);
479 printf(" mk = %8.8lx {(%d),%s",
480 (u_long)rm, -1 - rmask.rm_bit, rmask.rm_refs ? nbuf : " ");
481 if (rmask.rm_flags & RNF_NORMAL) {
482 struct radix_node rnode_aux;
483 printf(" <normal>, ");
484 if (kget(rmask.rm_leaf, rnode_aux) == 0)
485 p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask),
488 p_sockaddr(NULL, NULL, 0, -1);
490 p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask),
493 if ((rm = rmask.rm_mklist))
504 char *buf, *next, *lim;
505 struct rt_msghdr *rtm;
511 mib[4] = NET_RT_DUMP;
513 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
514 err(1, "sysctl: net.route.0.0.dump estimate");
517 if ((buf = malloc(needed)) == 0) {
518 errx(2, "malloc(%lu)", (unsigned long)needed);
520 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
521 err(1, "sysctl: net.route.0.0.dump");
524 for (next = buf; next < lim; next += rtm->rtm_msglen) {
525 rtm = (struct rt_msghdr *)next;
531 np_rtentry(struct rt_msghdr *rtm)
533 struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
535 static int masks_done, banner_printed;
538 int af1 = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
541 /* for the moment, netmasks are skipped over */
542 if (!banner_printed) {
543 printf("Netmasks:\n");
546 if (masks_done == 0) {
547 if (rtm->rtm_addrs != RTA_DST ) {
558 if (rtm->rtm_addrs == RTA_DST)
559 p_sockaddr(sa, NULL, 0, 36);
561 p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
562 sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa);
563 p_sockaddr(sa, NULL, 0, 18);
565 p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
570 p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width)
574 cp = fmt_sockaddr(sa, mask, flags);
580 printf("%-*s ", width, cp);
582 printf("%-*.*s ", width, width, cp);
587 fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags)
589 static char workbuf[128];
595 switch(sa->sa_family) {
598 struct sockaddr_in *sockin = (struct sockaddr_in *)sa;
600 if ((sockin->sin_addr.s_addr == INADDR_ANY) &&
602 ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr)
605 else if (flags & RTF_HOST)
606 cp = routename(sockin->sin_addr.s_addr);
608 cp = netname(sockin->sin_addr.s_addr,
609 ntohl(((struct sockaddr_in *)mask)
612 cp = netname(sockin->sin_addr.s_addr, 0L);
619 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
620 struct in6_addr *in6 = &sa6->sin6_addr;
623 * XXX: This is a special workaround for KAME kernels.
624 * sin6_scope_id field of SA should be set in the future.
626 if (IN6_IS_ADDR_LINKLOCAL(in6) ||
627 IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
628 /* XXX: override is ok? */
629 sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
630 *(u_short *)&in6->s6_addr[2] = 0;
633 if (flags & RTF_HOST)
634 cp = routename6(sa6);
637 &((struct sockaddr_in6 *)mask)->sin6_addr);
639 cp = netname6(sa6, NULL);
647 struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr;
648 if (ipx_nullnet(satoipx_addr(work)))
656 if (!(flags & RTF_HOST) && mask)
657 cp = atalk_print2(sa,mask,9);
659 cp = atalk_print(sa,11);
664 strlcpy(workbuf, ((struct sockaddr_ng *)sa)->sg_data,
672 struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
674 if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
675 sdl->sdl_slen == 0) {
676 (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
679 switch (sdl->sdl_type) {
684 if (sdl->sdl_alen == ETHER_ADDR_LEN) {
685 cp = ether_ntoa((struct ether_addr *)
686 (sdl->sdl_data + sdl->sdl_nlen));
699 u_char *s = (u_char *)sa->sa_data, *slim;
703 slim = sa->sa_len + (u_char *) sa;
704 cqlim = cq + sizeof(workbuf) - 6;
705 cq += sprintf(cq, "(%d)", sa->sa_family);
706 while (s < slim && cq < cqlim) {
707 cq += sprintf(cq, " %02x", *s++);
709 cq += sprintf(cq, "%02x", *s++);
719 p_flags(int f, const char *format)
721 printf(format, fmt_flags(f));
727 static char name[33];
729 struct bits *p = bits;
731 for (flags = name; p->b_mask; p++)
739 p_rtentry(struct rtentry *rt)
741 static struct ifnet ifnet, *lastif;
742 struct rtentry parent;
743 static char buffer[128];
744 static char prettyname[128];
749 * Don't print protocol-cloned routes unless -a.
751 if (rt->rt_flags & RTF_WASCLONED && !aflag) {
752 if (kget(rt->rt_parent, parent) != 0)
754 if (parent.rt_flags & RTF_PRCLONING)
758 bzero(&addr, sizeof(addr));
759 if ((sa = kgetsa(rt_key(rt))))
760 bcopy(sa, &addr, sa->sa_len);
761 bzero(&mask, sizeof(mask));
762 if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
763 bcopy(sa, &mask, sa->sa_len);
764 p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags, wid_dst);
765 p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST, wid_gw);
766 snprintf(buffer, sizeof(buffer), "%%-%d.%ds ", wid_flags, wid_flags);
767 p_flags(rt->rt_flags, buffer);
768 if (addr.u_sa.sa_family == AF_INET || Wflag) {
769 printf("%*ld %*lu ", wid_refs, rt->rt_refcnt,
770 wid_use, rt->rt_use);
772 if (rt->rt_rmx.rmx_mtu != 0)
773 printf("%*lu ", wid_mtu, rt->rt_rmx.rmx_mtu);
775 printf("%*s ", wid_mtu, "");
779 if (rt->rt_ifp != lastif) {
780 if (kget(rt->rt_ifp, ifnet) == 0)
781 strlcpy(prettyname, ifnet.if_xname,
784 strlcpy(prettyname, "---", sizeof(prettyname));
787 printf("%*.*s", wid_if, wid_if, prettyname);
788 if (rt->rt_rmx.rmx_expire) {
792 rt->rt_rmx.rmx_expire - uptime.tv_sec) > 0)
793 printf(" %*d", wid_expire, (int)expire_time);
795 if (rt->rt_nodes[0].rn_dupedkey)
802 routename(in_addr_t in)
805 static char line[MAXHOSTNAMELEN];
810 hp = gethostbyaddr(&in, sizeof (struct in_addr), AF_INET);
813 trimdomain(cp, strlen(cp));
817 strncpy(line, cp, sizeof(line) - 1);
818 line[sizeof(line) - 1] = '\0';
820 #define C(x) ((x) & 0xff)
822 sprintf(line, "%u.%u.%u.%u",
823 C(in >> 24), C(in >> 16), C(in >> 8), C(in));
828 #define NSHIFT(m) ( \
829 (m) == IN_CLASSA_NET ? IN_CLASSA_NSHIFT : \
830 (m) == IN_CLASSB_NET ? IN_CLASSB_NSHIFT : \
831 (m) == IN_CLASSC_NET ? IN_CLASSC_NSHIFT : \
835 domask(char *dst, in_addr_t addr __unused, u_long mask)
839 if (mask == 0 || (!numeric_addr && NSHIFT(mask) != 0)) {
844 for (b = 0; b < 32; b++)
845 if (mask & (1 << b)) {
849 for (bb = b+1; bb < 32; bb++)
850 if (!(mask & (1 << bb))) {
851 i = -1; /* noncontig */
857 sprintf(dst, "&0x%lx", mask);
859 sprintf(dst, "/%d", 32-i);
863 * Return the name of the network whose address is given.
864 * The address is assumed to be that of a net or subnet, not a host.
867 netname(in_addr_t in, u_long mask)
870 static char line[MAXHOSTNAMELEN];
871 struct netent *np = 0;
875 if (!numeric_addr && i) {
876 np = getnetbyaddr(i >> NSHIFT(mask), AF_INET);
879 trimdomain(cp, strlen(cp));
883 strncpy(line, cp, sizeof(line) - 1);
884 line[sizeof(line) - 1] = '\0';
886 inet_ntop(AF_INET, &in, line, sizeof(line) - 1);
888 domask(line + strlen(line), i, mask);
896 netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask)
898 static char line[MAXHOSTNAMELEN];
899 u_char *p = (u_char *)mask;
901 int masklen, illegal = 0, flag = 0;
904 for (masklen = 0, lim = p + 16; p < lim; p++) {
938 fprintf(stderr, "illegal prefixlen\n");
943 if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
947 flag |= NI_NUMERICHOST;
948 getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
952 sprintf(&line[strlen(line)], "/%d", masklen);
958 routename6(struct sockaddr_in6 *sa6)
960 static char line[MAXHOSTNAMELEN];
962 /* use local variable for safety */
963 struct sockaddr_in6 sa6_local;
965 sa6_local.sin6_family = AF_INET6;
966 sa6_local.sin6_len = sizeof(sa6_local);
967 sa6_local.sin6_addr = sa6->sin6_addr;
968 sa6_local.sin6_scope_id = sa6->sin6_scope_id;
971 flag |= NI_NUMERICHOST;
973 getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
974 line, sizeof(line), NULL, 0, flag);
981 * Print routing statistics
984 rt_stats(u_long rtsaddr, u_long rttaddr)
986 struct rtstat rtstat;
990 printf("rtstat: symbol not in namelist\n");
994 printf("rttrash: symbol not in namelist\n");
997 kread(rtsaddr, (char *)&rtstat, sizeof (rtstat));
998 kread(rttaddr, (char *)&rttrash, sizeof (rttrash));
999 printf("routing:\n");
1001 #define p(f, m) if (rtstat.f || sflag <= 1) \
1002 printf(m, rtstat.f, plural(rtstat.f))
1004 p(rts_badredirect, "\t%u bad routing redirect%s\n");
1005 p(rts_dynamic, "\t%u dynamically created route%s\n");
1006 p(rts_newgateway, "\t%u new gateway%s due to redirects\n");
1007 p(rts_unreach, "\t%u destination%s found unreachable\n");
1008 p(rts_wildcard, "\t%u use%s of a wildcard route\n");
1011 if (rttrash || sflag <= 1)
1012 printf("\t%u route%s not in table but not freed\n",
1013 rttrash, plural(rttrash));
1017 ipx_print(struct sockaddr *sa)
1020 struct servent *sp = 0;
1021 const char *net = "", *host = "";
1024 struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr;
1025 static char mybuf[50];
1026 char cport[10], chost[15], cnet[15];
1028 port = ntohs(work.x_port);
1030 if (ipx_nullnet(work) && ipx_nullhost(work)) {
1034 sprintf(mybuf, "*.%s", sp->s_name);
1036 sprintf(mybuf, "*.%x", port);
1038 sprintf(mybuf, "*.*");
1043 if (ipx_wildnet(work))
1045 else if (ipx_nullnet(work))
1048 q = work.x_net.c_net;
1049 sprintf(cnet, "%02x%02x%02x%02x",
1050 q[0], q[1], q[2], q[3]);
1051 for (p = cnet; *p == '0' && p < cnet + 8; p++)
1056 if (ipx_wildhost(work))
1058 else if (ipx_nullhost(work))
1061 q = work.x_host.c_host;
1062 sprintf(chost, "%02x%02x%02x%02x%02x%02x",
1063 q[0], q[1], q[2], q[3], q[4], q[5]);
1064 for (p = chost; *p == '0' && p < chost + 12; p++)
1070 if (strcmp(host, "*") == 0)
1073 snprintf(cport, sizeof(cport),
1074 "%s%s", *host ? "." : "", sp->s_name);
1076 snprintf(cport, sizeof(cport),
1077 "%s%x", *host ? "." : "", port);
1081 snprintf(mybuf, sizeof(mybuf), "%s.%s%s", net, host, cport);
1086 ipx_phost(struct sockaddr *sa)
1088 struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa;
1089 struct sockaddr_ipx work;
1090 static union ipx_net ipx_zeronet;
1095 in = work.sipx_addr;
1097 work.sipx_addr.x_port = 0;
1098 work.sipx_addr.x_net = ipx_zeronet;
1099 p = ipx_print((struct sockaddr *)&work);
1100 if (strncmp("*.", p, 2) == 0) p += 2;