]>
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.4 2003/07/08 23:03:54 lindak Exp $";
65 #include <sys/param.h>
66 #include <sys/protosw.h>
67 #include <sys/socket.h>
71 #include <net/if_var.h>
72 #include <net/if_dl.h>
73 #include <net/if_types.h>
74 #include <net/route.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>
102 #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
105 /* alignment constraint for routing socket */
107 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
108 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
111 * Definitions for showing gateway flags.
118 { RTF_GATEWAY
, 'G' },
121 { RTF_DYNAMIC
, 'D' },
122 { RTF_MODIFIED
, 'M' },
123 { RTF_DONE
, 'd' }, /* Completed -- for routing messages only */
124 { RTF_CLONING
, 'C' },
125 { RTF_XRESOLVE
, 'X' },
130 { RTF_WASCLONED
,'W' },
131 { RTF_PRCLONING
,'c' },
133 { RTF_BLACKHOLE
,'B' },
134 { RTF_BROADCAST
,'b' },
139 long dummy
; /* Helps align structure. */
140 struct sockaddr u_sa
;
147 struct rtentry rtentry
;
148 struct radix_node rnode
;
149 struct radix_mask rmask
;
150 struct radix_node_head
*rt_tables
[AF_MAX
+1];
154 static struct sockaddr
*kgetsa
__P((struct sockaddr
*));
155 static void p_tree
__P((struct radix_node
*));
156 static void p_rtnode
__P((void));
157 static void ntreestuff
__P((void));
158 static void np_rtentry
__P((struct rt_msghdr
*));
159 static void p_sockaddr
__P((struct sockaddr
*, struct sockaddr
*, int, int));
160 static void p_flags
__P((int, char *));
161 static void p_rtentry
__P((struct rtentry
*));
162 static u_long forgemask
__P((u_long
));
163 static void domask
__P((char *, u_long
, u_long
));
166 * Print routing tables.
169 routepr(u_long rtree
)
171 struct radix_node_head
*rnh
, head
;
174 printf("Routing tables\n");
176 if (Aflag
== 0 && NewTree
)
180 printf("rt_tables: symbol not in namelist\n");
184 kget(rtree
, rt_tables
);
185 for (i
= 0; i
<= AF_MAX
; i
++) {
186 if ((rnh
= rt_tables
[i
]) == 0)
189 if (i
== AF_UNSPEC
) {
190 if (Aflag
&& af
== 0) {
191 printf("Netmasks:\n");
192 p_tree(head
.rnh_treetop
);
194 } else if (af
== AF_UNSPEC
|| af
== i
) {
198 p_tree(head
.rnh_treetop
);
205 * Print address family header before a section of the routing table.
218 afname
= "Internet6";
234 afname
= "AppleTalk";
248 printf("\n%s:\n", afname
);
250 printf("\nProtocol Family %d:\n", af
);
253 /* column widths; each followed by one space */
255 #define WID_DST(af) 18 /* width of destination column */
256 #define WID_GW(af) 18 /* width of gateway column */
257 #define WID_IF(af) 6 /* width of netif column */
259 #define WID_DST(af) \
260 ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18)
262 ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18)
263 #define WID_IF(af) ((af) == AF_INET6 ? 8 : 6)
267 * Print header for routing table columns.
274 printf("%-8.8s ","Address");
275 if (af
== AF_INET
|| lflag
)
277 printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %6.6s %*.*s %6s\n",
278 WID_DST(af
), WID_DST(af
), "Destination",
279 WID_GW(af
), WID_GW(af
), "Gateway",
280 "Flags", "Refs", "Use", "Mtu",
281 WID_IF(af
), WID_IF(af
), "Netif", "Expire");
283 printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %*.*s %6s\n",
284 WID_DST(af
), WID_DST(af
), "Destination",
285 WID_GW(af
), WID_GW(af
), "Gateway",
286 "Flags", "Refs", "Use",
287 WID_IF(af
), WID_IF(af
), "Netif", "Expire");
289 printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n",
290 WID_DST(af
), WID_DST(af
), "Destination",
291 WID_GW(af
), WID_GW(af
), "Gateway",
292 "Flags", "Netif", "Expire");
295 static struct sockaddr
*
296 kgetsa(struct sockaddr
*dst
)
299 kget(dst
, pt_u
.u_sa
);
300 if (pt_u
.u_sa
.sa_len
> sizeof (pt_u
.u_sa
))
301 kread((u_long
)dst
, (char *)pt_u
.u_data
, pt_u
.u_sa
.sa_len
);
306 p_tree(struct radix_node
*rn
)
311 if (rnode
.rn_bit
< 0) {
313 printf("%-8.8lx ", (u_long
)rn
);
314 if (rnode
.rn_flags
& RNF_ROOT
) {
316 printf("(root node)%s",
317 rnode
.rn_dupedkey
? " =>\n" : "\n");
318 } else if (do_rtent
) {
324 p_sockaddr(kgetsa((struct sockaddr
*)rnode
.rn_key
),
328 if ((rn
= rnode
.rn_dupedkey
))
331 if (Aflag
&& do_rtent
) {
332 printf("%-8.8lx ", (u_long
)rn
);
336 p_tree(rnode
.rn_left
);
346 struct radix_mask
*rm
= rnode
.rn_mklist
;
348 if (rnode
.rn_bit
< 0) {
351 p_sockaddr(kgetsa((struct sockaddr
*)rnode
.rn_mask
),
356 sprintf(nbuf
, "(%d)", rnode
.rn_bit
);
357 printf("%6.6s %8.8lx : %8.8lx", nbuf
, (u_long
)rnode
.rn_left
, (u_long
)rnode
.rn_right
);
361 sprintf(nbuf
, " %d refs, ", rmask
.rm_refs
);
362 printf(" mk = %8.8lx {(%d),%s",
363 (u_long
)rm
, -1 - rmask
.rm_bit
, rmask
.rm_refs
? nbuf
: " ");
364 if (rmask
.rm_flags
& RNF_NORMAL
) {
365 struct radix_node rnode_aux
;
366 printf(" <normal>, ");
367 kget(rmask
.rm_leaf
, rnode_aux
);
368 p_sockaddr(kgetsa((struct sockaddr
*)rnode_aux
.rn_mask
),
371 p_sockaddr(kgetsa((struct sockaddr
*)rmask
.rm_mask
),
374 if ((rm
= rmask
.rm_mklist
))
385 char *buf
, *next
, *lim
;
386 register struct rt_msghdr
*rtm
;
392 mib
[4] = NET_RT_DUMP
;
394 if (sysctl(mib
, 6, NULL
, &needed
, NULL
, 0) < 0) {
395 err(1, "sysctl: net.route.0.0.dump estimate");
398 if ((buf
= malloc(needed
)) == 0) {
399 err(2, "malloc(%lu)", (unsigned long)needed
);
401 if (sysctl(mib
, 6, buf
, &needed
, NULL
, 0) < 0) {
402 err(1, "sysctl: net.route.0.0.dump");
405 for (next
= buf
; next
< lim
; next
+= rtm
->rtm_msglen
) {
406 rtm
= (struct rt_msghdr
*)next
;
412 np_rtentry(struct rt_msghdr
*rtm
)
414 register struct sockaddr
*sa
= (struct sockaddr
*)(rtm
+ 1);
416 static int masks_done
, banner_printed
;
419 int af
= 0, interesting
= RTF_UP
| RTF_GATEWAY
| RTF_HOST
;
422 /* for the moment, netmasks are skipped over */
423 if (!banner_printed
) {
424 printf("Netmasks:\n");
427 if (masks_done
== 0) {
428 if (rtm
->rtm_addrs
!= RTA_DST
) {
439 if (rtm
->rtm_addrs
== RTA_DST
)
440 p_sockaddr(sa
, NULL
, 0, 36);
442 p_sockaddr(sa
, NULL
, rtm
->rtm_flags
, 16);
443 sa
= (struct sockaddr
*)(ROUNDUP(sa
->sa_len
) + (char *)sa
);
444 p_sockaddr(sa
, NULL
, 0, 18);
446 p_flags(rtm
->rtm_flags
& interesting
, "%-6.6s ");
451 p_sockaddr(struct sockaddr
*sa
, struct sockaddr
*mask
, int flags
, int width
)
453 char workbuf
[128], *cplim
;
454 register char *cp
= workbuf
;
456 switch(sa
->sa_family
) {
459 register struct sockaddr_in
*sin
= (struct sockaddr_in
*)sa
;
461 if ((sin
->sin_addr
.s_addr
== INADDR_ANY
) &&
463 ntohl(((struct sockaddr_in
*)mask
)->sin_addr
.s_addr
)
466 else if (flags
& RTF_HOST
)
467 cp
= routename(sin
->sin_addr
.s_addr
);
469 cp
= netname(sin
->sin_addr
.s_addr
,
470 ntohl(((struct sockaddr_in
*)mask
)
473 cp
= netname(sin
->sin_addr
.s_addr
, 0L);
480 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*)sa
;
481 struct in6_addr
*in6
= &sa6
->sin6_addr
;
484 * XXX: This is a special workaround for KAME kernels.
485 * sin6_scope_id field of SA should be set in the future.
487 if (IN6_IS_ADDR_LINKLOCAL(in6
) ||
488 IN6_IS_ADDR_MC_LINKLOCAL(in6
)) {
489 /* XXX: override is ok? */
490 sa6
->sin6_scope_id
= (u_int32_t
)ntohs(*(u_short
*)&in6
->s6_addr
[2]);
491 *(u_short
*)&in6
->s6_addr
[2] = 0;
494 if (flags
& RTF_HOST
)
495 cp
= routename6(sa6
);
498 &((struct sockaddr_in6
*)mask
)->sin6_addr
);
500 cp
= netname6(sa6
, NULL
);
508 struct ipx_addr work
= ((struct sockaddr_ipx
*)sa
)->sipx_addr
;
509 if (ipx_nullnet(satoipx_addr(work
)))
517 if (!(flags
& RTF_HOST
) && mask
)
518 cp
= atalk_print2(sa
,mask
,9);
520 cp
= atalk_print(sa
,11);
525 printf("%s", ((struct sockaddr_ng
*)sa
)->sg_data
);
537 register struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)sa
;
539 if (sdl
->sdl_nlen
== 0 && sdl
->sdl_alen
== 0 &&
541 (void) sprintf(workbuf
, "link#%d", sdl
->sdl_index
);
543 switch (sdl
->sdl_type
) {
548 register u_char
*lla
= (u_char
*)sdl
->sdl_data
+
552 for (i
= 0; i
< sdl
->sdl_alen
; i
++, lla
++) {
553 cp
+= sprintf(cp
, "%s%x", cplim
, *lla
);
569 register u_char
*s
= (u_char
*)sa
->sa_data
, *slim
;
571 slim
= sa
->sa_len
+ (u_char
*) sa
;
572 cplim
= cp
+ sizeof(workbuf
) - 6;
573 cp
+= sprintf(cp
, "(%d)", sa
->sa_family
);
574 while (s
< slim
&& cp
< cplim
) {
575 cp
+= sprintf(cp
, " %02x", *s
++);
577 cp
+= sprintf(cp
, "%02x", *s
++);
586 printf("%-*s ", width
, cp
);
588 printf("%-*.*s ", width
, width
, cp
);
593 p_flags(int f
, char *format
)
595 char name
[33], *flags
;
596 register struct bits
*p
= bits
;
598 for (flags
= name
; p
->b_mask
; p
++)
602 printf(format
, name
);
606 p_rtentry(struct rtentry
*rt
)
608 static struct ifnet ifnet
, *lastif
;
609 struct rtentry parent
;
610 static char name
[16];
611 static char prettyname
[9];
616 * Don't print protocol-cloned routes unless -a.
618 if (rt
->rt_flags
& RTF_WASCLONED
&& !aflag
) {
619 kget(rt
->rt_parent
, parent
);
620 if (parent
.rt_flags
& RTF_PRCLONING
)
624 bzero(&addr
, sizeof(addr
));
625 if ((sa
= kgetsa(rt_key(rt
))))
626 bcopy(sa
, &addr
, sa
->sa_len
);
627 bzero(&mask
, sizeof(mask
));
628 if (rt_mask(rt
) && (sa
= kgetsa(rt_mask(rt
))))
629 bcopy(sa
, &mask
, sa
->sa_len
);
630 p_sockaddr(&addr
.u_sa
, &mask
.u_sa
, rt
->rt_flags
,
631 WID_DST(addr
.u_sa
.sa_family
));
632 p_sockaddr(kgetsa(rt
->rt_gateway
), NULL
, RTF_HOST
,
633 WID_GW(addr
.u_sa
.sa_family
));
634 p_flags(rt
->rt_flags
, "%-6.6s ");
635 if (addr
.u_sa
.sa_family
== AF_INET
|| lflag
) {
636 printf("%6ld %8ld ", rt
->rt_refcnt
, rt
->rt_use
);
638 if (rt
->rt_rmx
.rmx_mtu
!= 0)
639 printf("%6lu ", rt
->rt_rmx
.rmx_mtu
);
645 if (rt
->rt_ifp
!= lastif
) {
646 kget(rt
->rt_ifp
, ifnet
);
647 kread((u_long
)ifnet
.if_name
, name
, 16);
649 snprintf(prettyname
, sizeof prettyname
,
650 "%s%d", name
, ifnet
.if_unit
);
652 printf("%*.*s", WID_IF(addr
.u_sa
.sa_family
),
653 WID_IF(addr
.u_sa
.sa_family
), prettyname
);
654 if (rt
->rt_rmx
.rmx_expire
) {
658 rt
->rt_rmx
.rmx_expire
- time((time_t *)0)) > 0)
659 printf(" %6d", (int)expire_time
);
661 if (rt
->rt_nodes
[0].rn_dupedkey
)
671 static char line
[MAXHOSTNAMELEN
];
676 hp
= gethostbyaddr((char *)&in
, sizeof (struct in_addr
),
680 //### trimdomain(cp, strlen(cp));
684 strncpy(line
, cp
, sizeof(line
) - 1);
685 line
[sizeof(line
) - 1] = '\0';
687 #define C(x) ((x) & 0xff)
689 sprintf(line
, "%lu.%lu.%lu.%lu",
690 C(in
>> 24), C(in
>> 16), C(in
>> 8), C(in
));
702 else if (IN_CLASSB(a
))
710 domask(char *dst
, u_long addr
, u_long mask
)
714 if (!mask
|| (forgemask(addr
) == mask
)) {
719 for (b
= 0; b
< 32; b
++)
720 if (mask
& (1 << b
)) {
724 for (bb
= b
+1; bb
< 32; bb
++)
725 if (!(mask
& (1 << bb
))) {
726 i
= -1; /* noncontig */
732 sprintf(dst
, "&0x%lx", mask
);
734 sprintf(dst
, "/%d", 32-i
);
738 * Return the name of the network whose address is given.
739 * The address is assumed to be that of a net or subnet, not a host.
742 netname(u_long in
, u_long mask
)
745 static char line
[MAXHOSTNAMELEN
];
746 struct netent
*np
= 0;
747 u_long net
, omask
, dmask
;
751 dmask
= forgemask(i
);
755 if (!(np
= getnetbyaddr(i
, AF_INET
)) && net
!= i
)
756 np
= getnetbyaddr(net
, AF_INET
);
759 //### trimdomain(cp, strlen(cp));
763 strncpy(line
, cp
, sizeof(line
) - 1);
767 if ((i
& IN_CLASSA_HOST
) == 0) {
768 sprintf(line
, "%lu", C(i
>> 24));
773 if ((i
& IN_CLASSB_HOST
) == 0) {
774 sprintf(line
, "%lu.%lu",
775 C(i
>> 24), C(i
>> 16));
780 if ((i
& IN_CLASSC_HOST
) == 0) {
781 sprintf(line
, "%lu.%lu.%lu",
782 C(i
>> 24), C(i
>> 16), C(i
>> 8));
787 sprintf(line
, "%lu.%lu.%lu.%lu",
788 C(i
>> 24), C(i
>> 16), C(i
>> 8), C(i
));
792 domask(line
+strlen(line
), i
, omask
);
798 netname6(struct sockaddr_in6
*sa6
, struct in6_addr
*mask
)
800 static char line
[MAXHOSTNAMELEN
];
801 u_char
*p
= (u_char
*)mask
;
803 int masklen
, illegal
= 0, flag
= NI_WITHSCOPEID
;
806 for (masklen
= 0, lim
= p
+ 16; p
< lim
; p
++) {
840 fprintf(stderr
, "illegal prefixlen\n");
845 if (masklen
== 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6
->sin6_addr
))
849 flag
|= NI_NUMERICHOST
;
850 getnameinfo((struct sockaddr
*)sa6
, sa6
->sin6_len
, line
, sizeof(line
),
854 sprintf(&line
[strlen(line
)], "/%d", masklen
);
860 routename6(struct sockaddr_in6
*sa6
)
862 static char line
[MAXHOSTNAMELEN
];
863 int flag
= NI_WITHSCOPEID
;
864 /* use local variable for safety */
865 struct sockaddr_in6 sa6_local
= {sizeof(sa6_local
), AF_INET6
, };
867 sa6_local
.sin6_addr
= sa6
->sin6_addr
;
868 sa6_local
.sin6_scope_id
= sa6
->sin6_scope_id
;
871 flag
|= NI_NUMERICHOST
;
873 getnameinfo((struct sockaddr
*)&sa6_local
, sa6_local
.sin6_len
,
874 line
, sizeof(line
), NULL
, 0, flag
);
881 * Print routing statistics
884 rt_stats(u_long rtsaddr
, u_long rttaddr
)
886 struct rtstat rtstat
;
890 printf("rtstat: symbol not in namelist\n");
894 printf("rttrash: symbol not in namelist\n");
897 kread(rtsaddr
, (char *)&rtstat
, sizeof (rtstat
));
898 kread(rttaddr
, (char *)&rttrash
, sizeof (rttrash
));
899 printf("routing:\n");
901 #define p(f, m) if (rtstat.f || sflag <= 1) \
902 printf(m, rtstat.f, plural(rtstat.f))
904 p(rts_badredirect
, "\t%u bad routing redirect%s\n");
905 p(rts_dynamic
, "\t%u dynamically created route%s\n");
906 p(rts_newgateway
, "\t%u new gateway%s due to redirects\n");
907 p(rts_unreach
, "\t%u destination%s found unreachable\n");
908 p(rts_wildcard
, "\t%u use%s of a wildcard route\n");
911 if (rttrash
|| sflag
<= 1)
912 printf("\t%u route%s not in table but not freed\n",
913 rttrash
, plural(rttrash
));
917 ipx_print(struct sockaddr
*sa
)
920 struct servent
*sp
= 0;
921 char *net
= "", *host
= "";
924 struct ipx_addr work
= ((struct sockaddr_ipx
*)sa
)->sipx_addr
;
925 static char mybuf
[50];
926 char cport
[10], chost
[15], cnet
[15];
928 port
= ntohs(work
.x_port
);
930 if (ipx_nullnet(work
) && ipx_nullhost(work
)) {
934 sprintf(mybuf
, "*.%s", sp
->s_name
);
936 sprintf(mybuf
, "*.%x", port
);
938 sprintf(mybuf
, "*.*");
943 if (ipx_wildnet(work
))
945 else if (ipx_nullnet(work
))
948 q
= work
.x_net
.c_net
;
949 sprintf(cnet
, "%02x%02x%02x%02x",
950 q
[0], q
[1], q
[2], q
[3]);
951 for (p
= cnet
; *p
== '0' && p
< cnet
+ 8; p
++)
956 if (ipx_wildhost(work
))
958 else if (ipx_nullhost(work
))
961 q
= work
.x_host
.c_host
;
962 sprintf(chost
, "%02x%02x%02x%02x%02x%02x",
963 q
[0], q
[1], q
[2], q
[3], q
[4], q
[5]);
964 for (p
= chost
; *p
== '0' && p
< chost
+ 12; p
++)
970 if (strcmp(host
, "*") == 0)
973 snprintf(cport
, sizeof(cport
),
974 "%s%s", *host
? "." : "", sp
->s_name
);
976 snprintf(cport
, sizeof(cport
),
977 "%s%x", *host
? "." : "", port
);
981 snprintf(mybuf
, sizeof(mybuf
), "%s.%s%s", net
, host
, cport
);
986 ipx_phost(struct sockaddr
*sa
)
988 register struct sockaddr_ipx
*sipx
= (struct sockaddr_ipx
*)sa
;
989 struct sockaddr_ipx work
;
990 static union ipx_net ipx_zeronet
;
997 work
.sipx_addr
.x_port
= 0;
998 work
.sipx_addr
.x_net
= ipx_zeronet
;
999 p
= ipx_print((struct sockaddr
*)&work
);
1000 if (strncmp("*.", p
, 2) == 0) p
+= 2;
1006 short ns_nullh
[] = {0,0,0};
1007 short ns_bh
[] = {-1,-1,-1};
1010 ns_print(struct sockaddr
*sa
)
1012 register struct sockaddr_ns
*sns
= (struct sockaddr_ns
*)sa
;
1013 struct ns_addr work
;
1014 union { union ns_net net_e
; u_long long_e
; } net
;
1016 static char mybuf
[50], cport
[10], chost
[25];
1018 register char *p
; register u_char
*q
;
1020 work
= sns
->sns_addr
;
1021 port
= ntohs(work
.x_port
);
1023 net
.net_e
= work
.x_net
;
1024 if (ns_nullhost(work
) && net
.long_e
== 0) {
1026 sprintf(mybuf
, "*.%xH", port
);
1029 sprintf(mybuf
, "*.*");
1033 if (bcmp(ns_bh
, work
.x_host
.c_host
, 6) == 0) {
1035 } else if (bcmp(ns_nullh
, work
.x_host
.c_host
, 6) == 0) {
1038 q
= work
.x_host
.c_host
;
1039 sprintf(chost
, "%02x%02x%02x%02x%02x%02xH",
1040 q
[0], q
[1], q
[2], q
[3], q
[4], q
[5]);
1041 for (p
= chost
; *p
== '0' && p
< chost
+ 12; p
++)
1046 sprintf(cport
, ".%xH", htons(port
));
1050 sprintf(mybuf
,"%xH.%s%s", ntohl(net
.long_e
), host
, cport
);
1056 ns_phost(struct sockaddr
*sa
)
1058 register struct sockaddr_ns
*sns
= (struct sockaddr_ns
*)sa
;
1059 struct sockaddr_ns work
;
1060 static union ns_net ns_zeronet
;
1064 work
.sns_addr
.x_port
= 0;
1065 work
.sns_addr
.x_net
= ns_zeronet
;
1067 p
= ns_print((struct sockaddr
*)&work
);
1068 if (strncmp("0H.", p
, 3) == 0)
1077 register char *p
= p0
;