]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/route.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1983, 1988, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 static char sccsid
[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
61 static const char rcsid
[] =
62 "$Id: route.c,v 1.7 2004/10/14 22:24:09 lindak Exp $";
65 #include <sys/param.h>
66 #include <sys/socket.h>
70 #include <net/if_var.h>
71 #include <net/if_dl.h>
72 #include <net/if_types.h>
73 #include <net/route.h>
74 #include <net/radix.h>
76 #include <netinet/in.h>
78 #include <netipx/ipx.h>
79 #include <netatalk/at.h>
80 #include <netgraph/ng_socket.h>
87 #include <sys/sysctl.h>
89 #include <arpa/inet.h>
103 #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
106 /* alignment constraint for routing socket */
108 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
109 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
112 * Definitions for showing gateway flags.
119 { RTF_GATEWAY
, 'G' },
122 { RTF_DYNAMIC
, 'D' },
123 { RTF_MODIFIED
, 'M' },
124 { RTF_DONE
, 'd' }, /* Completed -- for routing messages only */
125 { RTF_CLONING
, 'C' },
126 { RTF_XRESOLVE
, 'X' },
131 { RTF_WASCLONED
,'W' },
132 { RTF_PRCLONING
,'c' },
134 { RTF_BLACKHOLE
,'B' },
135 { RTF_BROADCAST
,'b' },
140 long dummy
; /* Helps align structure. */
141 struct sockaddr u_sa
;
150 struct rtentry rtentry
;
151 struct radix_node rnode
;
152 struct radix_mask rmask
;
153 struct radix_node_head
*rt_tables
[AF_MAX
+1];
156 static struct sockaddr
*kgetsa
__P((struct sockaddr
*));
157 static void p_tree
__P((struct radix_node
*));
158 static void p_rtnode
__P((void));
159 static void p_rtentry
__P((struct rtentry
*));
161 static void ntreestuff
__P((void));
162 static void np_rtentry
__P((struct rt_msghdr2
*));
163 static void p_sockaddr
__P((struct sockaddr
*, struct sockaddr
*, int, int));
164 static void p_flags
__P((int, char *));
165 static u_long forgemask
__P((u_long
));
166 static void domask
__P((char *, u_long
, u_long
));
169 * Print routing tables.
172 routepr(u_long rtree
)
175 struct radix_node_head
*rnh
, head
;
179 printf("Routing tables\n");
185 printf("rt_tables: symbol not in namelist\n");
189 kget(rtree
, rt_tables
);
190 for (i
= 0; i
<= AF_MAX
; i
++) {
191 if ((rnh
= rt_tables
[i
]) == 0)
194 if (i
== AF_UNSPEC
) {
195 if (Aflag
&& af
== 0) {
196 printf("Netmasks:\n");
197 p_tree(head
.rnh_treetop
);
199 } else if (af
== AF_UNSPEC
|| af
== i
) {
203 p_tree(head
.rnh_treetop
);
211 * Print address family header before a section of the routing table.
224 afname
= "Internet6";
240 afname
= "AppleTalk";
254 printf("\n%s:\n", afname
);
256 printf("\nProtocol Family %d:\n", af
);
259 /* column widths; each followed by one space */
261 #define WID_DST(af) 18 /* width of destination column */
262 #define WID_GW(af) 18 /* width of gateway column */
263 #define WID_IF(af) 6 /* width of netif column */
265 #define WID_DST(af) \
266 ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
268 ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
269 #define WID_IF(af) ((af) == AF_INET6 ? 8 : 6)
273 * Print header for routing table columns.
280 printf("%-8.8s ","Address");
281 if (af
== AF_INET
|| lflag
)
283 printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %6.6s %*.*s %6s\n",
284 WID_DST(af
), WID_DST(af
), "Destination",
285 WID_GW(af
), WID_GW(af
), "Gateway",
286 "Flags", "Refs", "Use", "Mtu",
287 WID_IF(af
), WID_IF(af
), "Netif", "Expire");
289 printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %*.*s %6s\n",
290 WID_DST(af
), WID_DST(af
), "Destination",
291 WID_GW(af
), WID_GW(af
), "Gateway",
292 "Flags", "Refs", "Use",
293 WID_IF(af
), WID_IF(af
), "Netif", "Expire");
295 printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n",
296 WID_DST(af
), WID_DST(af
), "Destination",
297 WID_GW(af
), WID_GW(af
), "Gateway",
298 "Flags", "Netif", "Expire");
302 static struct sockaddr
*
303 kgetsa(struct sockaddr
*dst
)
306 kget(dst
, pt_u
.u_sa
);
307 if (pt_u
.u_sa
.sa_len
> sizeof (pt_u
.u_sa
))
308 kread((u_long
)dst
, (char *)pt_u
.u_data
, pt_u
.u_sa
.sa_len
);
313 p_tree(struct radix_node
*rn
)
318 if (rnode
.rn_bit
< 0) {
320 printf("%-8.8lx ", (u_long
)rn
);
321 if (rnode
.rn_flags
& RNF_ROOT
) {
323 printf("(root node)%s",
324 rnode
.rn_dupedkey
? " =>\n" : "\n");
325 } else if (do_rtent
) {
331 p_sockaddr(kgetsa((struct sockaddr
*)rnode
.rn_key
),
335 if ((rn
= rnode
.rn_dupedkey
))
338 if (Aflag
&& do_rtent
) {
339 printf("%-8.8lx ", (u_long
)rn
);
343 p_tree(rnode
.rn_left
);
353 struct radix_mask
*rm
= rnode
.rn_mklist
;
355 if (rnode
.rn_bit
< 0) {
358 p_sockaddr(kgetsa((struct sockaddr
*)rnode
.rn_mask
),
363 sprintf(nbuf
, "(%d)", rnode
.rn_bit
);
364 printf("%6.6s %8.8lx : %8.8lx", nbuf
, (u_long
)rnode
.rn_left
, (u_long
)rnode
.rn_right
);
368 sprintf(nbuf
, " %d refs, ", rmask
.rm_refs
);
369 printf(" mk = %8.8lx {(%d),%s",
370 (u_long
)rm
, -1 - rmask
.rm_bit
, rmask
.rm_refs
? nbuf
: " ");
371 if (rmask
.rm_flags
& RNF_NORMAL
) {
372 struct radix_node rnode_aux
;
373 printf(" <normal>, ");
374 kget(rmask
.rm_leaf
, rnode_aux
);
375 p_sockaddr(kgetsa((struct sockaddr
*)rnode_aux
.rn_mask
),
378 p_sockaddr(kgetsa((struct sockaddr
*)rmask
.rm_mask
),
381 if ((rm
= rmask
.rm_mklist
))
393 char *buf
, *next
, *lim
;
394 register struct rt_msghdr2
*rtm
;
400 mib
[4] = NET_RT_DUMP2
;
402 if (sysctl(mib
, 6, NULL
, &needed
, NULL
, 0) < 0) {
403 err(1, "sysctl: net.route.0.0.dump estimate");
406 if ((buf
= malloc(needed
)) == 0) {
407 err(2, "malloc(%lu)", (unsigned long)needed
);
409 if (sysctl(mib
, 6, buf
, &needed
, NULL
, 0) < 0) {
410 err(1, "sysctl: net.route.0.0.dump");
413 for (next
= buf
; next
< lim
; next
+= rtm
->rtm_msglen
) {
414 rtm
= (struct rt_msghdr2
*)next
;
420 get_rtaddrs(int addrs
, struct sockaddr
*sa
, struct sockaddr
**rti_info
)
424 for (i
= 0; i
< RTAX_MAX
; i
++) {
425 if (addrs
& (1 << i
)) {
427 sa
= (struct sockaddr
*)(ROUNDUP(sa
->sa_len
) + (char *)sa
);
435 np_rtentry(struct rt_msghdr2
*rtm
)
437 struct sockaddr
*sa
= (struct sockaddr
*)(rtm
+ 1);
438 struct sockaddr
*rti_info
[RTAX_MAX
];
441 u_short lastindex
= 0xffff;
442 static char ifname
[IFNAMSIZ
+ 1];
446 * Don't print protocol-cloned routes unless -a.
448 if ((rtm
->rtm_flags
& RTF_WASCLONED
) && (rtm
->rtm_parentflags
& RTF_PRCLONING
) && !aflag
) {
453 if (af
!= AF_UNSPEC
&& af
!= fam
)
455 if (fam
!= old_fam
) {
460 get_rtaddrs(rtm
->rtm_addrs
, sa
, rti_info
);
461 bzero(&addr
, sizeof(addr
));
462 if ((rtm
->rtm_addrs
& RTA_DST
))
463 bcopy(rti_info
[RTAX_DST
], &addr
, rti_info
[RTAX_DST
]->sa_len
);
464 bzero(&mask
, sizeof(mask
));
465 if ((rtm
->rtm_addrs
& RTA_NETMASK
))
466 bcopy(rti_info
[RTAX_NETMASK
], &mask
, rti_info
[RTAX_NETMASK
]->sa_len
);
467 p_sockaddr(&addr
.u_sa
, &mask
.u_sa
, rtm
->rtm_flags
,
468 WID_DST(addr
.u_sa
.sa_family
));
470 p_sockaddr(rti_info
[RTAX_GATEWAY
], NULL
, RTF_HOST
,
471 WID_GW(addr
.u_sa
.sa_family
));
473 p_flags(rtm
->rtm_flags
, "%-6.6s ");
475 if (addr
.u_sa
.sa_family
== AF_INET
|| lflag
) {
476 printf("%6u %8d ", rtm
->rtm_refcnt
, rtm
->rtm_use
);
478 if (rtm
->rtm_rmx
.rmx_mtu
!= 0)
479 printf("%6lu ", rtm
->rtm_rmx
.rmx_mtu
);
484 if (rtm
->rtm_index
!= lastindex
) {
485 if_indextoname(rtm
->rtm_index
, ifname
);
486 lastindex
= rtm
->rtm_index
;
488 printf("%*.*s", WID_IF(addr
.u_sa
.sa_family
),
489 WID_IF(addr
.u_sa
.sa_family
), ifname
);
491 if (rtm
->rtm_rmx
.rmx_expire
) {
495 rtm
->rtm_rmx
.rmx_expire
- time((time_t *)0)) > 0)
496 printf(" %6d", (int)expire_time
);
502 p_sockaddr(struct sockaddr
*sa
, struct sockaddr
*mask
, int flags
, int width
)
504 char workbuf
[128], *cplim
;
505 register char *cp
= workbuf
;
507 switch(sa
->sa_family
) {
510 register struct sockaddr_in
*sin
= (struct sockaddr_in
*)sa
;
512 if ((sin
->sin_addr
.s_addr
== INADDR_ANY
) &&
514 (ntohl(((struct sockaddr_in
*)mask
)->sin_addr
.s_addr
) == 0L ||
517 else if (flags
& RTF_HOST
)
518 cp
= routename(sin
->sin_addr
.s_addr
);
520 cp
= netname(sin
->sin_addr
.s_addr
,
521 ntohl(((struct sockaddr_in
*)mask
)
524 cp
= netname(sin
->sin_addr
.s_addr
, 0L);
531 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*)sa
;
532 struct in6_addr
*in6
= &sa6
->sin6_addr
;
535 * XXX: This is a special workaround for KAME kernels.
536 * sin6_scope_id field of SA should be set in the future.
538 if (IN6_IS_ADDR_LINKLOCAL(in6
) ||
539 IN6_IS_ADDR_MC_LINKLOCAL(in6
)) {
540 /* XXX: override is ok? */
541 sa6
->sin6_scope_id
= (u_int32_t
)ntohs(*(u_short
*)&in6
->s6_addr
[2]);
542 *(u_short
*)&in6
->s6_addr
[2] = 0;
545 if (flags
& RTF_HOST
)
546 cp
= routename6(sa6
);
548 cp
= netname6(sa6
, mask
);
550 cp
= netname6(sa6
, NULL
);
558 struct ipx_addr work
= ((struct sockaddr_ipx
*)sa
)->sipx_addr
;
559 if (ipx_nullnet(satoipx_addr(work
)))
567 if (!(flags
& RTF_HOST
) && mask
)
568 cp
= atalk_print2(sa
,mask
,9);
570 cp
= atalk_print(sa
,11);
575 printf("%s", ((struct sockaddr_ng
*)sa
)->sg_data
);
587 register struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)sa
;
589 if (sdl
->sdl_nlen
== 0 && sdl
->sdl_alen
== 0 &&
591 (void) sprintf(workbuf
, "link#%d", sdl
->sdl_index
);
593 switch (sdl
->sdl_type
) {
598 register u_char
*lla
= (u_char
*)sdl
->sdl_data
+
602 for (i
= 0; i
< sdl
->sdl_alen
; i
++, lla
++) {
603 cp
+= sprintf(cp
, "%s%x", cplim
, *lla
);
619 register u_char
*s
= (u_char
*)sa
->sa_data
, *slim
;
621 slim
= sa
->sa_len
+ (u_char
*) sa
;
622 cplim
= cp
+ sizeof(workbuf
) - 6;
623 cp
+= sprintf(cp
, "(%d)", sa
->sa_family
);
624 while (s
< slim
&& cp
< cplim
) {
625 cp
+= sprintf(cp
, " %02x", *s
++);
627 cp
+= sprintf(cp
, "%02x", *s
++);
636 printf("%-*s ", width
, cp
);
638 printf("%-*.*s ", width
, width
, cp
);
643 p_flags(int f
, char *format
)
645 char name
[33], *flags
;
646 register struct bits
*p
= bits
;
648 for (flags
= name
; p
->b_mask
; p
++)
652 printf(format
, name
);
657 p_rtentry(struct rtentry
*rt
)
659 static struct ifnet ifnet
, *lastif
;
660 struct rtentry parent
;
661 static char name
[16];
662 static char prettyname
[9];
667 * Don't print protocol-cloned routes unless -a.
669 if (rt
->rt_flags
& RTF_WASCLONED
&& !aflag
) {
670 kget(rt
->rt_parent
, parent
);
671 if (parent
.rt_flags
& RTF_PRCLONING
)
675 bzero(&addr
, sizeof(addr
));
676 if ((sa
= kgetsa(rt_key(rt
))))
677 bcopy(sa
, &addr
, sa
->sa_len
);
678 bzero(&mask
, sizeof(mask
));
679 if (rt_mask(rt
) && (sa
= kgetsa(rt_mask(rt
))))
680 bcopy(sa
, &mask
, sa
->sa_len
);
681 p_sockaddr(&addr
.u_sa
, &mask
.u_sa
, rt
->rt_flags
,
682 WID_DST(addr
.u_sa
.sa_family
));
683 p_sockaddr(kgetsa(rt
->rt_gateway
), NULL
, RTF_HOST
,
684 WID_GW(addr
.u_sa
.sa_family
));
685 p_flags(rt
->rt_flags
, "%-6.6s ");
686 if (addr
.u_sa
.sa_family
== AF_INET
|| lflag
) {
687 printf("%6u %8ld ", rt
->rt_refcnt
, rt
->rt_use
);
689 if (rt
->rt_rmx
.rmx_mtu
!= 0)
690 printf("%6lu ", rt
->rt_rmx
.rmx_mtu
);
696 if (rt
->rt_ifp
!= lastif
) {
697 kget(rt
->rt_ifp
, ifnet
);
698 kread((u_long
)ifnet
.if_name
, name
, 16);
700 snprintf(prettyname
, sizeof prettyname
,
701 "%s%d", name
, ifnet
.if_unit
);
703 printf("%*.*s", WID_IF(addr
.u_sa
.sa_family
),
704 WID_IF(addr
.u_sa
.sa_family
), prettyname
);
705 if (rt
->rt_rmx
.rmx_expire
) {
709 rt
->rt_rmx
.rmx_expire
- time((time_t *)0)) > 0)
710 printf(" %6d", (int)expire_time
);
712 if (rt
->rt_nodes
[0].rn_dupedkey
)
723 static char line
[MAXHOSTNAMELEN
];
728 hp
= gethostbyaddr((char *)&in
, sizeof (struct in_addr
),
732 //### trimdomain(cp, strlen(cp));
736 strncpy(line
, cp
, sizeof(line
) - 1);
737 line
[sizeof(line
) - 1] = '\0';
739 #define C(x) ((x) & 0xff)
741 sprintf(line
, "%lu.%lu.%lu.%lu",
742 C(in
>> 24), C(in
>> 16), C(in
>> 8), C(in
));
754 else if (IN_CLASSB(a
))
762 domask(char *dst
, u_long addr
, u_long mask
)
766 if (!mask
|| (forgemask(addr
) == mask
)) {
771 for (b
= 0; b
< 32; b
++)
772 if (mask
& (1 << b
)) {
776 for (bb
= b
+1; bb
< 32; bb
++)
777 if (!(mask
& (1 << bb
))) {
778 i
= -1; /* noncontig */
784 sprintf(dst
, "&0x%lx", mask
);
786 sprintf(dst
, "/%d", 32-i
);
790 * Return the name of the network whose address is given.
791 * The address is assumed to be that of a net or subnet, not a host.
794 netname(u_long in
, u_long mask
)
797 static char line
[MAXHOSTNAMELEN
];
798 struct netent
*np
= 0;
799 u_long net
, omask
, dmask
;
803 dmask
= forgemask(i
);
807 if (!(np
= getnetbyaddr(i
, AF_INET
)) && net
!= i
)
808 np
= getnetbyaddr(net
, AF_INET
);
811 //### trimdomain(cp, strlen(cp));
815 strncpy(line
, cp
, sizeof(line
) - 1);
819 if ((i
& IN_CLASSA_HOST
) == 0) {
820 sprintf(line
, "%lu", C(i
>> 24));
825 if ((i
& IN_CLASSB_HOST
) == 0) {
826 sprintf(line
, "%lu.%lu",
827 C(i
>> 24), C(i
>> 16));
832 if ((i
& IN_CLASSC_HOST
) == 0) {
833 sprintf(line
, "%lu.%lu.%lu",
834 C(i
>> 24), C(i
>> 16), C(i
>> 8));
839 sprintf(line
, "%lu.%lu.%lu.%lu",
840 C(i
>> 24), C(i
>> 16), C(i
>> 8), C(i
));
844 domask(line
+strlen(line
), i
, omask
);
850 netname6(struct sockaddr_in6
*sa6
, struct sockaddr
*sam
)
852 static char line
[MAXHOSTNAMELEN
];
854 int masklen
, illegal
= 0, flag
= NI_WITHSCOPEID
;
855 struct in6_addr
*mask
= sam
? &((struct sockaddr_in6
*)sam
)->sin6_addr
: 0;
857 if (sam
&& sam
->sa_len
== 0) {
860 u_char
*p
= (u_char
*)mask
;
861 for (masklen
= 0, lim
= p
+ 16; p
< lim
; p
++) {
895 fprintf(stderr
, "illegal prefixlen\n");
900 if (masklen
== 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6
->sin6_addr
))
904 flag
|= NI_NUMERICHOST
;
905 getnameinfo((struct sockaddr
*)sa6
, sa6
->sin6_len
, line
, sizeof(line
),
909 sprintf(&line
[strlen(line
)], "/%d", masklen
);
915 routename6(struct sockaddr_in6
*sa6
)
917 static char line
[MAXHOSTNAMELEN
];
918 int flag
= NI_WITHSCOPEID
;
919 /* use local variable for safety */
920 struct sockaddr_in6 sa6_local
= {sizeof(sa6_local
), AF_INET6
, };
922 sa6_local
.sin6_addr
= sa6
->sin6_addr
;
923 sa6_local
.sin6_scope_id
= sa6
->sin6_scope_id
;
926 flag
|= NI_NUMERICHOST
;
928 getnameinfo((struct sockaddr
*)&sa6_local
, sa6_local
.sin6_len
,
929 line
, sizeof(line
), NULL
, 0, flag
);
936 * Print routing statistics
941 struct rtstat rtstat
;
950 mib
[4] = NET_RT_STAT
;
952 len
= sizeof(struct rtstat
);
953 if (sysctl(mib
, 6, &rtstat
, &len
, 0, 0) == -1)
960 mib
[4] = NET_RT_TRASH
;
962 len
= sizeof(rttrash
);
963 if (sysctl(mib
, 6, &rttrash
, &len
, 0, 0) == -1)
966 printf("routing:\n");
968 #define p(f, m) if (rtstat.f || sflag <= 1) \
969 printf(m, rtstat.f, plural(rtstat.f))
971 p(rts_badredirect
, "\t%u bad routing redirect%s\n");
972 p(rts_dynamic
, "\t%u dynamically created route%s\n");
973 p(rts_newgateway
, "\t%u new gateway%s due to redirects\n");
974 p(rts_unreach
, "\t%u destination%s found unreachable\n");
975 p(rts_wildcard
, "\t%u use%s of a wildcard route\n");
978 if (rttrash
|| sflag
<= 1)
979 printf("\t%u route%s not in table but not freed\n",
980 rttrash
, plural(rttrash
));
984 ipx_print(struct sockaddr
*sa
)
987 struct servent
*sp
= 0;
988 char *net
= "", *host
= "";
991 struct ipx_addr work
= ((struct sockaddr_ipx
*)sa
)->sipx_addr
;
992 static char mybuf
[50];
993 char cport
[10], chost
[15], cnet
[15];
995 port
= ntohs(work
.x_port
);
997 if (ipx_nullnet(work
) && ipx_nullhost(work
)) {
1001 sprintf(mybuf
, "*.%s", sp
->s_name
);
1003 sprintf(mybuf
, "*.%x", port
);
1005 sprintf(mybuf
, "*.*");
1010 if (ipx_wildnet(work
))
1012 else if (ipx_nullnet(work
))
1015 q
= work
.x_net
.c_net
;
1016 sprintf(cnet
, "%02x%02x%02x%02x",
1017 q
[0], q
[1], q
[2], q
[3]);
1018 for (p
= cnet
; *p
== '0' && p
< cnet
+ 8; p
++)
1023 if (ipx_wildhost(work
))
1025 else if (ipx_nullhost(work
))
1028 q
= work
.x_host
.c_host
;
1029 sprintf(chost
, "%02x%02x%02x%02x%02x%02x",
1030 q
[0], q
[1], q
[2], q
[3], q
[4], q
[5]);
1031 for (p
= chost
; *p
== '0' && p
< chost
+ 12; p
++)
1037 if (strcmp(host
, "*") == 0)
1040 snprintf(cport
, sizeof(cport
),
1041 "%s%s", *host
? "." : "", sp
->s_name
);
1043 snprintf(cport
, sizeof(cport
),
1044 "%s%x", *host
? "." : "", port
);
1048 snprintf(mybuf
, sizeof(mybuf
), "%s.%s%s", net
, host
, cport
);
1053 ipx_phost(struct sockaddr
*sa
)
1055 register struct sockaddr_ipx
*sipx
= (struct sockaddr_ipx
*)sa
;
1056 struct sockaddr_ipx work
;
1057 static union ipx_net ipx_zeronet
;
1062 in
= work
.sipx_addr
;
1064 work
.sipx_addr
.x_port
= 0;
1065 work
.sipx_addr
.x_net
= ipx_zeronet
;
1066 p
= ipx_print((struct sockaddr
*)&work
);
1067 if (strncmp("*.", p
, 2) == 0) p
+= 2;
1073 short ns_nullh
[] = {0,0,0};
1074 short ns_bh
[] = {-1,-1,-1};
1077 ns_print(struct sockaddr
*sa
)
1079 register struct sockaddr_ns
*sns
= (struct sockaddr_ns
*)sa
;
1080 struct ns_addr work
;
1081 union { union ns_net net_e
; u_long long_e
; } net
;
1083 static char mybuf
[50], cport
[10], chost
[25];
1085 register char *p
; register u_char
*q
;
1087 work
= sns
->sns_addr
;
1088 port
= ntohs(work
.x_port
);
1090 net
.net_e
= work
.x_net
;
1091 if (ns_nullhost(work
) && net
.long_e
== 0) {
1093 sprintf(mybuf
, "*.%xH", port
);
1096 sprintf(mybuf
, "*.*");
1100 if (bcmp(ns_bh
, work
.x_host
.c_host
, 6) == 0) {
1102 } else if (bcmp(ns_nullh
, work
.x_host
.c_host
, 6) == 0) {
1105 q
= work
.x_host
.c_host
;
1106 sprintf(chost
, "%02x%02x%02x%02x%02x%02xH",
1107 q
[0], q
[1], q
[2], q
[3], q
[4], q
[5]);
1108 for (p
= chost
; *p
== '0' && p
< chost
+ 12; p
++)
1113 sprintf(cport
, ".%xH", htons(port
));
1117 sprintf(mybuf
,"%xH.%s%s", ntohl(net
.long_e
), host
, cport
);
1123 ns_phost(struct sockaddr
*sa
)
1125 register struct sockaddr_ns
*sns
= (struct sockaddr_ns
*)sa
;
1126 struct sockaddr_ns work
;
1127 static union ns_net ns_zeronet
;
1131 work
.sns_addr
.x_port
= 0;
1132 work
.sns_addr
.x_net
= ns_zeronet
;
1134 p
= ns_print((struct sockaddr
*)&work
);
1135 if (strncmp("0H.", p
, 3) == 0)
1144 register char *p
= p0
;